aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/.gitignore6
-rw-r--r--src/include/Makefile.am30
-rw-r--r--src/include/gnu_name_system_protocols.h96
-rw-r--r--src/include/gnu_name_system_record_types.h204
-rw-r--r--src/include/gnu_name_system_service_ports.h104
-rw-r--r--src/include/gnunet_abd_service.h28
-rw-r--r--src/include/gnunet_arm_service.h82
-rw-r--r--src/include/gnunet_ats_application_service.h109
-rw-r--r--src/include/gnunet_ats_plugin.h492
-rw-r--r--src/include/gnunet_ats_service.h631
-rw-r--r--src/include/gnunet_ats_transport_service.h241
-rw-r--r--src/include/gnunet_bandwidth_lib.h4
-rw-r--r--src/include/gnunet_bio_lib.h37
-rw-r--r--src/include/gnunet_cadet_service.h2
-rw-r--r--src/include/gnunet_child_management_lib.h5
-rw-r--r--src/include/gnunet_common.h493
-rw-r--r--src/include/gnunet_configuration_lib.h174
-rw-r--r--src/include/gnunet_container_lib.h25
-rw-r--r--src/include/gnunet_conversation_service.h2
-rw-r--r--src/include/gnunet_core_service.h1
-rw-r--r--src/include/gnunet_crypto_lib.h1650
-rw-r--r--src/include/gnunet_curl_lib.h2
-rw-r--r--src/include/gnunet_dht_block_types.h156
-rw-r--r--src/include/gnunet_dht_service.h1
-rw-r--r--src/include/gnunet_disk_lib.h2
-rw-r--r--src/include/gnunet_dnsparser_lib.h86
-rw-r--r--src/include/gnunet_error_codes.h242
-rw-r--r--src/include/gnunet_fragmentation_lib.h235
-rw-r--r--src/include/gnunet_friends_lib.h124
-rw-r--r--src/include/gnunet_fs_service.h11
-rw-r--r--src/include/gnunet_getopt_lib.h20
-rw-r--r--src/include/gnunet_gns_service.h14
-rw-r--r--src/include/gnunet_gnsrecord_lib.h193
-rw-r--r--src/include/gnunet_hello_lib.h545
-rw-r--r--src/include/gnunet_hello_uri_lib.h62
-rw-r--r--src/include/gnunet_helper_lib.h17
-rw-r--r--src/include/gnunet_identity_service.h559
-rw-r--r--src/include/gnunet_json_lib.h128
-rw-r--r--src/include/gnunet_messenger_service.h300
-rw-r--r--src/include/gnunet_mq_lib.h84
-rw-r--r--src/include/gnunet_mst_lib.h4
-rw-r--r--src/include/gnunet_my_lib.h511
-rw-r--r--src/include/gnunet_mysql_compat.h63
-rw-r--r--src/include/gnunet_mysql_lib.h151
-rw-r--r--src/include/gnunet_namestore_plugin.h72
-rw-r--r--src/include/gnunet_namestore_service.h168
-rw-r--r--src/include/gnunet_nat_service.h13
-rw-r--r--src/include/gnunet_network_lib.h3
-rw-r--r--src/include/gnunet_nt_lib.h5
-rw-r--r--src/include/gnunet_os_lib.h24
-rw-r--r--src/include/gnunet_peerinfo_service.h214
-rw-r--r--src/include/gnunet_peerstore_plugin.h18
-rw-r--r--src/include/gnunet_peerstore_service.h193
-rw-r--r--src/include/gnunet_plugin_lib.h2
-rw-r--r--src/include/gnunet_pq_lib.h639
-rw-r--r--src/include/gnunet_program_lib.h41
-rw-r--r--src/include/gnunet_protocols.h80
-rw-r--r--src/include/gnunet_reclaim_service.h101
-rw-r--r--src/include/gnunet_rest_plugin.h21
-rw-r--r--src/include/gnunet_revocation_service.h134
-rw-r--r--src/include/gnunet_service_lib.h112
-rw-r--r--src/include/gnunet_signatures.h254
-rw-r--r--src/include/gnunet_strings_lib.h33
-rw-r--r--src/include/gnunet_testbed_lib.h130
-rw-r--r--src/include/gnunet_testbed_logger_service.h139
-rw-r--r--src/include/gnunet_testbed_service.h1735
-rw-r--r--src/include/gnunet_testing_arm_lib.h47
-rw-r--r--src/include/gnunet_testing_barrier.h115
-rw-r--r--src/include/gnunet_testing_core_lib.h159
-rw-r--r--src/include/gnunet_testing_lib.h1125
-rw-r--r--src/include/gnunet_testing_netjail_lib.h525
-rw-r--r--src/include/gnunet_testing_ng_lib.h722
-rw-r--r--src/include/gnunet_testing_plugin.h141
-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.h11
-rw-r--r--src/include/gnunet_transport_application_service.h7
-rw-r--r--src/include/gnunet_transport_communication_service.h7
-rw-r--r--src/include/gnunet_transport_core_service.h2
-rw-r--r--src/include/gnunet_transport_hello_service.h207
-rw-r--r--src/include/gnunet_transport_manipulation_service.h123
-rw-r--r--src/include/gnunet_transport_monitor_service.h3
-rw-r--r--src/include/gnunet_transport_plugin.h733
-rw-r--r--src/include/gnunet_transport_service.h715
-rw-r--r--src/include/gnunet_tun_lib.h23
-rw-r--r--src/include/gnunet_util_lib.h10
-rw-r--r--src/include/meson.build122
-rw-r--r--src/include/platform.h5
88 files changed, 6648 insertions, 10458 deletions
diff --git a/src/include/.gitignore b/src/include/.gitignore
index 75c6af4b6..76ca45ab4 100644
--- a/src/include/.gitignore
+++ b/src/include/.gitignore
@@ -1,7 +1,3 @@
1gnunet_error_codes.h
2gnu_name_system_record_flags.h
3gnu_name_system_record_types.h
4gnunet_dht_block_types.h
5gnunet_signatures.h
6!gnunet_config.h.in 1!gnunet_config.h.in
7gnunet_config.h 2gnunet_config.h
3gnunet_mysql_compat.h
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 8519883c9..6942d2d0e 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -17,10 +17,6 @@ gnunetinclude_HEADERS = \
17 gnunet_abd_service.h \ 17 gnunet_abd_service.h \
18 gnunet_applications.h \ 18 gnunet_applications.h \
19 gnunet_arm_service.h \ 19 gnunet_arm_service.h \
20 gnunet_ats_service.h \
21 gnunet_ats_application_service.h \
22 gnunet_ats_transport_service.h \
23 gnunet_ats_plugin.h \
24 gnunet_bandwidth_lib.h \ 20 gnunet_bandwidth_lib.h \
25 gnunet_bio_lib.h \ 21 gnunet_bio_lib.h \
26 gnunet_dht_block_types.h \ 22 gnunet_dht_block_types.h \
@@ -51,8 +47,6 @@ gnunetinclude_HEADERS = \
51 gnunet_dnsstub_lib.h \ 47 gnunet_dnsstub_lib.h \
52 gnunet_dns_service.h \ 48 gnunet_dns_service.h \
53 gnunet_error_codes.h \ 49 gnunet_error_codes.h \
54 gnunet_fragmentation_lib.h \
55 gnunet_friends_lib.h \
56 gnunet_fs_service.h \ 50 gnunet_fs_service.h \
57 gnunet_getopt_lib.h \ 51 gnunet_getopt_lib.h \
58 gnunet_gns_service.h \ 52 gnunet_gns_service.h \
@@ -60,7 +54,8 @@ gnunetinclude_HEADERS = \
60 gnunet_gnsrecord_json_lib.h \ 54 gnunet_gnsrecord_json_lib.h \
61 gnunet_gnsrecord_plugin.h \ 55 gnunet_gnsrecord_plugin.h \
62 gnu_name_system_record_types.h \ 56 gnu_name_system_record_types.h \
63 gnunet_hello_lib.h \ 57 gnu_name_system_protocols.h \
58 gnu_name_system_service_ports.h \
64 gnunet_hello_uri_lib.h \ 59 gnunet_hello_uri_lib.h \
65 gnunet_helper_lib.h \ 60 gnunet_helper_lib.h \
66 gnunet_identity_service.h \ 61 gnunet_identity_service.h \
@@ -75,9 +70,6 @@ gnunetinclude_HEADERS = \
75 gnunet_microphone_lib.h \ 70 gnunet_microphone_lib.h \
76 gnunet_mst_lib.h \ 71 gnunet_mst_lib.h \
77 gnunet_mq_lib.h \ 72 gnunet_mq_lib.h \
78 gnunet_my_lib.h \
79 gnunet_mysql_compat.h \
80 gnunet_mysql_lib.h \
81 gnunet_namecache_plugin.h \ 73 gnunet_namecache_plugin.h \
82 gnunet_namecache_service.h \ 74 gnunet_namecache_service.h \
83 gnunet_namestore_plugin.h \ 75 gnunet_namestore_plugin.h \
@@ -91,7 +83,6 @@ gnunetinclude_HEADERS = \
91 gnunet_op_lib.h \ 83 gnunet_op_lib.h \
92 gnunet_os_lib.h \ 84 gnunet_os_lib.h \
93 gnunet_peer_lib.h \ 85 gnunet_peer_lib.h \
94 gnunet_peerinfo_service.h \
95 gnunet_peerstore_plugin.h \ 86 gnunet_peerstore_plugin.h \
96 gnunet_peerstore_service.h \ 87 gnunet_peerstore_service.h \
97 gnunet_plugin_lib.h \ 88 gnunet_plugin_lib.h \
@@ -118,22 +109,17 @@ gnunetinclude_HEADERS = \
118 gnunet_sq_lib.h \ 109 gnunet_sq_lib.h \
119 gnunet_statistics_service.h \ 110 gnunet_statistics_service.h \
120 gnunet_strings_lib.h \ 111 gnunet_strings_lib.h \
121 gnunet_testbed_service.h \
122 gnunet_testbed_logger_service.h \
123 gnunet_testing_barrier.h \
124 gnunet_testing_lib.h \ 112 gnunet_testing_lib.h \
125 gnunet_testing_plugin.h \ 113 gnunet_testing_arm_lib.h \
126 gnunet_testing_ng_lib.h \ 114 gnunet_testing_core_lib.h \
127 gnunet_testing_netjail_lib.h \ 115 gnunet_testing_testbed_lib.h \
116 gnunet_testing_transport_lib.h \
117 gnunet_testbed_lib.h \
128 gnunet_time_lib.h \ 118 gnunet_time_lib.h \
129 gnunet_transport_service.h \
130 gnunet_transport_application_service.h \ 119 gnunet_transport_application_service.h \
131 gnunet_transport_communication_service.h \ 120 gnunet_transport_communication_service.h \
132 gnunet_transport_core_service.h \
133 gnunet_transport_hello_service.h \
134 gnunet_transport_manipulation_service.h \
135 gnunet_transport_monitor_service.h \ 121 gnunet_transport_monitor_service.h \
136 gnunet_transport_plugin.h \ 122 gnunet_transport_core_service.h \
137 gnunet_tun_lib.h \ 123 gnunet_tun_lib.h \
138 gnunet_uri_lib.h \ 124 gnunet_uri_lib.h \
139 gnunet_util_lib.h \ 125 gnunet_util_lib.h \
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
new file mode 100644
index 000000000..8a62cac11
--- /dev/null
+++ b/src/include/gnu_name_system_record_types.h
@@ -0,0 +1,204 @@
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 GNU_NAME_SYSTEM_RECORD_TYPES_H
21#define GNU_NAME_SYSTEM_RECORD_TYPES_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add GNS record 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/**
41 * GNS zone delegation (PKEY)
42 */
43#define GNUNET_GNSRECORD_TYPE_PKEY 65536
44
45
46/**
47 * GNS zone nickname
48 */
49#define GNUNET_GNSRECORD_TYPE_NICK 65537
50
51
52/**
53 * GNS legacy hostname
54 */
55#define GNUNET_GNSRECORD_TYPE_LEHO 65538
56
57
58/**
59 * VPN resolution
60 */
61#define GNUNET_GNSRECORD_TYPE_VPN 65539
62
63
64/**
65 * Delegation to DNS
66 */
67#define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540
68
69
70/**
71 * Box record
72 */
73#define GNUNET_GNSRECORD_TYPE_BOX 65541
74
75
76/**
77 * social place for SecuShare
78 */
79#define GNUNET_GNSRECORD_TYPE_PLACE 65542
80
81
82/**
83 * Endpoint for conversation
84 */
85#define GNUNET_GNSRECORD_TYPE_PHONE 65543
86
87
88/**
89 * identity attribute
90 */
91#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544
92
93
94/**
95 * local ticket reference
96 */
97#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545
98
99
100/**
101 * SBox record
102 */
103#define GNUNET_GNSRECORD_TYPE_SBOX 65547
104
105
106/**
107 * For ABD policies
108 */
109#define GNUNET_GNSRECORD_TYPE_DELEGATE 65548
110
111
112/**
113 * For ABD reverse lookups
114 */
115#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549
116
117
118/**
119 * for reclaim records
120 */
121#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550
122
123
124/**
125 * Redirection record
126 */
127#define GNUNET_GNSRECORD_TYPE_REDIRECT 65551
128
129
130/**
131 * For reclaim OIDC client names.
132 */
133#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552
134
135
136/**
137 * Used reclaimID OIDC client redirect URIs.
138 */
139#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553
140
141
142/**
143 * Record type for an attribute attestation (e.g. JWT).
144 */
145#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554
146
147
148/**
149 * Record type for a presentation of a credential.
150 */
151#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555
152
153
154/**
155 * GNS zone delegation (EDKEY)
156 */
157#define GNUNET_GNSRECORD_TYPE_EDKEY 65556
158
159
160/**
161 * Encoding for Robust Immutable Storage (ERIS) binary read capability
162 */
163#define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557
164
165
166/**
167 * Record type to share an entry of a messenger room
168 */
169#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558
170
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
197#if 0 /* keep Emacsens' auto-indent happy */
198{
199#endif
200#ifdef __cplusplus
201}
202#endif
203
204#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 75c1757ab..cb6e77256 100644
--- a/src/include/gnunet_abd_service.h
+++ b/src/include/gnunet_abd_service.h
@@ -107,7 +107,7 @@ struct GNUNET_ABD_DelegationRecordSet
107 /** 107 /**
108 * Public key of the subject this attribute was delegated to 108 * Public key of the subject this attribute was delegated to
109 */ 109 */
110 struct GNUNET_IDENTITY_PublicKey subject_key; 110 struct GNUNET_CRYPTO_PublicKey subject_key;
111 111
112 /** 112 /**
113 * Length of attribute, may be 0 113 * Length of attribute, may be 0
@@ -127,7 +127,7 @@ struct GNUNET_ABD_DelegationSet
127 /** 127 /**
128 * Public key of the subject this attribute was delegated to 128 * Public key of the subject this attribute was delegated to
129 */ 129 */
130 struct GNUNET_IDENTITY_PublicKey subject_key; 130 struct GNUNET_CRYPTO_PublicKey subject_key;
131 131
132 uint32_t subject_attribute_len; 132 uint32_t subject_attribute_len;
133 133
@@ -147,12 +147,12 @@ struct GNUNET_ABD_Delegation
147 /** 147 /**
148 * The issuer of the delegation 148 * The issuer of the delegation
149 */ 149 */
150 struct GNUNET_IDENTITY_PublicKey issuer_key; 150 struct GNUNET_CRYPTO_PublicKey issuer_key;
151 151
152 /** 152 /**
153 * Public key of the subject this attribute was delegated to 153 * Public key of the subject this attribute was delegated to
154 */ 154 */
155 struct GNUNET_IDENTITY_PublicKey subject_key; 155 struct GNUNET_CRYPTO_PublicKey subject_key;
156 156
157 /** 157 /**
158 * Length of the attribute 158 * Length of the attribute
@@ -185,17 +185,17 @@ struct GNUNET_ABD_Delegate
185 /** 185 /**
186 * The issuer of the credential 186 * The issuer of the credential
187 */ 187 */
188 struct GNUNET_IDENTITY_PublicKey issuer_key; 188 struct GNUNET_CRYPTO_PublicKey issuer_key;
189 189
190 /** 190 /**
191 * Public key of the subject this credential was issued to 191 * Public key of the subject this credential was issued to
192 */ 192 */
193 struct GNUNET_IDENTITY_PublicKey subject_key; 193 struct GNUNET_CRYPTO_PublicKey subject_key;
194 194
195 /** 195 /**
196 * Signature of this credential 196 * Signature of this credential
197 */ 197 */
198 struct GNUNET_IDENTITY_Signature signature; 198 struct GNUNET_CRYPTO_Signature signature;
199 199
200 /** 200 /**
201 * Expiration of this credential 201 * Expiration of this credential
@@ -322,9 +322,9 @@ typedef void (*GNUNET_ABD_RemoveDelegateResultProcessor) (void *cls,
322 */ 322 */
323struct GNUNET_ABD_Request* 323struct GNUNET_ABD_Request*
324 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle, 324 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle,
325 const struct GNUNET_IDENTITY_PublicKey *issuer_key, 325 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
326 const char *issuer_attribute, 326 const char *issuer_attribute,
327 const struct GNUNET_IDENTITY_PublicKey *subject_key, 327 const struct GNUNET_CRYPTO_PublicKey *subject_key,
328 uint32_t delegate_count, 328 uint32_t delegate_count,
329 const struct GNUNET_ABD_Delegate *delegates, 329 const struct GNUNET_ABD_Delegate *delegates,
330 enum GNUNET_ABD_AlgoDirectionFlags direction, 330 enum GNUNET_ABD_AlgoDirectionFlags direction,
@@ -335,9 +335,9 @@ struct GNUNET_ABD_Request*
335 335
336struct GNUNET_ABD_Request* 336struct GNUNET_ABD_Request*
337 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle, 337 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle,
338 const struct GNUNET_IDENTITY_PublicKey *issuer_key, 338 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
339 const char *issuer_attribute, 339 const char *issuer_attribute,
340 const struct GNUNET_IDENTITY_PrivateKey *subject_key, 340 const struct GNUNET_CRYPTO_PrivateKey *subject_key,
341 enum GNUNET_ABD_AlgoDirectionFlags direction, 341 enum GNUNET_ABD_AlgoDirectionFlags direction,
342 GNUNET_ABD_CredentialResultProcessor proc, 342 GNUNET_ABD_CredentialResultProcessor proc,
343 void *proc_cls, 343 void *proc_cls,
@@ -360,7 +360,7 @@ struct GNUNET_ABD_Request *
360GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle, 360GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle,
361 struct GNUNET_IDENTITY_Ego *issuer, 361 struct GNUNET_IDENTITY_Ego *issuer,
362 const char *attribute, 362 const char *attribute,
363 struct GNUNET_IDENTITY_PublicKey *subject, 363 struct GNUNET_CRYPTO_PublicKey *subject,
364 const char *delegated_attribute, 364 const char *delegated_attribute,
365 GNUNET_ABD_DelegateResultProcessor proc, 365 GNUNET_ABD_DelegateResultProcessor proc,
366 void *proc_cls); 366 void *proc_cls);
@@ -393,8 +393,8 @@ GNUNET_ABD_remove_delegation (struct GNUNET_ABD_Handle *handle,
393 * @return handle to the queued request 393 * @return handle to the queued request
394 */ 394 */
395struct GNUNET_ABD_Delegate* 395struct GNUNET_ABD_Delegate*
396GNUNET_ABD_delegate_issue (const struct GNUNET_IDENTITY_PrivateKey *issuer, 396GNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_PrivateKey *issuer,
397 struct GNUNET_IDENTITY_PublicKey *subject, 397 struct GNUNET_CRYPTO_PublicKey *subject,
398 const char *iss_attr, 398 const char *iss_attr,
399 const char *sub_attr, 399 const char *sub_attr,
400 struct GNUNET_TIME_Absolute *expiration); 400 struct GNUNET_TIME_Absolute *expiration);
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 639e723c5..ef860bff4 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -244,8 +244,9 @@ struct GNUNET_ARM_Operation;
244 * #GNUNET_SYSERR if there was an error. 244 * #GNUNET_SYSERR if there was an error.
245 */ 245 */
246typedef void 246typedef void
247(*GNUNET_ARM_ConnectionStatusCallback) (void *cls, 247(*GNUNET_ARM_ConnectionStatusCallback) (
248 int connected); 248 void *cls,
249 enum GNUNET_GenericReturnValue connected);
249 250
250 251
251/** 252/**
@@ -259,9 +260,10 @@ typedef void
259 * @param result result of the operation 260 * @param result result of the operation
260 */ 261 */
261typedef void 262typedef void
262(*GNUNET_ARM_ResultCallback) (void *cls, 263(*GNUNET_ARM_ResultCallback) (
263 enum GNUNET_ARM_RequestStatus rs, 264 void *cls,
264 enum GNUNET_ARM_Result result); 265 enum GNUNET_ARM_RequestStatus rs,
266 enum GNUNET_ARM_Result result);
265 267
266 268
267/** 269/**
@@ -276,10 +278,11 @@ typedef void
276 * @param list list of services managed by arm 278 * @param list list of services managed by arm
277 */ 279 */
278typedef void 280typedef void
279(*GNUNET_ARM_ServiceListCallback) (void *cls, 281(*GNUNET_ARM_ServiceListCallback) (
280 enum GNUNET_ARM_RequestStatus rs, 282 void *cls,
281 unsigned int count, 283 enum GNUNET_ARM_RequestStatus rs,
282 const struct GNUNET_ARM_ServiceInfo *list); 284 unsigned int count,
285 const struct GNUNET_ARM_ServiceInfo *list);
283 286
284 287
285/** 288/**
@@ -294,18 +297,20 @@ typedef void
294 * @return context to use for further ARM operations, NULL on error. 297 * @return context to use for further ARM operations, NULL on error.
295 */ 298 */
296struct GNUNET_ARM_Handle * 299struct GNUNET_ARM_Handle *
297GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 300GNUNET_ARM_connect (
298 GNUNET_ARM_ConnectionStatusCallback conn_status, 301 const struct GNUNET_CONFIGURATION_Handle *cfg,
299 void *conn_status_cls); 302 GNUNET_ARM_ConnectionStatusCallback conn_status,
303 void *conn_status_cls);
300 304
301 305
302/** 306/**
303 * Disconnect from the ARM service and destroy the handle. 307 * Disconnect from the ARM service and destroy the handle.
304 * 308 *
305 * @param h the handle that was being used 309 * @param[in] h the handle that was being used
306 */ 310 */
307void 311void
308GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); 312GNUNET_ARM_disconnect (
313 struct GNUNET_ARM_Handle *h);
309 314
310 315
311/** 316/**
@@ -315,7 +320,8 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
315 * @param op operation to cancel 320 * @param op operation to cancel
316 */ 321 */
317void 322void
318GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op); 323GNUNET_ARM_operation_cancel (
324 struct GNUNET_ARM_Operation *op);
319 325
320 326
321/** 327/**
@@ -327,9 +333,10 @@ GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op);
327 * @return handle for the operation, NULL on error 333 * @return handle for the operation, NULL on error
328 */ 334 */
329struct GNUNET_ARM_Operation * 335struct GNUNET_ARM_Operation *
330GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, 336GNUNET_ARM_request_service_list (
331 GNUNET_ARM_ServiceListCallback cont, 337 struct GNUNET_ARM_Handle *h,
332 void *cont_cls); 338 GNUNET_ARM_ServiceListCallback cont,
339 void *cont_cls);
333 340
334 341
335/** 342/**
@@ -347,10 +354,11 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
347 * @return handle for the operation, NULL on error 354 * @return handle for the operation, NULL on error
348 */ 355 */
349struct GNUNET_ARM_Operation * 356struct GNUNET_ARM_Operation *
350GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, 357GNUNET_ARM_request_service_stop (
351 const char *service_name, 358 struct GNUNET_ARM_Handle *h,
352 GNUNET_ARM_ResultCallback cont, 359 const char *service_name,
353 void *cont_cls); 360 GNUNET_ARM_ResultCallback cont,
361 void *cont_cls);
354 362
355 363
356/** 364/**
@@ -364,12 +372,12 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
364 * @return handle for the operation, NULL on error 372 * @return handle for the operation, NULL on error
365 */ 373 */
366struct GNUNET_ARM_Operation * 374struct GNUNET_ARM_Operation *
367GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, 375GNUNET_ARM_request_service_start (
368 const char *service_name, 376 struct GNUNET_ARM_Handle *h,
369 enum GNUNET_OS_InheritStdioFlags 377 const char *service_name,
370 std_inheritance, 378 enum GNUNET_OS_InheritStdioFlags std_inheritance,
371 GNUNET_ARM_ResultCallback cont, 379 GNUNET_ARM_ResultCallback cont,
372 void *cont_cls); 380 void *cont_cls);
373 381
374 382
375/** 383/**
@@ -386,10 +394,10 @@ struct GNUNET_ARM_MonitorHandle;
386 * @param status status of the service 394 * @param status status of the service
387 */ 395 */
388typedef void 396typedef void
389(*GNUNET_ARM_ServiceMonitorCallback) (void *cls, 397(*GNUNET_ARM_ServiceMonitorCallback) (
390 const char *service, 398 void *cls,
391 enum GNUNET_ARM_ServiceMonitorStatus 399 const char *service,
392 status); 400 enum GNUNET_ARM_ServiceMonitorStatus status);
393 401
394 402
395/** 403/**
@@ -404,9 +412,10 @@ typedef void
404 * @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.
405 */ 413 */
406struct GNUNET_ARM_MonitorHandle * 414struct GNUNET_ARM_MonitorHandle *
407GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 415GNUNET_ARM_monitor_start (
408 GNUNET_ARM_ServiceMonitorCallback cont, 416 const struct GNUNET_CONFIGURATION_Handle *cfg,
409 void *cont_cls); 417 GNUNET_ARM_ServiceMonitorCallback cont,
418 void *cont_cls);
410 419
411 420
412/** 421/**
@@ -415,7 +424,8 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
415 * @param h the handle that was being used 424 * @param h the handle that was being used
416 */ 425 */
417void 426void
418GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h); 427GNUNET_ARM_monitor_stop (
428 struct GNUNET_ARM_MonitorHandle *h);
419 429
420#if 0 /* keep Emacsens' auto-indent happy */ 430#if 0 /* keep Emacsens' auto-indent happy */
421{ 431{
diff --git a/src/include/gnunet_ats_application_service.h b/src/include/gnunet_ats_application_service.h
deleted file mode 100644
index da7fd4b52..000000000
--- a/src/include/gnunet_ats_application_service.h
+++ /dev/null
@@ -1,109 +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 * @addtogroup Backbone
22 * @{
23 *
24 * @file
25 * Bandwidth allocation API for applications to interact with
26 *
27 * @author Christian Grothoff
28 * @author Matthias Wachs
29 *
30 * @defgroup ats ATS service
31 * Bandwidth allocation
32 *
33 * @see [Documentation](https://gnunet.org/ats-subsystem)
34 *
35 * @{
36 */
37#ifndef GNUNET_ATS_APPLICATION_SERVICE_H
38#define GNUNET_ATS_APPLICATION_SERVICE_H
39
40
41#include "gnunet_constants.h"
42#include "gnunet_util_lib.h"
43
44/**
45 * Handle to the ATS subsystem for making suggestions about
46 * connections the peer would like to have.
47 */
48struct GNUNET_ATS_ApplicationHandle;
49
50
51/**
52 * Initialize the ATS application client handle.
53 *
54 * @param cfg configuration to use
55 * @return ats application handle, NULL on error
56 */
57struct GNUNET_ATS_ApplicationHandle *
58GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
59
60
61/**
62 * Shutdown ATS application client.
63 *
64 * @param ch handle to destroy
65 */
66void
67GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch);
68
69
70/**
71 * Handle for suggestion requests.
72 */
73struct GNUNET_ATS_ApplicationSuggestHandle;
74
75
76/**
77 * An application would like to communicate with a peer. ATS should
78 * allocate bandwidth using a suitable address for requiremetns @a pk
79 * to transport.
80 *
81 * @param ch handle
82 * @param peer identity of the peer we need an address for
83 * @param pk what kind of application will the application require (can be
84 * #GNUNET_MQ_PREFERENCE_NONE, we will still try to connect)
85 * @param bw desired bandwidth, can be zero (we will still try to connect)
86 * @return suggestion handle, NULL if request is already pending
87 */
88struct GNUNET_ATS_ApplicationSuggestHandle *
89GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
90 const struct GNUNET_PeerIdentity *peer,
91 enum GNUNET_MQ_PreferenceKind pk,
92 struct GNUNET_BANDWIDTH_Value32NBO bw);
93
94
95/**
96 * We no longer care about communicating with a peer.
97 *
98 * @param sh handle
99 */
100void
101GNUNET_ATS_application_suggest_cancel (struct
102 GNUNET_ATS_ApplicationSuggestHandle *sh);
103
104/** @} */ /* end of group */
105
106/** @} */ /* end of Backbone addition*/
107
108#endif
109/* 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 206f2dd52..000000000
--- a/src/include/gnunet_ats_plugin.h
+++ /dev/null
@@ -1,492 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * API for the ATS solvers.
29 *
30 * @defgroup ats-plugin ATS service plugin API
31 * Plugin API for the ATS service.
32 *
33 * Specifies the struct that is given to the plugin's entry method and the other
34 * struct that must be returned. Note that the destructors of ATS plugins will
35 * be given the value returned by the constructor and is expected to return a
36 * NULL pointer.
37 *
38 * @{
39 */
40#ifndef PLUGIN_ATS_H
41#define PLUGIN_ATS_H
42
43
44#include "gnunet_ats_service.h"
45#include "gnunet_statistics_service.h"
46
47/**
48 * Representation of an address the plugin can choose from.
49 */
50struct ATS_Address;
51
52/**
53 * Change the preference for a peer
54 *
55 * @param handle the solver handle
56 * @param client the client sending this request
57 * @param peer the peer id
58 * @param kind the preference kind to change
59 * @param score the new preference score
60 * @param pref_rel the normalized preference value for this kind over all clients
61 */
62typedef void
63(*GAS_solver_address_change_preference) (void *solver,
64 const struct GNUNET_PeerIdentity *peer,
65 enum GNUNET_ATS_PreferenceKind kind,
66 double pref_rel);
67
68
69/**
70 * Give feedback about the current assignment
71 *
72 * @param handle the solver handle
73 * @param application the application sending this request
74 * @param peer the peer id
75 * @param scope the time interval for this feedback: [now - scope .. now]
76 * @param kind the preference kind for this feedback
77 * @param score the feedback score
78 */
79typedef void
80(*GAS_solver_address_feedback_preference) (void *solver,
81 struct GNUNET_SERVICE_Client *
82 application,
83 const struct
84 GNUNET_PeerIdentity *peer,
85 const struct GNUNET_TIME_Relative
86 scope,
87 enum GNUNET_ATS_PreferenceKind kind,
88 double score);
89
90/**
91 * Notify the solver about a bulk operation changing possibly a lot of values
92 * Solver will not resolve until all bulk operations are marked as done
93 *
94 * @param solver the solver
95 */
96typedef void
97(*GAS_solver_bulk_start) (void *solver);
98
99
100/**
101 * Mark a bulk operation as done
102 * Solver will resolve if values have changed
103 *
104 * @param solver the solver
105 */
106typedef void
107(*GAS_solver_bulk_stop) (void *solver);
108
109
110/**
111 * Add a single address within a network to the solver
112 *
113 * @param solver the solver Handle
114 * @param address the address to add
115 * @param network network type of this address
116 */
117typedef void
118(*GAS_solver_address_add) (void *solver,
119 struct ATS_Address *address,
120 uint32_t network);
121
122
123/**
124 * Delete an address or just the session from the solver
125 *
126 * @param solver the solver Handle
127 * @param address the address to delete
128 */
129typedef void
130(*GAS_solver_address_delete) (void *solver,
131 struct ATS_Address *address);
132
133
134/**
135 * Transport properties for this address have changed
136 *
137 * @param solver solver handle
138 * @param address the address
139 */
140typedef void
141(*GAS_solver_address_property_changed) (void *solver,
142 struct ATS_Address *address);
143
144
145/**
146 * Get the preferred address for a peer from solver
147 *
148 * @param solver the solver to use
149 * @param peer the peer
150 */
151typedef void
152(*GAS_solver_get_preferred_address) (void *solver,
153 const struct GNUNET_PeerIdentity *peer);
154
155
156/**
157 * Stop getting the preferred address for a peer from solver
158 *
159 * @param solver the solver to use
160 * @param peer the peer
161 */
162typedef void
163(*GAS_solver_stop_get_preferred_address) (void *solver,
164 const struct
165 GNUNET_PeerIdentity *peer);
166
167
168/**
169 * Solver functions.
170 *
171 * Each solver is required to set up and return an instance
172 * of this struct during initialization.
173 */
174struct GNUNET_ATS_SolverFunctions
175{
176 /**
177 * Closure to pass to all solver functions in this struct.
178 */
179 void *cls;
180
181 /**
182 * Add a new address for a peer to the solver
183 *
184 * The address is already contained in the addresses hashmap!
185 */
186 GAS_solver_address_add s_add;
187
188 /**
189 * Update the properties of an address in the solver
190 */
191 GAS_solver_address_property_changed s_address_update_property;
192
193 /**
194 * Tell solver to notify ATS if the address to use changes for a specific
195 * peer using the bandwidth changed callback
196 *
197 * The solver must only notify about changes for peers with pending address
198 * requests!
199 */
200 GAS_solver_get_preferred_address s_get;
201
202 /**
203 * Tell solver stop notifying ATS about changes for this peers
204 *
205 * The solver must only notify about changes for peers with pending address
206 * requests!
207 */
208 GAS_solver_stop_get_preferred_address s_get_stop;
209
210 /**
211 * Delete an address in the solver
212 *
213 * The address is not contained in the address hashmap anymore!
214 */
215 GAS_solver_address_delete s_del;
216
217 /**
218 * Change relative preference for quality in solver
219 */
220 GAS_solver_address_change_preference s_pref;
221
222 /**
223 * Give feedback about the current assignment
224 */
225 GAS_solver_address_feedback_preference s_feedback;
226
227 /**
228 * Start a bulk operation
229 *
230 * Used if many values have to be updated at the same time.
231 * When a bulk operation is pending the solver does not have to resolve
232 * the problem since more updates will follow anyway
233 *
234 * For each call to bulk_start, a call to bulk_stop is required!
235 */
236 GAS_solver_bulk_start s_bulk_start;
237
238 /**
239 * Bulk operation done
240 *
241 * If no more bulk operations are pending, the solver can solve the problem
242 * with the updated values
243 */
244 GAS_solver_bulk_stop s_bulk_stop;
245};
246
247
248/**
249 * Operation codes for solver information callback
250 *
251 * Order of calls is expected to be:
252 * #GAS_OP_SOLVE_START
253 * #GAS_OP_SOLVE_STOP
254 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
255 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
256 *
257 */
258enum GAS_Solver_Operation
259{
260 /**
261 * A solution iteration has been started
262 */
263 GAS_OP_SOLVE_START,
264
265 /**
266 * A solution iteration has been finished
267 */
268 GAS_OP_SOLVE_STOP,
269
270 /**
271 * The setup of the problem as a preparation to solve it was started
272 */
273 GAS_OP_SOLVE_SETUP_START,
274
275 /**
276 * The setup of the problem as a preparation to solve is finished
277 */
278 GAS_OP_SOLVE_SETUP_STOP,
279
280 /**
281 * Solving of the LP problem was started
282 * MLP solver only
283 */
284 GAS_OP_SOLVE_MLP_LP_START,
285
286 /**
287 * Solving of the LP problem is done
288 * MLP solver only
289 */
290 GAS_OP_SOLVE_MLP_LP_STOP,
291
292 /**
293 * Solving of the MLP problem was started
294 * MLP solver only
295 */
296 GAS_OP_SOLVE_MLP_MLP_START,
297
298 /**
299 * Solving of the MLP problem is done
300 * MLP solver only
301 */
302 GAS_OP_SOLVE_MLP_MLP_STOP,
303
304 /**
305 * After the problem was finished, start notifications about changes
306 * to addresses
307 */
308 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
309
310 /**
311 * After the problem was finished, notifications about changes to addresses
312 * are done
313 */
314 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
315};
316
317
318/**
319 * Status of a GAS_Solver_Operation operation
320 */
321enum GAS_Solver_Status
322{
323 /**
324 * Success
325 */
326 GAS_STAT_SUCCESS,
327
328 /**
329 * Failure
330 */
331 GAS_STAT_FAIL
332};
333
334
335/**
336 * Status of the operation
337 */
338enum GAS_Solver_Additional_Information
339{
340 /**
341 * No more specific information
342 */
343 GAS_INFO_NONE,
344
345 /**
346 * A full solution process is performed
347 * Quite specific to the MLP solver
348 */
349 GAS_INFO_FULL,
350
351 /**
352 * An existing solution was reused
353 * Quite specific to the MLP solver
354 */
355 GAS_INFO_UPDATED,
356
357 /**
358 * The proportional solver had to recalculate for a single network
359 */
360 GAS_INFO_PROP_SINGLE,
361
362 /**
363 * The proportional solver had to recalculate for all networks
364 */
365 GAS_INFO_PROP_ALL
366};
367
368
369/**
370 * Callback to call with additional information
371 * Used for measurement
372 *
373 * @param cls the closure
374 * @param op the operation
375 */
376typedef void
377(*GAS_solver_information_callback) (void *cls,
378 enum GAS_Solver_Operation op,
379 enum GAS_Solver_Status stat,
380 enum GAS_Solver_Additional_Information);
381
382
383/**
384 * Callback to call from solver when bandwidth for address has changed
385 *
386 * @param address the with changed bandwidth assigned
387 */
388typedef void
389(*GAS_bandwidth_changed_cb) (void *cls,
390 struct ATS_Address *address);
391
392
393/**
394 * Callback to call from solver to obtain application preference
395 * values for a peer.
396 *
397 * @param cls the cls
398 * @param id the peer id
399 * @return carry of double values containing the preferences with
400 * GNUNET_ATS_PreferenceCount elements
401 */
402typedef const double *
403(*GAS_get_preferences) (void *cls,
404 const struct GNUNET_PeerIdentity *id);
405
406
407/**
408 * Callback to call from solver to obtain application connectivity
409 * preferences for a peer.
410 *
411 * @param cls the cls
412 * @param id the peer id
413 * @return 0 if connectivity is not desired, non-null if address
414 * suggestions are requested
415 */
416typedef unsigned int
417(*GAS_get_connectivity) (void *cls,
418 const struct GNUNET_PeerIdentity *id);
419
420
421/**
422 * The ATS plugin will pass a pointer to a struct
423 * of this type as to the initialization function
424 * of the ATS plugins.
425 */
426struct GNUNET_ATS_PluginEnvironment
427{
428 /**
429 * Configuration handle to be used by the solver
430 */
431 const struct GNUNET_CONFIGURATION_Handle *cfg;
432
433 /**
434 * Statistics handle to be used by the solver
435 */
436 struct GNUNET_STATISTICS_Handle *stats;
437
438 /**
439 * Closure to pass to all callbacks in this struct.
440 */
441 void *cls;
442
443 /**
444 * Hashmap containing all addresses available
445 */
446 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
447
448 /**
449 * ATS addresses callback to be notified about bandwidth assignment changes
450 */
451 GAS_bandwidth_changed_cb bandwidth_changed_cb;
452
453 /**
454 * ATS addresses function to obtain preference values
455 */
456 GAS_get_preferences get_preferences;
457
458 /**
459 * ATS addresses function to obtain preference values
460 */
461 GAS_get_connectivity get_connectivity;
462
463 /**
464 * Callback for solver to call with status information,
465 * can be NULL
466 */
467 GAS_solver_information_callback info_cb;
468
469 /**
470 * Number of networks available, size of the @e out_quota
471 * and @e in_quota arrays.
472 */
473 unsigned int network_count;
474
475 /**
476 * Array of configured outbound quotas
477 * Order according to networks in network array
478 */
479 unsigned long long out_quota[GNUNET_NT_COUNT];
480
481 /**
482 * Array of configured inbound quotas
483 * Order according to networks in network array
484 */
485 unsigned long long in_quota[GNUNET_NT_COUNT];
486};
487
488#endif
489
490/** @} */ /* end of group */
491
492/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h
deleted file mode 100644
index ce149875a..000000000
--- a/src/include/gnunet_ats_service.h
+++ /dev/null
@@ -1,631 +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 * @addtogroup Backbone
22 * @{
23 *
24 * @file
25 * Automatic transport selection and outbound bandwidth determination
26 *
27 * @author Christian Grothoff
28 * @author Matthias Wachs
29 *
30 * @defgroup ats ATS service
31 * Automatic Transport Selection and outbound bandwidth determination
32 *
33 * @see [Documentation](https://gnunet.org/ats-subsystem)
34 *
35 * @{
36 */
37#ifndef GNUNET_ATS_SERVICE_H
38#define GNUNET_ATS_SERVICE_H
39
40
41#include "gnunet_constants.h"
42#include "gnunet_util_lib.h"
43#include "gnunet_hello_lib.h"
44
45
46/**
47 * Default bandwidth assigned to a network : 64 KB/s
48 */
49#define GNUNET_ATS_DefaultBandwidth 65536
50
51/**
52 * Undefined value for an `enum GNUNET_ATS_Property`
53 */
54#define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
55
56/**
57 * String representation for GNUNET_ATS_VALUE_UNDEFINED
58 */
59#define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
60
61/**
62 * Maximum bandwidth assigned to a network : 4095 MB/s
63 */
64#define GNUNET_ATS_MaxBandwidth UINT32_MAX
65
66/**
67 * Textual equivalent for GNUNET_ATS_MaxBandwidth
68 */
69#define GNUNET_ATS_MaxBandwidthString "unlimited"
70
71
72/**
73 * ATS performance characteristics for an address.
74 */
75struct GNUNET_ATS_Properties
76{
77 /**
78 * Delay. Time between when the time packet is sent and the packet
79 * arrives. FOREVER if we did not measure yet.
80 */
81 struct GNUNET_TIME_Relative delay;
82
83 /**
84 * Actual traffic on this connection from this peer to the other peer.
85 * Includes transport overhead.
86 *
87 * Unit: [bytes/second]
88 */
89 uint32_t utilization_out;
90
91 /**
92 * Actual traffic on this connection from the other peer to this peer.
93 * Includes transport overhead.
94 *
95 * Unit: [bytes/second]
96 */
97 uint32_t utilization_in;
98
99 /**
100 * Distance on network layer (required for distance-vector routing)
101 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
102 */
103 unsigned int distance;
104
105 /**
106 * Which network scope does the respective address belong to?
107 * This property does not change.
108 */
109 enum GNUNET_NetworkType scope;
110};
111
112
113/**
114 * ATS performance characteristics for an address in
115 * network byte order (for IPC).
116 */
117struct GNUNET_ATS_PropertiesNBO
118{
119 /**
120 * Actual traffic on this connection from this peer to the other peer.
121 * Includes transport overhead.
122 *
123 * Unit: [bytes/second]
124 */
125 uint32_t utilization_out GNUNET_PACKED;
126
127 /**
128 * Actual traffic on this connection from the other peer to this peer.
129 * Includes transport overhead.
130 *
131 * Unit: [bytes/second]
132 */
133 uint32_t utilization_in GNUNET_PACKED;
134
135 /**
136 * Which network scope does the respective address belong to?
137 * This property does not change.
138 */
139 uint32_t scope GNUNET_PACKED;
140
141 /**
142 * Distance on network layer (required for distance-vector routing)
143 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
144 */
145 uint32_t distance GNUNET_PACKED;
146
147 /**
148 * Delay. Time between when the time packet is sent and the packet
149 * arrives. FOREVER if we did not measure yet.
150 */
151 struct GNUNET_TIME_RelativeNBO delay;
152};
153
154
155/* ********************* LAN Characterization library ************************ */
156/* Note: these functions do not really communicate with the ATS service */
157
158
159/**
160 * Convert ATS properties from host to network byte order.
161 *
162 * @param nbo[out] value written
163 * @param hbo value read
164 */
165void
166GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
167 const struct GNUNET_ATS_Properties *hbo);
168
169
170/**
171 * Convert ATS properties from network to host byte order.
172 *
173 * @param hbo[out] value written
174 * @param nbo value read
175 */
176void
177GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
178 const struct GNUNET_ATS_PropertiesNBO *nbo);
179
180
181/* ********************Connection Suggestion API ***************************** */
182
183/**
184 * Handle to the ATS subsystem for making suggestions about
185 * connections the peer would like to have.
186 */
187struct GNUNET_ATS_ConnectivityHandle;
188
189/**
190 * Handle for address suggestion requests.
191 */
192struct GNUNET_ATS_ConnectivitySuggestHandle;
193
194
195/**
196 * Initialize the ATS connectivity suggestion client handle.
197 *
198 * @param cfg configuration to use
199 * @return ats connectivity handle, NULL on error
200 */
201struct GNUNET_ATS_ConnectivityHandle *
202GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
203
204
205/**
206 * Shutdown ATS connectivity suggestion client.
207 *
208 * @param ch handle to destroy
209 */
210void
211GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
212
213
214/**
215 * We would like to establish a new connection with a peer. ATS
216 * should suggest a good address to begin with.
217 *
218 * @param ch handle
219 * @param peer identity of the peer we need an address for
220 * @param strength how urgent is the need for such a suggestion
221 * @return suggestion handle, NULL if request is already pending
222 */
223struct GNUNET_ATS_ConnectivitySuggestHandle *
224GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
225 const struct GNUNET_PeerIdentity *peer,
226 uint32_t strength);
227
228
229/**
230 * We no longer care about being connected to a peer.
231 *
232 * @param sh handle to stop
233 */
234void
235GNUNET_ATS_connectivity_suggest_cancel (struct
236 GNUNET_ATS_ConnectivitySuggestHandle *sh);
237
238
239/* ******************************** Scheduling API ***************************** */
240
241/**
242 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
243 */
244struct GNUNET_ATS_SchedulingHandle;
245
246/**
247 * Opaque session handle, defined by plugins. Contents not known to ATS.
248 */
249struct GNUNET_ATS_Session;
250
251
252/**
253 * Signature of a function called by ATS with the current bandwidth
254 * and address preferences as determined by ATS. If our connection
255 * to ATS dies and thus all suggestions become invalid, this function
256 * is called ONCE with all arguments (except @a cls) being NULL/0.
257 *
258 * @param cls closure
259 * @param peer for which we suggest an address, NULL if ATS connection died
260 * @param address suggested address (including peer identity of the peer),
261 * may be NULL to signal disconnect from peer
262 * @param session session to use, NULL to establish a new outgoing session
263 * @param bandwidth_out assigned outbound bandwidth for the connection,
264 * 0 to signal disconnect
265 * @param bandwidth_in assigned inbound bandwidth for the connection,
266 * 0 to signal disconnect
267 */
268typedef void
269(*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
270 const struct GNUNET_PeerIdentity *peer,
271 const struct
272 GNUNET_HELLO_Address *address,
273 struct GNUNET_ATS_Session *session,
274 struct GNUNET_BANDWIDTH_Value32NBO
275 bandwidth_out,
276 struct GNUNET_BANDWIDTH_Value32NBO
277 bandwidth_in);
278
279
280/**
281 * Initialize the ATS scheduling subsystem.
282 *
283 * @param cfg configuration to use
284 * @param suggest_cb notification to call whenever the suggestation changed
285 * @param suggest_cb_cls closure for @a suggest_cb
286 * @return ats context
287 */
288struct GNUNET_ATS_SchedulingHandle *
289GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
290 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
291 void *suggest_cb_cls);
292
293
294/**
295 * Client is done with ATS scheduling, release resources.
296 *
297 * @param sh handle to release
298 */
299void
300GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
301
302
303/**
304 * Handle used within ATS to track an address.
305 */
306struct GNUNET_ATS_AddressRecord;
307
308
309/**
310 * We have a new address ATS should know. Addresses have to be added with this
311 * function before they can be: updated, set in use and destroyed
312 *
313 * @param sh handle
314 * @param address the address
315 * @param session session handle (if available, e.g for incoming connections)
316 * @param prop performance data for the address
317 * @return handle to the address representation inside ATS, NULL
318 * on error (i.e. ATS knows this exact address already, or
319 * address is invalid)
320 */
321struct GNUNET_ATS_AddressRecord *
322GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
323 const struct GNUNET_HELLO_Address *address,
324 struct GNUNET_ATS_Session *session,
325 const struct GNUNET_ATS_Properties *prop);
326
327
328/**
329 * An address was used to initiate a session.
330 *
331 * @param ar address record to update information for
332 * @param session session handle
333 */
334void
335GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
336 struct GNUNET_ATS_Session *session);
337
338
339/**
340 * A @a session was destroyed, disassociate it from the given address
341 * record. If this was an incoming address, destroys the address as
342 * well.
343 *
344 * @param ar address record to update information for
345 * @param session session handle
346 * @return #GNUNET_YES if the @a ar was destroyed because
347 * it was an incoming address,
348 * #GNUNET_NO if the @a ar was kept because we can
349 * use it still to establish a new session
350 */
351int
352GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
353 struct GNUNET_ATS_Session *session);
354
355
356/**
357 * We have updated performance statistics for a given address. Note
358 * that this function can be called for addresses that are currently
359 * in use as well as addresses that are valid but not actively in use.
360 * Furthermore, the peer may not even be connected to us right now (@a
361 * session value of NULL used to signal disconnect, or somehow we
362 * otherwise got updated on @a ats information). Based on the
363 * information provided, ATS may update bandwidth assignments and
364 * suggest to switch addresses.
365 *
366 * @param ar address record to update information for
367 * @param prop performance data for the address
368 */
369void
370GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
371 const struct GNUNET_ATS_Properties *prop);
372
373
374/**
375 * An address got destroyed, stop using it as a valid address.
376 *
377 * @param ar address record to destroy, its validation has
378 * expired and ATS may no longer use it
379 */
380void
381GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
382
383
384/* ******************************** Performance API ***************************** */
385
386/**
387 * ATS Handle to obtain and/or modify performance information.
388 */
389struct GNUNET_ATS_PerformanceHandle;
390
391/**
392 * Signature of a function that is called with QoS information about an address.
393 *
394 * @param cls closure
395 * @param address the address, NULL if ATS service was disconnected or
396 * when the iteration is completed in the case of
397 * #GNUNET_ATS_performance_list_addresses()
398 * @param address_active #GNUNET_YES if this address is actively used
399 * to maintain a connection to a peer;
400 * #GNUNET_NO if the address is not actively used;
401 * #GNUNET_SYSERR if this address is no longer available for ATS
402 * @param bandwidth_out assigned outbound bandwidth for the connection
403 * @param bandwidth_in assigned inbound bandwidth for the connection
404 * @param prop performance data for the address
405 */
406typedef void
407(*GNUNET_ATS_AddressInformationCallback) (void *cls,
408 const struct
409 GNUNET_HELLO_Address *address,
410 int address_active,
411 struct GNUNET_BANDWIDTH_Value32NBO
412 bandwidth_out,
413 struct GNUNET_BANDWIDTH_Value32NBO
414 bandwidth_in,
415 const struct
416 GNUNET_ATS_Properties *prop);
417
418
419/**
420 * Handle for an address listing operation
421 */
422struct GNUNET_ATS_AddressListHandle;
423
424
425/**
426 * Get handle to access performance API of the ATS subsystem.
427 *
428 * @param cfg configuration to use
429 * @param addr_info_cb callback called when performance characteristics for
430 * an address change
431 * @param addr_info_cb_cls closure for @a addr_info_cb
432 * @return ats performance context
433 */
434struct GNUNET_ATS_PerformanceHandle *
435GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
436 GNUNET_ATS_AddressInformationCallback addr_info_cb,
437 void *addr_info_cb_cls);
438
439
440/**
441 * Get information about addresses known to the ATS subsystem.
442 *
443 * @param ph the performance handle to use
444 * @param peer peer idm can be NULL for all peers
445 * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO to
446 * get only address currently used
447 * @param infocb callback to call with the addresses,
448 * will callback with address == NULL when done
449 * @param infocb_cls closure for @a infocb
450 * @return handle to abort the operation
451 */
452struct GNUNET_ATS_AddressListHandle *
453GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph,
454 const struct GNUNET_PeerIdentity *peer,
455 int all,
456 GNUNET_ATS_AddressInformationCallback
457 infocb,
458 void *infocb_cls);
459
460
461/**
462 * Cancel a pending address listing operation
463 *
464 * @param alh the `struct GNUNET_ATS_AddressListHandle` handle to cancel
465 */
466void
467GNUNET_ATS_performance_list_addresses_cancel (struct
468 GNUNET_ATS_AddressListHandle *alh);
469
470
471/**
472 * Client is done using the ATS performance subsystem, release resources.
473 *
474 * @param ph handle
475 */
476void
477GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
478
479
480/**
481 * Function called with reservation result.
482 *
483 * @param cls closure
484 * @param peer identifies the peer
485 * @param amount set to the amount that was actually reserved or unreserved;
486 * either the full requested amount or zero (no partial reservations)
487 * @param res_delay if the reservation could not be satisfied (amount was 0), how
488 * long should the client wait until re-trying?
489 */
490typedef void
491(*GNUNET_ATS_ReservationCallback) (void *cls,
492 const struct GNUNET_PeerIdentity *peer,
493 int32_t amount,
494 struct GNUNET_TIME_Relative res_delay);
495
496
497/**
498 * Context that can be used to cancel a peer information request.
499 */
500struct GNUNET_ATS_ReservationContext;
501
502
503/**
504 * Reserve inbound bandwidth from the given peer. ATS will look at
505 * the current amount of traffic we receive from the peer and ensure
506 * that the peer could add 'amount' of data to its stream.
507 *
508 * @param ph performance handle
509 * @param peer identifies the peer
510 * @param amount reserve N bytes for receiving, negative
511 * amounts can be used to undo a (recent) reservation;
512 * @param rcb function to call with the resulting reservation information
513 * @param rcb_cls closure for @a rcb
514 * @return NULL on error
515 * @deprecated will be replaced soon
516 */
517struct GNUNET_ATS_ReservationContext *
518GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
519 const struct GNUNET_PeerIdentity *peer,
520 int32_t amount,
521 GNUNET_ATS_ReservationCallback rcb,
522 void *rcb_cls);
523
524
525/**
526 * Cancel request for reserving bandwidth.
527 *
528 * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call
529 */
530void
531GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
532
533
534/**
535 * ATS preference types as array initializer
536 */
537#define GNUNET_ATS_PreferenceType { GNUNET_ATS_PREFERENCE_BANDWIDTH, \
538 GNUNET_ATS_PREFERENCE_LATENCY, \
539 GNUNET_ATS_PREFERENCE_END }
540
541/**
542 * ATS preference types as string array initializer
543 */
544#define GNUNET_ATS_PreferenceTypeString { "BANDWIDTH", "LATENCY", "END" }
545
546/**
547 * Enum defining all known preference categories.
548 */
549enum GNUNET_ATS_PreferenceKind
550{
551 /**
552 * Change the peer's bandwidth value (value per byte of bandwidth in
553 * the goal function) to the given amount. The argument is followed
554 * by a double value giving the desired value (can be negative).
555 * Preference changes are forgotten if peers disconnect.
556 */
557 GNUNET_ATS_PREFERENCE_BANDWIDTH = 0,
558
559 /**
560 * Change the peer's latency value to the given amount. The
561 * argument is followed by a double value giving the desired value
562 * (can be negative). The absolute score in the goal function is
563 * the inverse of the latency in microseconds (minimum: 1
564 * microsecond) multiplied by the latency preferences.
565 */
566 GNUNET_ATS_PREFERENCE_LATENCY = 1,
567
568 /**
569 * End of preference list.
570 */
571 GNUNET_ATS_PREFERENCE_END = 2
572};
573
574
575/**
576 * Convert an `enum GNUNET_ATS_PreferenceType` to a string
577 *
578 * @param type the preference type
579 * @return a string or NULL if invalid
580 */
581const char *
582GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type);
583
584
585/**
586 * Change preferences for the given peer. Preference changes are
587 * forgotten if peers disconnect.
588 *
589 * @param ph performance handle
590 * @param peer identifies the peer
591 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the
592 * desired changes
593 */
594void
595GNUNET_ATS_performance_change_preference (struct
596 GNUNET_ATS_PerformanceHandle *ph,
597 const struct
598 GNUNET_PeerIdentity *peer,
599 ...);
600
601
602/**
603 * Application feedback on how good preference requirements are fulfilled
604 * for the preferences included in the given time scope [now - scope .. now]
605 *
606 * An application notifies ATS if (and only if) it has feedback information
607 * for specific properties. This values are valid until the feedback scores are
608 * updated by the application.
609 *
610 * If the application has no feedback for this preference kind the application
611 * will not explicitly call for this property and will not include it in this
612 * function call.
613 *
614 * @param ph performance handle
615 * @param scope the time interval this valid for: [now - scope .. now]
616 * @param peer identifies the peer
617 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
618 */
619void
620GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
621 const struct GNUNET_PeerIdentity *peer,
622 const struct GNUNET_TIME_Relative scope,
623 ...);
624
625#endif
626
627/** @} */ /* end of group */
628
629/** @} */ /* end of Backbone addition */
630
631/* 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 b6c7b15ae..000000000
--- a/src/include/gnunet_ats_transport_service.h
+++ /dev/null
@@ -1,241 +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
38#include "gnunet_constants.h"
39#include "gnunet_util_lib.h"
40#include "gnunet_nt_lib.h"
41#include "gnunet_transport_communication_service.h"
42
43
44/**
45 * ATS performance characteristics for a session.
46 */
47struct GNUNET_ATS_Properties
48{
49 /**
50 * Delay. Time between when the time packet is sent and the packet
51 * arrives. FOREVER if we did not (successfully) measure yet.
52 */
53 struct GNUNET_TIME_Relative delay;
54
55 /**
56 * Confirmed successful payload on this connection from this peer to
57 * the other peer.
58 *
59 * Unit: [bytes/second]
60 */
61 uint32_t goodput_out;
62
63 /**
64 * Confirmed useful payload on this connection to this peer from
65 * the other peer.
66 *
67 * Unit: [bytes/second]
68 */
69 uint32_t goodput_in;
70
71 /**
72 * Actual traffic on this connection from this peer to the other peer.
73 * Includes transport overhead.
74 *
75 * Unit: [bytes/second]
76 */
77 uint32_t utilization_out;
78
79 /**
80 * Actual traffic on this connection from the other peer to this peer.
81 * Includes transport overhead.
82 *
83 * Unit: [bytes/second]
84 */
85 uint32_t utilization_in;
86
87 /**
88 * Distance on network layer (required for distance-vector routing)
89 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
90 */
91 uint32_t distance;
92
93 /**
94 * MTU of the network layer, UINT32_MAX for no MTU (stream).
95 *
96 * Unit: [bytes]
97 */
98 uint32_t mtu;
99
100 /**
101 * Which network scope does the respective address belong to?
102 */
103 enum GNUNET_NetworkType nt;
104
105 /**
106 * What characteristics does this communicator have?
107 */
108 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
109};
110
111
112/* ******************************** Transport API ***************************** */
113
114/**
115 * Handle to the ATS subsystem for bandwidth/transport transport information.
116 */
117struct GNUNET_ATS_TransportHandle;
118
119/**
120 * Opaque session handle, to be defined by transport. Contents not known to ATS.
121 */
122struct GNUNET_ATS_Session;
123
124
125/**
126 * Signature of a function called by ATS with the current bandwidth
127 * allocation to be used as determined by ATS.
128 *
129 * @param cls closure
130 * @param session session this is about
131 * @param bandwidth_out assigned outbound bandwidth for the connection,
132 * 0 to signal disconnect
133 * @param bandwidth_in assigned inbound bandwidth for the connection,
134 * 0 to signal disconnect
135 */
136typedef void
137(*GNUNET_ATS_AllocationCallback) (void *cls,
138 struct GNUNET_ATS_Session *session,
139 struct GNUNET_BANDWIDTH_Value32NBO
140 bandwidth_out,
141 struct GNUNET_BANDWIDTH_Value32NBO
142 bandwidth_in);
143
144
145/**
146 * Signature of a function called by ATS suggesting transport to
147 * try connecting with a particular address.
148 *
149 * @param cls closure
150 * @param pid target peer
151 * @param address the address to try
152 */
153typedef void
154(*GNUNET_ATS_SuggestionCallback) (void *cls,
155 const struct GNUNET_PeerIdentity *pid,
156 const char *address);
157
158
159/**
160 * Initialize the ATS transport subsystem.
161 *
162 * @param cfg configuration to use
163 * @param alloc_cb notification to call whenever the allocation changed
164 * @param alloc_cb_cls closure for @a alloc_cb
165 * @param suggest_cb notification to call whenever the suggestation is made
166 * @param suggest_cb_cls closure for @a suggest_cb
167 * @return ats context
168 */
169struct GNUNET_ATS_TransportHandle *
170GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
171 GNUNET_ATS_AllocationCallback alloc_cb,
172 void *alloc_cb_cls,
173 GNUNET_ATS_SuggestionCallback suggest_cb,
174 void *suggest_cb_cls);
175
176
177/**
178 * Client is done with ATS transport, release resources.
179 *
180 * @param ath handle to release
181 */
182void
183GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath);
184
185
186/**
187 * Handle used within ATS to track an session.
188 */
189struct GNUNET_ATS_SessionRecord;
190
191
192/**
193 * We have a new session ATS should know. Sessiones have to be added with this
194 * function before they can be: updated, set in use and destroyed
195 *
196 * @param ath handle
197 * @param pid peer we connected to
198 * @param address the address (human readable version),
199 * @param session transport-internal handle for the session/queue, NULL if
200 * the session is inbound-only
201 * @param prop performance data for the session
202 * @return handle to the session representation inside ATS, NULL
203 * on error (i.e. ATS knows this exact session already, or
204 * session is invalid)
205 */
206struct GNUNET_ATS_SessionRecord *
207GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
208 const struct GNUNET_PeerIdentity *pid,
209 const char *address,
210 struct GNUNET_ATS_Session *session,
211 const struct GNUNET_ATS_Properties *prop);
212
213
214/**
215 * We have updated performance statistics for a given session. Based
216 * on the information provided, ATS may update bandwidth assignments.
217 *
218 * @param ar session record to update information for
219 * @param prop performance data for the session
220 */
221void
222GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
223 const struct GNUNET_ATS_Properties *prop);
224
225
226/**
227 * A session was destroyed, ATS should now schedule and
228 * allocate under the assumption that this @a ar is no
229 * longer in use.
230 *
231 * @param ar session record to drop
232 */
233void
234GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar);
235
236
237#endif
238
239/** @} */ /* end of group */
240
241/* 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 7c854aab5..00a7d6c5d 100644
--- a/src/include/gnunet_bandwidth_lib.h
+++ b/src/include/gnunet_bandwidth_lib.h
@@ -18,10 +18,6 @@
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 * @addtogroup libgnunetutil 22 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs 23 * Multi-function utilities library for GNUnet programs
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 48a1a512d..73550db7e 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -33,6 +33,7 @@
33 * @{ 33 * @{
34 */ 34 */
35 35
36#include "gnunet_common.h"
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 37#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly." 38#error "Only <gnunet_util_lib.h> can be included directly."
38#endif 39#endif
@@ -88,7 +89,7 @@ GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
88 * @param emsg set to the error message 89 * @param emsg set to the error message
89 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
90 */ 91 */
91int 92enum GNUNET_GenericReturnValue
92GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); 93GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
93 94
94/** 95/**
@@ -110,7 +111,7 @@ GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg);
110 * @param len the number of bytes to read 111 * @param len the number of bytes to read
111 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 112 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
112 */ 113 */
113int 114enum GNUNET_GenericReturnValue
114GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 115GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
115 const char *what, 116 const char *what,
116 void *result, 117 void *result,
@@ -127,7 +128,7 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
127 * @param max_length maximum allowed length for the string 128 * @param max_length maximum allowed length for the string
128 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
129 */ 130 */
130int 131enum GNUNET_GenericReturnValue
131GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 132GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
132 const char *what, 133 const char *what,
133 char **result, 134 char **result,
@@ -142,7 +143,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
142 * @param what describes what is being read (for error message creation) 143 * @param what describes what is being read (for error message creation)
143 * @param f address of float to read 144 * @param f address of float to read
144 */ 145 */
145int 146enum GNUNET_GenericReturnValue
146GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, 147GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
147 const char *what, 148 const char *what,
148 float *f); 149 float *f);
@@ -155,7 +156,7 @@ GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
155 * @param what describes what is being read (for error message creation) 156 * @param what describes what is being read (for error message creation)
156 * @param f address of double to read 157 * @param f address of double to read
157 */ 158 */
158int 159enum GNUNET_GenericReturnValue
159GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, 160GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
160 const char *what, 161 const char *what,
161 double *f); 162 double *f);
@@ -169,7 +170,7 @@ GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
169 * @param i where to store the data 170 * @param i where to store the data
170 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 171 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
171 */ 172 */
172int 173enum GNUNET_GenericReturnValue
173GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, 174GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
174 const char *what, 175 const char *what,
175 int32_t *i); 176 int32_t *i);
@@ -183,7 +184,7 @@ GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
183 * @param i where to store the data 184 * @param i where to store the data
184 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
185 */ 186 */
186int 187enum GNUNET_GenericReturnValue
187GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, 188GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
188 const char *what, 189 const char *what,
189 int64_t *i); 190 int64_t *i);
@@ -224,7 +225,7 @@ GNUNET_BIO_write_open_buffer (void);
224 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned 225 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
225 * and the file is closed 226 * and the file is closed
226 */ 227 */
227int 228enum GNUNET_GenericReturnValue
228GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); 229GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
229 230
230 231
@@ -240,7 +241,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
240 * @param size where to store the size of @e contents 241 * @param size where to store the size of @e contents
241 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 242 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
242 */ 243 */
243int 244enum GNUNET_GenericReturnValue
244GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 245GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
245 char **emsg, 246 char **emsg,
246 void **contents, 247 void **contents,
@@ -256,7 +257,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
256 * 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
257 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 258 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
258 */ 259 */
259int 260enum GNUNET_GenericReturnValue
260GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); 261GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
261 262
262 263
@@ -269,7 +270,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
269 * @param n number of bytes to write 270 * @param n number of bytes to write
270 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 271 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
271 */ 272 */
272int 273enum GNUNET_GenericReturnValue
273GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 274GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
274 const char *what, 275 const char *what,
275 const void *buffer, 276 const void *buffer,
@@ -284,7 +285,7 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
284 * @param s string to write (can be NULL) 285 * @param s string to write (can be NULL)
285 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 286 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
286 */ 287 */
287int 288enum GNUNET_GenericReturnValue
288GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 289GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
289 const char *what, 290 const char *what,
290 const char *s); 291 const char *s);
@@ -298,7 +299,7 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
298 * @param what what is being written (for error message creation) 299 * @param what what is being written (for error message creation)
299 * @param f float to write (must be a variable) 300 * @param f float to write (must be a variable)
300 */ 301 */
301int 302enum GNUNET_GenericReturnValue
302GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, 303GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
303 const char *what, 304 const char *what,
304 float f); 305 float f);
@@ -310,7 +311,7 @@ GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
310 * @param what what is being written (for error message creation) 311 * @param what what is being written (for error message creation)
311 * @param f double to write (must be a variable) 312 * @param f double to write (must be a variable)
312 */ 313 */
313int 314enum GNUNET_GenericReturnValue
314GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, 315GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
315 const char *what, 316 const char *what,
316 double f); 317 double f);
@@ -324,7 +325,7 @@ GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
324 * @param i 32-bit integer to write 325 * @param i 32-bit integer to write
325 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
326 */ 327 */
327int 328enum GNUNET_GenericReturnValue
328GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 329GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
329 const char *what, 330 const char *what,
330 int32_t i); 331 int32_t i);
@@ -338,7 +339,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
338 * @param i 64-bit integer to write 339 * @param i 64-bit integer to write
339 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 340 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
340 */ 341 */
341int 342enum GNUNET_GenericReturnValue
342GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 343GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
343 const char *what, 344 const char *what,
344 int64_t i); 345 int64_t i);
@@ -489,7 +490,7 @@ GNUNET_BIO_read_spec_double (const char *what, double *f);
489 * the last element must be #GNUNET_BIO_read_spec_end 490 * the last element must be #GNUNET_BIO_read_spec_end
490 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 491 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
491 */ 492 */
492int 493enum GNUNET_GenericReturnValue
493GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, 494GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
494 struct GNUNET_BIO_ReadSpec *rs); 495 struct GNUNET_BIO_ReadSpec *rs);
495 496
@@ -635,7 +636,7 @@ GNUNET_BIO_write_spec_double (const char *what, double *f);
635 * the last element must be #GNUNET_BIO_write_spec_end 636 * the last element must be #GNUNET_BIO_write_spec_end
636 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 637 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
637 */ 638 */
638int 639enum GNUNET_GenericReturnValue
639GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, 640GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
640 struct GNUNET_BIO_WriteSpec *ws); 641 struct GNUNET_BIO_WriteSpec *ws);
641 642
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index acc7bb330..ab53d2bd8 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -47,7 +47,6 @@ extern "C" {
47 47
48 48
49#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
50#include "gnunet_transport_service.h"
51 50
52/** 51/**
53 * Version number of GNUnet-cadet API. 52 * Version number of GNUnet-cadet API.
@@ -636,4 +635,3 @@ GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt);
636/** @} */ /* end of group addition */ 635/** @} */ /* end of group addition */
637 636
638/* end of gnunet_cadet_service.h */ 637/* end of gnunet_cadet_service.h */
639
diff --git a/src/include/gnunet_child_management_lib.h b/src/include/gnunet_child_management_lib.h
index d8f63b60d..ab0ab93eb 100644
--- a/src/include/gnunet_child_management_lib.h
+++ b/src/include/gnunet_child_management_lib.h
@@ -18,7 +18,7 @@
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__) 21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly." 22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif 23#endif
24 24
@@ -49,8 +49,7 @@ struct GNUNET_ChildWaitHandle;
49 * @param cls handle for the callback 49 * @param cls handle for the callback
50 * @param type type of the process 50 * @param type type of the process
51 * @param exit_code status code of the process 51 * @param exit_code status code of the process
52 * 52 */
53*/
54typedef void 53typedef void
55(*GNUNET_ChildCompletedCallback)(void *cls, 54(*GNUNET_ChildCompletedCallback)(void *cls,
56 enum GNUNET_OS_ProcessStatusType type, 55 enum GNUNET_OS_ProcessStatusType type,
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 9b2b50f01..c5885e7c4 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -55,20 +55,20 @@
55#if defined(__FreeBSD__) 55#if defined(__FreeBSD__)
56 56
57#include <sys/endian.h> 57#include <sys/endian.h>
58#define bswap_32(x) bswap32(x) 58#define bswap_32(x) bswap32 (x)
59#define bswap_64(x) bswap64(x) 59#define bswap_64(x) bswap64 (x)
60 60
61#elif defined(__OpenBSD__) 61#elif defined(__OpenBSD__)
62 62
63#define bswap_32(x) swap32(x) 63#define bswap_32(x) swap32 (x)
64#define bswap_64(x) swap64(x) 64#define bswap_64(x) swap64 (x)
65 65
66#elif defined(__NetBSD__) 66#elif defined(__NetBSD__)
67 67
68#include <machine/bswap.h> 68#include <machine/bswap.h>
69#if defined(__BSWAP_RENAME) && !defined(__bswap_32) 69#if defined(__BSWAP_RENAME) && ! defined(__bswap_32)
70#define bswap_32(x) bswap32(x) 70#define bswap_32(x) bswap32 (x)
71#define bswap_64(x) bswap64(x) 71#define bswap_64(x) bswap64 (x)
72#endif 72#endif
73 73
74#elif defined(__linux__) || defined(GNU) 74#elif defined(__linux__) || defined(GNU)
@@ -146,12 +146,6 @@ enum GNUNET_GenericReturnValue
146#endif 146#endif
147 147
148/** 148/**
149 * wrap va_arg for enums
150 */
151#define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
152
153
154/**
155 * @ingroup logging 149 * @ingroup logging
156 * 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
157 * tree where gnunet_config.h is unavailable 151 * tree where gnunet_config.h is unavailable
@@ -172,15 +166,19 @@ enum GNUNET_GenericReturnValue
172#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) 166#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
173 167
174#define BYTE_SWAP_32(x) \ 168#define BYTE_SWAP_32(x) \
175 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ 169 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
176 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) 170 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
177 171
178#define BYTE_SWAP_64(x) \ 172#define BYTE_SWAP_64(x) \
179 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \ 173 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
180 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \ 174 40) \
181 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \ 175 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
182 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \ 176 << 8) \
183 56)) 177 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
178 >> 24) \
179 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
180 >> \
181 56))
184#endif 182#endif
185 183
186#if __BYTE_ORDER == __LITTLE_ENDIAN 184#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -485,7 +483,7 @@ GNUNET_get_log_call_status (int caller_level,
485 483
486#endif 484#endif
487 485
488 486/* *INDENT-OFF* */
489/** 487/**
490 * @ingroup logging 488 * @ingroup logging
491 * Main log function. 489 * Main log function.
@@ -495,13 +493,15 @@ GNUNET_get_log_call_status (int caller_level,
495 * @param ... arguments for format string 493 * @param ... arguments for format string
496 */ 494 */
497void 495void
498GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) 496GNUNET_log_nocheck (enum GNUNET_ErrorType kind,
497 const char *message,
498 ...)
499__attribute__ ((format (printf, 2, 3))); 499__attribute__ ((format (printf, 2, 3)));
500 500
501/* from glib */ 501/* from glib */
502#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 502#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
503#define _GNUNET_BOOLEAN_EXPR(expr) \ 503#define _GNUNET_BOOLEAN_EXPR(expr) \
504 __extension__ ({ \ 504 __extension__ ({ \
505 int _gnunet_boolean_var_; \ 505 int _gnunet_boolean_var_; \
506 if (expr) \ 506 if (expr) \
507 _gnunet_boolean_var_ = 1; \ 507 _gnunet_boolean_var_ = 1; \
@@ -519,6 +519,7 @@ __attribute__ ((format (printf, 2, 3)));
519#if ! defined(GNUNET_LOG_CALL_STATUS) 519#if ! defined(GNUNET_LOG_CALL_STATUS)
520#define GNUNET_LOG_CALL_STATUS -1 520#define GNUNET_LOG_CALL_STATUS -1
521#endif 521#endif
522/* *INDENT-ON* */
522 523
523 524
524/** 525/**
@@ -540,56 +541,56 @@ __attribute__ ((format (printf, 3, 4)));
540 541
541#if ! defined(GNUNET_CULL_LOGGING) 542#if ! defined(GNUNET_CULL_LOGGING)
542#define GNUNET_log_from(kind, comp, ...) \ 543#define GNUNET_log_from(kind, comp, ...) \
543 do \ 544 do \
544 { \ 545 { \
545 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 546 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
546 if ((GNUNET_EXTRA_LOGGING > 0) || \ 547 if ((GNUNET_EXTRA_LOGGING > 0) || \
547 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 548 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
548 { \ 549 { \
549 if (GN_UNLIKELY (log_call_enabled == -1)) \ 550 if (GN_UNLIKELY (log_call_enabled == -1)) \
550 log_call_enabled = \ 551 log_call_enabled = \
551 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 552 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
552 (comp), \ 553 (comp), \
553 __FILE__, \ 554 __FILE__, \
554 __FUNCTION__, \ 555 __FUNCTION__, \
555 __LINE__); \ 556 __LINE__); \
556 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 557 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
557 { \ 558 { \
558 GNUNET_log_skip (-1, GNUNET_NO); \ 559 GNUNET_log_skip (-1, GNUNET_NO); \
559 } \ 560 } \
560 else \ 561 else \
561 { \ 562 { \
562 if (GN_UNLIKELY (log_call_enabled)) \ 563 if (GN_UNLIKELY (log_call_enabled)) \
563 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ 564 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
564 } \ 565 } \
565 } \ 566 } \
566 } while (0) 567 } while (0)
567 568
568#define GNUNET_log(kind, ...) \ 569#define GNUNET_log(kind, ...) \
569 do \ 570 do \
570 { \ 571 { \
571 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 572 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
572 if ((GNUNET_EXTRA_LOGGING > 0) || \ 573 if ((GNUNET_EXTRA_LOGGING > 0) || \
573 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 574 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
574 { \ 575 { \
575 if (GN_UNLIKELY (log_call_enabled == -1)) \ 576 if (GN_UNLIKELY (log_call_enabled == -1)) \
576 log_call_enabled = \ 577 log_call_enabled = \
577 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 578 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
578 NULL, \ 579 NULL, \
579 __FILE__, \ 580 __FILE__, \
580 __FUNCTION__, \ 581 __FUNCTION__, \
581 __LINE__); \ 582 __LINE__); \
582 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 583 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
583 { \ 584 { \
584 GNUNET_log_skip (-1, GNUNET_NO); \ 585 GNUNET_log_skip (-1, GNUNET_NO); \
585 } \ 586 } \
586 else \ 587 else \
587 { \ 588 { \
588 if (GN_UNLIKELY (log_call_enabled)) \ 589 if (GN_UNLIKELY (log_call_enabled)) \
589 GNUNET_log_nocheck ((kind), __VA_ARGS__); \ 590 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
590 } \ 591 } \
591 } \ 592 } \
592 } while (0) 593 } while (0)
593#else 594#else
594#define GNUNET_log(...) 595#define GNUNET_log(...)
595#define GNUNET_log_from(...) 596#define GNUNET_log_from(...)
@@ -648,7 +649,7 @@ GNUNET_abort_ (void) GNUNET_NORETURN;
648 */ 649 */
649const char * 650const char *
650GNUNET_b2s (const void *buf, 651GNUNET_b2s (const void *buf,
651 size_t buf_size); 652 size_t buf_size);
652 653
653 654
654/** 655/**
@@ -681,8 +682,10 @@ GNUNET_log_skip (int n, int check_reset);
681 * @param logfile change logging to logfile (use NULL to keep stderr) 682 * @param logfile change logging to logfile (use NULL to keep stderr)
682 * @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
683 */ 684 */
684int 685enum GNUNET_GenericReturnValue
685GNUNET_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);
686 689
687 690
688/** 691/**
@@ -696,7 +699,8 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
696 * @param logger_cls closure for @a logger 699 * @param logger_cls closure for @a logger
697 */ 700 */
698void 701void
699GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); 702GNUNET_logger_add (GNUNET_Logger logger,
703 void *logger_cls);
700 704
701 705
702/** 706/**
@@ -707,7 +711,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
707 * @param logger_cls closure for @a logger 711 * @param logger_cls closure for @a logger
708 */ 712 */
709void 713void
710GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); 714GNUNET_logger_remove (GNUNET_Logger logger,
715 void *logger_cls);
711 716
712 717
713/** 718/**
@@ -922,36 +927,37 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
922 * @ingroup logging 927 * @ingroup logging
923 * Use this for fatal errors that cannot be handled 928 * Use this for fatal errors that cannot be handled
924 */ 929 */
925#if __GNUC__ >= 6 || __clang_major__ >= 6 930#if __GNUC__ >= 6 || __clang_major__ >= 6
926#define GNUNET_assert(cond) \ 931#define GNUNET_assert(cond) \
927 do \ 932 do \
928 { \ 933 { \
929 _Pragma("GCC diagnostic push") \ 934 _Pragma("GCC diagnostic push") \
930 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ 935 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
931 if (! (cond)) \ 936 if (! (cond)) \
932 { \ 937 { \
933 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
934 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 939 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
935 __FILE__, \ 940 __FILE__, \
936 __LINE__); \ 941 __LINE__); \
937 GNUNET_abort_ (); \ 942 GNUNET_abort_ (); \
938 } \ 943 } \
939 _Pragma("GCC diagnostic pop") \ 944 _Pragma("GCC diagnostic pop") \
940 } while (0) 945 } while (0)
941#else 946#else
942/* older GCC/clangs do not support -Wtautological-compare */ 947/* older GCC/clangs do not support -Wtautological-compare */
943#define GNUNET_assert(cond) \ 948#define GNUNET_assert(cond) \
944 do \ 949 do \
945 { \ 950 { \
946 if (! (cond)) \ 951 if (! (cond)) \
947 { \ 952 { \
948 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 953 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
949 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 954 dgettext ("gnunet", \
950 __FILE__, \ 955 "Assertion failed at %s:%d. Aborting.\n"), \
951 __LINE__); \ 956 __FILE__, \
952 GNUNET_abort_ (); \ 957 __LINE__); \
953 } \ 958 GNUNET_abort_ (); \
954 } while (0) 959 } \
960 } while (0)
955#endif 961#endif
956 962
957/** 963/**
@@ -959,17 +965,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
959 * Use this for fatal errors that cannot be handled 965 * Use this for fatal errors that cannot be handled
960 */ 966 */
961#define GNUNET_assert_at(cond, f, l) \ 967#define GNUNET_assert_at(cond, f, l) \
962 do \ 968 do \
963 { \ 969 { \
964 if (! (cond)) \ 970 if (! (cond)) \
965 { \ 971 { \
966 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
967 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 973 dgettext ("gnunet", \
968 f, \ 974 "Assertion failed at %s:%d. Aborting.\n"), \
969 l); \ 975 f, \
970 GNUNET_abort_ (); \ 976 l); \
971 } \ 977 GNUNET_abort_ (); \
972 } while (0) 978 } \
979 } while (0)
973 980
974 981
975/** 982/**
@@ -980,18 +987,20 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
980 * @param comp Component string to use for logging 987 * @param comp Component string to use for logging
981 */ 988 */
982#define GNUNET_assert_from(cond, comp) \ 989#define GNUNET_assert_from(cond, comp) \
983 do \ 990 do \
984 { \ 991 { \
985 if (! (cond)) \ 992 if (! (cond)) \
986 { \ 993 { \
987 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ 994 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
988 comp, \ 995 comp, \
989 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 996 dgettext ("gnunet", \
990 __FILE__, \ 997 "Assertion failed at %s:%d. Aborting.\n") \
991 __LINE__); \ 998 , \
992 GNUNET_abort_ (); \ 999 __FILE__, \
993 } \ 1000 __LINE__); \
994 } while (0) 1001 GNUNET_abort_ (); \
1002 } \
1003 } while (0)
995 1004
996 1005
997#ifdef _Static_assert 1006#ifdef _Static_assert
@@ -1022,16 +1031,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1022 * not fatal (can be handled) but should not occur. 1031 * not fatal (can be handled) but should not occur.
1023 */ 1032 */
1024#define GNUNET_break(cond) \ 1033#define GNUNET_break(cond) \
1025 do \ 1034 do \
1026 { \ 1035 { \
1027 if (! (cond)) \ 1036 if (! (cond)) \
1028 { \ 1037 { \
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 1038 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1030 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ 1039 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1031 __FILE__, \ 1040 __FILE__, \
1032 __LINE__); \ 1041 __LINE__); \
1033 } \ 1042 } \
1034 } while (0) 1043 } while (0)
1035 1044
1036 1045
1037/** 1046/**
@@ -1044,16 +1053,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1044 * development and testing. "OP == other peer". 1053 * development and testing. "OP == other peer".
1045 */ 1054 */
1046#define GNUNET_break_op(cond) \ 1055#define GNUNET_break_op(cond) \
1047 do \ 1056 do \
1048 { \ 1057 { \
1049 if (! (cond)) \ 1058 if (! (cond)) \
1050 { \ 1059 { \
1051 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ 1060 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1052 dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \ 1061 dgettext ("gnunet", \
1053 __FILE__, \ 1062 "External protocol violation detected at %s:%d.\n"), \
1054 __LINE__); \ 1063 __FILE__, \
1055 } \ 1064 __LINE__); \
1056 } while (0) 1065 } \
1066 } while (0)
1057 1067
1058 1068
1059/** 1069/**
@@ -1063,15 +1073,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1063 * by strerror(errno). 1073 * by strerror(errno).
1064 */ 1074 */
1065#define GNUNET_log_strerror(level, cmd) \ 1075#define GNUNET_log_strerror(level, cmd) \
1066 do \ 1076 do \
1067 { \ 1077 { \
1068 GNUNET_log (level, \ 1078 GNUNET_log (level, \
1069 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ 1079 dgettext ("gnunet", \
1070 cmd, \ 1080 "`%s' failed at %s:%d with error: %s\n"), \
1071 __FILE__, \ 1081 cmd, \
1072 __LINE__, \ 1082 __FILE__, \
1073 strerror (errno)); \ 1083 __LINE__, \
1074 } while (0) 1084 strerror (errno)); \
1085 } while (0)
1075 1086
1076 1087
1077/** 1088/**
@@ -1081,16 +1092,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1081 * by strerror(errno). 1092 * by strerror(errno).
1082 */ 1093 */
1083#define GNUNET_log_from_strerror(level, component, cmd) \ 1094#define GNUNET_log_from_strerror(level, component, cmd) \
1084 do \ 1095 do \
1085 { \ 1096 { \
1086 GNUNET_log_from (level, \ 1097 GNUNET_log_from (level, \
1087 component, \ 1098 component, \
1088 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ 1099 dgettext ("gnunet", \
1089 cmd, \ 1100 "`%s' failed at %s:%d with error: %s\n"), \
1090 __FILE__, \ 1101 cmd, \
1091 __LINE__, \ 1102 __FILE__, \
1092 strerror (errno)); \ 1103 __LINE__, \
1093 } while (0) 1104 strerror (errno)); \
1105 } while (0)
1094 1106
1095 1107
1096/** 1108/**
@@ -1100,16 +1112,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1100 * by strerror(errno). 1112 * by strerror(errno).
1101 */ 1113 */
1102#define GNUNET_log_strerror_file(level, cmd, filename) \ 1114#define GNUNET_log_strerror_file(level, cmd, filename) \
1103 do \ 1115 do \
1104 { \ 1116 { \
1105 GNUNET_log (level, \ 1117 GNUNET_log (level, \
1106 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1118 dgettext ("gnunet", \
1107 cmd, \ 1119 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1108 filename, \ 1120 cmd, \
1109 __FILE__, \ 1121 filename, \
1110 __LINE__, \ 1122 __FILE__, \
1111 strerror (errno)); \ 1123 __LINE__, \
1112 } while (0) 1124 strerror (errno)); \
1125 } while (0)
1113 1126
1114 1127
1115/** 1128/**
@@ -1119,17 +1132,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1119 * by strerror(errno). 1132 * by strerror(errno).
1120 */ 1133 */
1121#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ 1134#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1122 do \ 1135 do \
1123 { \ 1136 { \
1124 GNUNET_log_from (level, \ 1137 GNUNET_log_from (level, \
1125 component, \ 1138 component, \
1126 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1139 dgettext ("gnunet", \
1127 cmd, \ 1140 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1128 filename, \ 1141 cmd, \
1129 __FILE__, \ 1142 filename, \
1130 __LINE__, \ 1143 __FILE__, \
1131 strerror (errno)); \ 1144 __LINE__, \
1132 } while (0) 1145 strerror (errno)); \
1146 } while (0)
1133 1147
1134/* ************************* endianness conversion ****************** */ 1148/* ************************* endianness conversion ****************** */
1135 1149
@@ -1222,7 +1236,7 @@ GNUNET_ntoh_double (double d);
1222 * the first element! 1236 * the first element!
1223 */ 1237 */
1224#define GNUNET_memcmp(a, b) \ 1238#define GNUNET_memcmp(a, b) \
1225 ({ \ 1239 ({ \
1226 const typeof (*b) * _a = (a); \ 1240 const typeof (*b) * _a = (a); \
1227 const typeof (*a) * _b = (b); \ 1241 const typeof (*a) * _b = (b); \
1228 memcmp (_a, _b, sizeof(*a)); \ 1242 memcmp (_a, _b, sizeof(*a)); \
@@ -1251,7 +1265,7 @@ GNUNET_memcmp_ct_ (const void *b1,
1251 * the first element! 1265 * the first element!
1252 */ 1266 */
1253#define GNUNET_memcmp_priv(a, b) \ 1267#define GNUNET_memcmp_priv(a, b) \
1254 ({ \ 1268 ({ \
1255 const typeof (*b) * _a = (a); \ 1269 const typeof (*b) * _a = (a); \
1256 const typeof (*a) * _b = (b); \ 1270 const typeof (*a) * _b = (b); \
1257 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ 1271 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
@@ -1264,9 +1278,9 @@ GNUNET_memcmp_ct_ (const void *b1,
1264 * @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
1265 * entire memory being zero'ed out. 1279 * entire memory being zero'ed out.
1266 * @param n number of bytes in @a to be tested 1280 * @param n number of bytes in @a to be tested
1267 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1281 * @return true if @a a is zero, false_NO otherwise
1268 */ 1282 */
1269enum GNUNET_GenericReturnValue 1283bool
1270GNUNET_is_zero_ (const void *a, 1284GNUNET_is_zero_ (const void *a,
1271 size_t n); 1285 size_t n);
1272 1286
@@ -1279,7 +1293,7 @@ GNUNET_is_zero_ (const void *a,
1279 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1293 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise
1280 */ 1294 */
1281#define GNUNET_is_zero(a) \ 1295#define GNUNET_is_zero(a) \
1282 GNUNET_is_zero_ ((a), sizeof (*(a))) 1296 GNUNET_is_zero_ ((a), sizeof (*(a)))
1283 1297
1284 1298
1285/** 1299/**
@@ -1292,15 +1306,16 @@ GNUNET_is_zero_ (const void *a,
1292 * @param n number of bytes to copy 1306 * @param n number of bytes to copy
1293 */ 1307 */
1294#define GNUNET_memcpy(dst, src, n) \ 1308#define GNUNET_memcpy(dst, src, n) \
1295 do \ 1309 do \
1296 { \ 1310 { \
1297 if (0 != n) \ 1311 if (0 != n) \
1298 { \ 1312 { \
1299 (void) memcpy (dst, src, n); \ 1313 (void) memcpy (dst, src, n); \
1300 } \ 1314 } \
1301 } while (0) 1315 } while (0)
1302 1316
1303 1317
1318/* *INDENT-OFF* */
1304/** 1319/**
1305 * @ingroup memory 1320 * @ingroup memory
1306 * 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.
@@ -1314,6 +1329,7 @@ GNUNET_is_zero_ (const void *a,
1314 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ 1329 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1315 (type *) GNUNET_malloc ((n) * sizeof(type)); \ 1330 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1316 }) 1331 })
1332/* *INDENT-ON* */
1317 1333
1318/** 1334/**
1319 * @ingroup memory 1335 * @ingroup memory
@@ -1325,7 +1341,7 @@ GNUNET_is_zero_ (const void *a,
1325 * @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'.
1326 */ 1342 */
1327#define GNUNET_new_array_2d(n, m, type) \ 1343#define GNUNET_new_array_2d(n, m, type) \
1328 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) 1344 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1329 1345
1330/** 1346/**
1331 * @ingroup memory 1347 * @ingroup memory
@@ -1338,7 +1354,8 @@ GNUNET_is_zero_ (const void *a,
1338 * @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'.
1339 */ 1355 */
1340#define GNUNET_new_array_3d(n, m, o, type) \ 1356#define GNUNET_new_array_3d(n, m, o, type) \
1341 (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__)
1342 1359
1343/** 1360/**
1344 * @ingroup memory 1361 * @ingroup memory
@@ -1370,7 +1387,7 @@ GNUNET_is_zero_ (const void *a,
1370 * @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
1371 */ 1388 */
1372#define GNUNET_malloc_large(size) \ 1389#define GNUNET_malloc_large(size) \
1373 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) 1390 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1374 1391
1375 1392
1376/** 1393/**
@@ -1383,7 +1400,7 @@ GNUNET_is_zero_ (const void *a,
1383 * @return pointer to size bytes of memory 1400 * @return pointer to size bytes of memory
1384 */ 1401 */
1385#define GNUNET_realloc(ptr, size) \ 1402#define GNUNET_realloc(ptr, size) \
1386 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) 1403 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1387 1404
1388 1405
1389/** 1406/**
@@ -1410,8 +1427,8 @@ GNUNET_is_zero_ (const void *a,
1410 * 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.
1411 */ 1428 */
1412#define GNUNET_free(ptr) do { \ 1429#define GNUNET_free(ptr) do { \
1413 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ 1430 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1414 ptr = NULL; \ 1431 ptr = NULL; \
1415} while (0) 1432} while (0)
1416 1433
1417 1434
@@ -1425,6 +1442,7 @@ GNUNET_is_zero_ (const void *a,
1425 */ 1442 */
1426#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) 1443#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1427 1444
1445
1428/** 1446/**
1429 * @ingroup memory 1447 * @ingroup memory
1430 * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string 1448 * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string
@@ -1435,7 +1453,7 @@ GNUNET_is_zero_ (const void *a,
1435 * @return a partial copy of the string including zero-termination 1453 * @return a partial copy of the string including zero-termination
1436 */ 1454 */
1437#define GNUNET_strndup(a, length) \ 1455#define GNUNET_strndup(a, length) \
1438 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) 1456 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1439 1457
1440/** 1458/**
1441 * @ingroup memory 1459 * @ingroup memory
@@ -1473,12 +1491,12 @@ GNUNET_is_zero_ (const void *a,
1473 * free the vector (then, arr will be NULL afterwards). 1491 * free the vector (then, arr will be NULL afterwards).
1474 */ 1492 */
1475#define GNUNET_array_grow(arr, size, tsize) \ 1493#define GNUNET_array_grow(arr, size, tsize) \
1476 GNUNET_xgrow_ ((void **) &(arr), \ 1494 GNUNET_xgrow_ ((void **) &(arr), \
1477 sizeof((arr)[0]), \ 1495 sizeof((arr)[0]), \
1478 &size, \ 1496 &size, \
1479 tsize, \ 1497 tsize, \
1480 __FILE__, \ 1498 __FILE__, \
1481 __LINE__) 1499 __LINE__)
1482 1500
1483/** 1501/**
1484 * @ingroup memory 1502 * @ingroup memory
@@ -1494,12 +1512,12 @@ GNUNET_is_zero_ (const void *a,
1494 * @param element the element that will be appended to the array 1512 * @param element the element that will be appended to the array
1495 */ 1513 */
1496#define GNUNET_array_append(arr, len, element) \ 1514#define GNUNET_array_append(arr, len, element) \
1497 do \ 1515 do \
1498 { \ 1516 { \
1499 GNUNET_assert ((len) + 1 > (len)); \ 1517 GNUNET_assert ((len) + 1 > (len)); \
1500 GNUNET_array_grow (arr, len, len + 1); \ 1518 GNUNET_array_grow (arr, len, len + 1); \
1501 (arr) [len - 1] = element; \ 1519 (arr) [len - 1] = element; \
1502 } while (0) 1520 } while (0)
1503 1521
1504 1522
1505/** 1523/**
@@ -1526,15 +1544,15 @@ GNUNET_is_zero_ (const void *a,
1526 1544
1527 */ 1545 */
1528#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ 1546#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1529 do \ 1547 do \
1530 { \ 1548 { \
1531 const typeof (*arr2) * _a1 = (arr1); \ 1549 const typeof (*arr2) * _a1 = (arr1); \
1532 const typeof (*arr1) * _a2 = (arr2); \ 1550 const typeof (*arr1) * _a2 = (arr2); \
1533 GNUNET_assert ((len1) + (len2) >= (len1)); \ 1551 GNUNET_assert ((len1) + (len2) >= (len1)); \
1534 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ 1552 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1535 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ 1553 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1536 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ 1554 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1537 } while (0) 1555 } while (0)
1538 1556
1539 1557
1540/** 1558/**
@@ -1585,7 +1603,9 @@ __attribute__ ((format (printf, 2, 3)));
1585 * @return allocated memory, never NULL 1603 * @return allocated memory, never NULL
1586 */ 1604 */
1587void * 1605void *
1588GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); 1606GNUNET_xmalloc_ (size_t size,
1607 const char *filename,
1608 int linenumber);
1589 1609
1590 1610
1591/** 1611/**
@@ -1665,7 +1685,9 @@ GNUNET_xmemdup_ (const void *buf,
1665 * @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
1666 */ 1686 */
1667void * 1687void *
1668GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); 1688GNUNET_xmalloc_unchecked_ (size_t size,
1689 const char *filename,
1690 int linenumber);
1669 1691
1670 1692
1671/** 1693/**
@@ -1673,7 +1695,10 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1673 * memory is available. 1695 * memory is available.
1674 */ 1696 */
1675void * 1697void *
1676GNUNET_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);
1677 1702
1678 1703
1679/** 1704/**
@@ -1686,7 +1711,9 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1686 * @param linenumber line where this call is being made (for debugging) 1711 * @param linenumber line where this call is being made (for debugging)
1687 */ 1712 */
1688void 1713void
1689GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); 1714GNUNET_xfree_ (void *ptr,
1715 const char *filename,
1716 int linenumber);
1690 1717
1691 1718
1692/** 1719/**
@@ -1697,7 +1724,9 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1697 * @return the duplicated string 1724 * @return the duplicated string
1698 */ 1725 */
1699char * 1726char *
1700GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); 1727GNUNET_xstrdup_ (const char *str,
1728 const char *filename,
1729 int linenumber);
1701 1730
1702/** 1731/**
1703 * 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.
@@ -1867,6 +1896,8 @@ enum GNUNET_SCHEDULER_Priority
1867}; 1896};
1868 1897
1869 1898
1899/* *INDENT-OFF* */
1900
1870#if 0 /* keep Emacsens' auto-indent happy */ 1901#if 0 /* keep Emacsens' auto-indent happy */
1871{ 1902{
1872#endif 1903#endif
@@ -1875,5 +1906,3 @@ enum GNUNET_SCHEDULER_Priority
1875#endif 1906#endif
1876 1907
1877#endif /* GNUNET_COMMON_H */ 1908#endif /* GNUNET_COMMON_H */
1878
1879/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 3b9be5849..132172516 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -66,7 +66,8 @@ GNUNET_CONFIGURATION_create (void);
66 * @return duplicate configuration 66 * @return duplicate configuration
67 */ 67 */
68struct GNUNET_CONFIGURATION_Handle * 68struct GNUNET_CONFIGURATION_Handle *
69GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); 69GNUNET_CONFIGURATION_dup (
70 const struct GNUNET_CONFIGURATION_Handle *cfg);
70 71
71 72
72/** 73/**
@@ -75,7 +76,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
75 * @param cfg configuration to destroy 76 * @param cfg configuration to destroy
76 */ 77 */
77void 78void
78GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); 79GNUNET_CONFIGURATION_destroy (
80 struct GNUNET_CONFIGURATION_Handle *cfg);
79 81
80 82
81/** 83/**
@@ -88,8 +90,9 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
88 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
89 */ 91 */
90enum GNUNET_GenericReturnValue 92enum GNUNET_GenericReturnValue
91GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, 93GNUNET_CONFIGURATION_load (
92 const char *filename); 94 struct GNUNET_CONFIGURATION_Handle *cfg,
95 const char *filename);
93 96
94 97
95/** 98/**
@@ -101,8 +104,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
101 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 104 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
102 */ 105 */
103enum GNUNET_GenericReturnValue 106enum GNUNET_GenericReturnValue
104GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 107GNUNET_CONFIGURATION_load_from (
105 const char *defaults_d); 108 struct GNUNET_CONFIGURATION_Handle *cfg,
109 const char *defaults_d);
106 110
107 111
108/** 112/**
@@ -138,8 +142,9 @@ GNUNET_CONFIGURATION_default_filename (void);
138 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 142 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
139 */ 143 */
140enum GNUNET_GenericReturnValue 144enum GNUNET_GenericReturnValue
141GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 145GNUNET_CONFIGURATION_parse (
142 const char *filename); 146 struct GNUNET_CONFIGURATION_Handle *cfg,
147 const char *filename);
143 148
144 149
145/** 150/**
@@ -151,8 +156,9 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
151 * present. This memory should be freed by the caller 156 * present. This memory should be freed by the caller
152 */ 157 */
153char * 158char *
154GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, 159GNUNET_CONFIGURATION_serialize (
155 size_t *size); 160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 size_t *size);
156 162
157 163
158/** 164/**
@@ -168,6 +174,7 @@ char *
168GNUNET_CONFIGURATION_serialize_diagnostics ( 174GNUNET_CONFIGURATION_serialize_diagnostics (
169 const struct GNUNET_CONFIGURATION_Handle *cfg); 175 const struct GNUNET_CONFIGURATION_Handle *cfg);
170 176
177
171/** 178/**
172 * De-serializes configuration 179 * De-serializes configuration
173 * 180 *
@@ -179,10 +186,11 @@ GNUNET_CONFIGURATION_serialize_diagnostics (
179 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 186 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
180 */ 187 */
181enum GNUNET_GenericReturnValue 188enum GNUNET_GenericReturnValue
182GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 189GNUNET_CONFIGURATION_deserialize (
183 const char *mem, 190 struct GNUNET_CONFIGURATION_Handle *cfg,
184 size_t size, 191 const char *mem,
185 const char *source_filename); 192 size_t size,
193 const char *source_filename);
186 194
187 195
188/** 196/**
@@ -193,8 +201,9 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
193 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 201 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
194 */ 202 */
195enum GNUNET_GenericReturnValue 203enum GNUNET_GenericReturnValue
196GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 204GNUNET_CONFIGURATION_write (
197 const char *filename); 205 struct GNUNET_CONFIGURATION_Handle *cfg,
206 const char *filename);
198 207
199 208
200/** 209/**
@@ -233,7 +242,8 @@ GNUNET_CONFIGURATION_get_diff (
233 * @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)
234 */ 243 */
235enum GNUNET_GenericReturnValue 244enum GNUNET_GenericReturnValue
236GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); 245GNUNET_CONFIGURATION_is_dirty (
246 const struct GNUNET_CONFIGURATION_Handle *cfg);
237 247
238 248
239/** 249/**
@@ -244,8 +254,9 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
244 * @return status code 254 * @return status code
245 */ 255 */
246typedef enum GNUNET_GenericReturnValue 256typedef enum GNUNET_GenericReturnValue
247(*GNUNET_CONFIGURATION_Callback)(void *cls, 257(*GNUNET_CONFIGURATION_Callback)(
248 const struct GNUNET_CONFIGURATION_Handle *cfg); 258 void *cls,
259 const struct GNUNET_CONFIGURATION_Handle *cfg);
249 260
250 261
251/** 262/**
@@ -260,9 +271,10 @@ typedef enum GNUNET_GenericReturnValue
260 * otherwise return value from @a cb. 271 * otherwise return value from @a cb.
261 */ 272 */
262enum GNUNET_GenericReturnValue 273enum GNUNET_GenericReturnValue
263GNUNET_CONFIGURATION_parse_and_run (const char *filename, 274GNUNET_CONFIGURATION_parse_and_run (
264 GNUNET_CONFIGURATION_Callback cb, 275 const char *filename,
265 void *cb_cls); 276 GNUNET_CONFIGURATION_Callback cb,
277 void *cb_cls);
266 278
267/** 279/**
268 * Enable extra diagnostics. Will produce more log output 280 * Enable extra diagnostics. Will produce more log output
@@ -309,9 +321,10 @@ typedef void
309 * @param iter_cls closure for @a iter 321 * @param iter_cls closure for @a iter
310 */ 322 */
311void 323void
312GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 324GNUNET_CONFIGURATION_iterate (
313 GNUNET_CONFIGURATION_Iterator iter, 325 const struct GNUNET_CONFIGURATION_Handle *cfg,
314 void *iter_cls); 326 GNUNET_CONFIGURATION_Iterator iter,
327 void *iter_cls);
315 328
316 329
317/** 330/**
@@ -335,8 +348,9 @@ GNUNET_CONFIGURATION_iterate_sections (
335 * @param section name of the section to remove 348 * @param section name of the section to remove
336 */ 349 */
337void 350void
338GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, 351GNUNET_CONFIGURATION_remove_section (
339 const char *section); 352 struct GNUNET_CONFIGURATION_Handle *cfg,
353 const char *section);
340 354
341 355
342/** 356/**
@@ -596,10 +610,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
596 * @param value value to set 610 * @param value value to set
597 */ 611 */
598void 612void
599GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, 613GNUNET_CONFIGURATION_set_value_string (
600 const char *section, 614 struct GNUNET_CONFIGURATION_Handle *cfg,
601 const char *option, 615 const char *section,
602 const char *value); 616 const char *option,
617 const char *value);
603 618
604 619
605/** 620/**
@@ -649,10 +664,8 @@ struct GNUNET_CONFIGURATION_ConfigSettings
649{ 664{
650 665
651 /** 666 /**
652 * Must be set to the API version, i.e. 667 * Must be set to the API version, i.e. #GNUNET_UTIL_VERSION. Used to
653 * #GNUNET_UTIL_VERSION. Used to detect 668 * detect which version of the struct the client is using.
654 * which version of the struct the client
655 * is using.
656 */ 669 */
657 unsigned int api_version; 670 unsigned int api_version;
658 671
@@ -696,7 +709,6 @@ struct GNUNET_CONFIGURATION_ConfigSettings
696 */ 709 */
697 int full; 710 int full;
698 711
699
700 /** 712 /**
701 * Return value from the operation, to be returned 713 * Return value from the operation, to be returned
702 * from 'main'. 714 * from 'main'.
@@ -714,50 +726,52 @@ struct GNUNET_CONFIGURATION_ConfigSettings
714 * @param cs configuration settings to initialize 726 * @param cs configuration settings to initialize
715 */ 727 */
716#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ 728#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \
717 GNUNET_GETOPT_option_flag ( \ 729 GNUNET_GETOPT_option_flag ( \
718 'F', \ 730 'F', \
719 "full", \ 731 "full", \
720 gettext_noop ( \ 732 gettext_noop ( \
721 "write the full configuration file, including default values"), \ 733 "write the full configuration file, including default values"), \
722 &(cs)->full), \ 734 &(cs)->full), \
723 GNUNET_GETOPT_option_flag ( \ 735 GNUNET_GETOPT_option_flag ( \
724 'f', \ 736 'f', \
725 "filename", \ 737 "filename", \
726 gettext_noop ("interpret option value as a filename (with $-expansion)"), \ 738 gettext_noop ( \
727 &(cs)->is_filename), \ 739 "interpret option value as a filename (with $-expansion)"), \
728 GNUNET_GETOPT_option_string ('o', \ 740 &(cs)->is_filename), \
729 "option", \ 741 GNUNET_GETOPT_option_string ('o', \
730 "OPTION", \ 742 "option", \
731 gettext_noop ("name of the option to access"), \ 743 "OPTION", \
732 &(cs)->option), \ 744 gettext_noop ( \
733 GNUNET_GETOPT_option_flag ( \ 745 "name of the option to access"), \
734 'r', \ 746 &(cs)->option), \
735 "rewrite", \ 747 GNUNET_GETOPT_option_flag ( \
736 gettext_noop ( \ 748 'r', \
737 "rewrite the configuration file, even if nothing changed"), \ 749 "rewrite", \
738 &(cs)->rewrite), \ 750 gettext_noop ( \
739 GNUNET_GETOPT_option_flag ( \ 751 "rewrite the configuration file, even if nothing changed"), \
740 'd', \ 752 &(cs)->rewrite), \
741 "diagnostics", \ 753 GNUNET_GETOPT_option_flag ( \
742 gettext_noop ( \ 754 'd', \
743 "output extra diagnostics"), \ 755 "diagnostics", \
744 &(cs)->diagnostics), \ 756 gettext_noop ( \
745 GNUNET_GETOPT_option_flag ('S', \ 757 "output extra diagnostics"), \
746 "list-sections", \ 758 &(cs)->diagnostics), \
747 gettext_noop ( \ 759 GNUNET_GETOPT_option_flag ('S', \
748 "print available configuration sections"), \ 760 "list-sections", \
749 &(cs)->list_sections), \ 761 gettext_noop ( \
750 GNUNET_GETOPT_option_string ('s', \ 762 "print available configuration sections"), \
751 "section", \ 763 &(cs)->list_sections), \
752 "SECTION", \ 764 GNUNET_GETOPT_option_string ('s', \
753 gettext_noop ( \ 765 "section", \
754 "name of the section to access"), \ 766 "SECTION", \
755 &(cs)->section), \ 767 gettext_noop ( \
756 GNUNET_GETOPT_option_string ('V', \ 768 "name of the section to access"), \
757 "value", \ 769 &(cs)->section), \
758 "VALUE", \ 770 GNUNET_GETOPT_option_string ('V', \
759 gettext_noop ("value to set"), \ 771 "value", \
760 &(cs)->value) 772 "VALUE", \
773 gettext_noop ("value to set"), \
774 &(cs)->value)
761 775
762 776
763/** 777/**
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 02bd32330..8f36f1c61 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -52,6 +52,7 @@
52 * @} 52 * @}
53 */ 53 */
54 54
55#include "gnunet_common.h"
55#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 56#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
56#error "Only <gnunet_util_lib.h> can be included directly." 57#error "Only <gnunet_util_lib.h> can be included directly."
57#endif 58#endif
@@ -177,7 +178,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data,
177 * @param size the size of the given @a data array 178 * @param size the size of the given @a data array
178 * @return #GNUNET_SYSERR if the data array of the wrong size 179 * @return #GNUNET_SYSERR if the data array of the wrong size
179 */ 180 */
180int 181enum GNUNET_GenericReturnValue
181GNUNET_CONTAINER_bloomfilter_get_raw_data ( 182GNUNET_CONTAINER_bloomfilter_get_raw_data (
182 const struct GNUNET_CONTAINER_BloomFilter *bf, 183 const struct GNUNET_CONTAINER_BloomFilter *bf,
183 char *data, 184 char *data,
@@ -291,7 +292,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
291 * @param size size of @a data 292 * @param size size of @a data
292 * @return #GNUNET_OK on success 293 * @return #GNUNET_OK on success
293 */ 294 */
294int 295enum GNUNET_GenericReturnValue
295GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 296GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
296 const char *data, 297 const char *data,
297 size_t size); 298 size_t size);
@@ -307,7 +308,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
307 * @param to_or the bloomfilter to or-in 308 * @param to_or the bloomfilter to or-in
308 * @return #GNUNET_OK on success 309 * @return #GNUNET_OK on success
309 */ 310 */
310int 311enum GNUNET_GenericReturnValue
311GNUNET_CONTAINER_bloomfilter_or2 ( 312GNUNET_CONTAINER_bloomfilter_or2 (
312 struct GNUNET_CONTAINER_BloomFilter *bf, 313 struct GNUNET_CONTAINER_BloomFilter *bf,
313 const struct GNUNET_CONTAINER_BloomFilter *to_or); 314 const struct GNUNET_CONTAINER_BloomFilter *to_or);
@@ -401,7 +402,7 @@ enum GNUNET_CONTAINER_MultiHashMapOption
401 * #GNUNET_NO if not. 402 * #GNUNET_NO if not.
402 */ 403 */
403typedef enum GNUNET_GenericReturnValue 404typedef enum GNUNET_GenericReturnValue
404(*GNUNET_CONTAINER_MulitHashMapIteratorCallback)( 405(*GNUNET_CONTAINER_MultiHashMapIteratorCallback)(
405 void *cls, 406 void *cls,
406 const struct GNUNET_HashCode *key, 407 const struct GNUNET_HashCode *key,
407 void *value); 408 void *value);
@@ -580,7 +581,7 @@ GNUNET_CONTAINER_multihashmap_size (
580int 581int
581GNUNET_CONTAINER_multihashmap_iterate ( 582GNUNET_CONTAINER_multihashmap_iterate (
582 struct GNUNET_CONTAINER_MultiHashMap *map, 583 struct GNUNET_CONTAINER_MultiHashMap *map,
583 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 584 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
584 void *it_cls); 585 void *it_cls);
585 586
586 587
@@ -646,11 +647,11 @@ GNUNET_CONTAINER_multihashmap_iterator_destroy (
646 * @return the number of key value pairs processed, 647 * @return the number of key value pairs processed,
647 * #GNUNET_SYSERR if it aborted iteration 648 * #GNUNET_SYSERR if it aborted iteration
648 */ 649 */
649int 650enum GNUNET_GenericReturnValue
650GNUNET_CONTAINER_multihashmap_get_multiple ( 651GNUNET_CONTAINER_multihashmap_get_multiple (
651 struct GNUNET_CONTAINER_MultiHashMap *map, 652 struct GNUNET_CONTAINER_MultiHashMap *map,
652 const struct GNUNET_HashCode *key, 653 const struct GNUNET_HashCode *key,
653 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 654 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
654 void *it_cls); 655 void *it_cls);
655 656
656 657
@@ -668,7 +669,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (
668unsigned int 669unsigned int
669GNUNET_CONTAINER_multihashmap_get_random ( 670GNUNET_CONTAINER_multihashmap_get_random (
670 const struct GNUNET_CONTAINER_MultiHashMap *map, 671 const struct GNUNET_CONTAINER_MultiHashMap *map,
671 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 672 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
672 void *it_cls); 673 void *it_cls);
673 674
674 675
@@ -1423,7 +1424,7 @@ GNUNET_CONTAINER_multiuuidmap_size (
1423 * @return the number of key value pairs processed, 1424 * @return the number of key value pairs processed,
1424 * #GNUNET_SYSERR if it aborted iteration 1425 * #GNUNET_SYSERR if it aborted iteration
1425 */ 1426 */
1426int 1427enum GNUNET_GenericReturnValue
1427GNUNET_CONTAINER_multiuuidmap_iterate ( 1428GNUNET_CONTAINER_multiuuidmap_iterate (
1428 struct GNUNET_CONTAINER_MultiUuidmap *map, 1429 struct GNUNET_CONTAINER_MultiUuidmap *map,
1429 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, 1430 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
@@ -1550,7 +1551,7 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1550 * #GNUNET_NO if not. 1551 * #GNUNET_NO if not.
1551 */ 1552 */
1552typedef enum GNUNET_GenericReturnValue 1553typedef enum GNUNET_GenericReturnValue
1553(*GNUNET_CONTAINER_MulitHashMapIterator32Callback)( 1554(*GNUNET_CONTAINER_MultiHashMapIterator32Callback)(
1554 void *cls, 1555 void *cls,
1555 uint32_t key, 1556 uint32_t key,
1556 void *value); 1557 void *value);
@@ -1621,7 +1622,7 @@ GNUNET_CONTAINER_multihashmap32_get (
1621int 1622int
1622GNUNET_CONTAINER_multihashmap32_iterate ( 1623GNUNET_CONTAINER_multihashmap32_iterate (
1623 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1624 struct GNUNET_CONTAINER_MultiHashMap32 *map,
1624 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1625 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
1625 void *it_cls); 1626 void *it_cls);
1626 1627
1627 1628
@@ -1729,7 +1730,7 @@ int
1729GNUNET_CONTAINER_multihashmap32_get_multiple ( 1730GNUNET_CONTAINER_multihashmap32_get_multiple (
1730 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1731 struct GNUNET_CONTAINER_MultiHashMap32 *map,
1731 uint32_t key, 1732 uint32_t key,
1732 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1733 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
1733 void *it_cls); 1734 void *it_cls);
1734 1735
1735 1736
diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h
index 7d54914d1..7857a49cf 100644
--- a/src/include/gnunet_conversation_service.h
+++ b/src/include/gnunet_conversation_service.h
@@ -151,7 +151,7 @@ typedef void
151 struct GNUNET_CONVERSATION_Caller * 151 struct GNUNET_CONVERSATION_Caller *
152 caller, 152 caller,
153 const struct 153 const struct
154 GNUNET_IDENTITY_PublicKey *caller_id); 154 GNUNET_CRYPTO_PublicKey *caller_id);
155 155
156 156
157/** 157/**
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 4e188df87..c3069be81 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -45,7 +45,6 @@ extern "C" {
45 45
46 46
47#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
48#include "gnunet_transport_service.h"
49 48
50/** 49/**
51 * Version number of GNUnet-core API. 50 * Version number of GNUnet-core API.
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 8d400118a..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
@@ -44,7 +44,7 @@
44 * @see [Documentation](https://gnunet.org/crypto-api) 44 * @see [Documentation](https://gnunet.org/crypto-api)
45 */ 45 */
46 46
47#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 47#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
48#error "Only <gnunet_util_lib.h> can be included directly." 48#error "Only <gnunet_util_lib.h> can be included directly."
49#endif 49#endif
50 50
@@ -348,6 +348,117 @@ struct GNUNET_CRYPTO_Edx25519Signature
348 unsigned char s[256 / 8]; 348 unsigned char s[256 / 8];
349}; 349};
350 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};
351 462
352/** 463/**
353 * @brief type for session keys 464 * @brief type for session keys
@@ -561,17 +672,33 @@ struct GNUNET_CRYPTO_CsSignature
561 * Schnorr signatures are composed of a scalar s and a curve point 672 * Schnorr signatures are composed of a scalar s and a curve point
562 */ 673 */
563 struct GNUNET_CRYPTO_CsS s_scalar; 674 struct GNUNET_CRYPTO_CsS s_scalar;
675
676 /**
677 * Curve point of the Schnorr signature.
678 */
564 struct GNUNET_CRYPTO_CsRPublic r_point; 679 struct GNUNET_CRYPTO_CsRPublic r_point;
565}; 680};
566 681
567 682
568/** 683/**
569 * Nonce 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.
570 */ 697 */
571struct GNUNET_CRYPTO_CsNonce 698struct GNUNET_CRYPTO_CsBlindingNonce
572{ 699{
573 /*a nonce*/ 700 /*a nonce*/
574 unsigned char nonce[256 / 8]; 701 unsigned char bnonce[256 / 8];
575}; 702};
576 703
577 704
@@ -663,7 +790,7 @@ GNUNET_CRYPTO_zero_keys (void *buffer, size_t length);
663 * Fill block with a random values. 790 * Fill block with a random values.
664 * 791 *
665 * @param mode desired quality of the random number 792 * @param mode desired quality of the random number
666 * @param buffer the buffer to fill 793 * @param[out] buffer the buffer to fill
667 * @param length buffer length 794 * @param length buffer length
668 */ 795 */
669void 796void
@@ -680,7 +807,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
680 * here is not a completely random number. 807 * here is not a completely random number.
681 * 808 *
682 * @param mode desired quality of the random number 809 * @param mode desired quality of the random number
683 * @param uuid the value to fill 810 * @param[out] uuid the value to fill
684 */ 811 */
685void 812void
686GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode, 813GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode,
@@ -1562,6 +1689,9 @@ GNUNET_CRYPTO_edx25519_key_create_from_seed (
1562/** 1689/**
1563 * @ingroup crypto 1690 * @ingroup crypto
1564 * 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.
1565 * 1695 *
1566 * @param[out] pk set to fresh private key; 1696 * @param[out] pk set to fresh private key;
1567 */ 1697 */
@@ -1606,6 +1736,15 @@ GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1606void 1736void
1607GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); 1737GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
1608 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
1609 1748
1610/** 1749/**
1611 * @ingroup crypto 1750 * @ingroup crypto
@@ -1645,6 +1784,43 @@ GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
1645 1784
1646 1785
1647/** 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/**
1648 * Internal structure used to cache pre-calculated values for DLOG calculation. 1824 * Internal structure used to cache pre-calculated values for DLOG calculation.
1649 */ 1825 */
1650struct GNUNET_CRYPTO_EccDlogContext; 1826struct GNUNET_CRYPTO_EccDlogContext;
@@ -1810,6 +1986,9 @@ GNUNET_CRYPTO_ecc_scalar_from_int (int64_t val,
1810/** 1986/**
1811 * @ingroup crypto 1987 * @ingroup crypto
1812 * 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().
1813 * 1992 *
1814 * @param priv private key to use for the ECDH (x) 1993 * @param priv private key to use for the ECDH (x)
1815 * @param pub public key to use for the ECDH (yG) 1994 * @param pub public key to use for the ECDH (yG)
@@ -1826,6 +2005,10 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1826 * @ingroup crypto 2005 * @ingroup crypto
1827 * 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.
1828 * 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)!
1829 * 2012 *
1830 * @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)
1831 * @param pub public key to use for the ECDH (yG) 2014 * @param pub public key to use for the ECDH (yG)
@@ -1837,6 +2020,122 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1837 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 2020 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1838 struct GNUNET_HashCode *key_material); 2021 struct GNUNET_HashCode *key_material);
1839 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);
1840 2139
1841/** 2140/**
1842 * @ingroup crypto 2141 * @ingroup crypto
@@ -1858,6 +2157,10 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1858 * @ingroup crypto 2157 * @ingroup crypto
1859 * 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.
1860 * 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)!
1861 * 2164 *
1862 * @param priv private key to use for the ECDH (y) 2165 * @param priv private key to use for the ECDH (y)
1863 * @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)
@@ -1869,6 +2172,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1869 const struct GNUNET_CRYPTO_EddsaPublicKey *pub, 2172 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1870 struct GNUNET_HashCode *key_material); 2173 struct GNUNET_HashCode *key_material);
1871 2174
2175
1872/** 2176/**
1873 * @ingroup crypto 2177 * @ingroup crypto
1874 * 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.
@@ -2371,6 +2675,97 @@ GNUNET_CRYPTO_edx25519_public_key_derive (
2371 2675
2372 2676
2373/** 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
2767
2768/**
2374 * Output the given MPI value to the given buffer in network 2769 * Output the given MPI value to the given buffer in network
2375 * byte order. The MPI @a val may not be negative. 2770 * byte order. The MPI @a val may not be negative.
2376 * 2771 *
@@ -2585,8 +2980,9 @@ GNUNET_CRYPTO_rsa_private_key_get_public (
2585 * @param hc where to store the hash code 2980 * @param hc where to store the hash code
2586 */ 2981 */
2587void 2982void
2588GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, 2983GNUNET_CRYPTO_rsa_public_key_hash (
2589 struct GNUNET_HashCode *hc); 2984 const struct GNUNET_CRYPTO_RsaPublicKey *key,
2985 struct GNUNET_HashCode *hc);
2590 2986
2591 2987
2592/** 2988/**
@@ -2691,53 +3087,83 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
2691 3087
2692 3088
2693/** 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/**
2694 * Blinds the given message with the given blinding key 3108 * Blinds the given message with the given blinding key
2695 * 3109 *
2696 * @param hash hash of the message to sign 3110 * @param message the message to sign
3111 * @param message_size number of bytes in @a message
2697 * @param bks the blinding key 3112 * @param bks the blinding key
2698 * @param pkey the public key of the signer 3113 * @param pkey the public key of the signer
2699 * @param[out] buf set to a buffer with the blinded message to be signed 3114 * @param[out] bm set to the blinded message
2700 * @param[out] buf_size number of bytes stored in @a buf
2701 * @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
2702 */ 3116 */
2703int 3117enum GNUNET_GenericReturnValue
2704GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, 3118GNUNET_CRYPTO_rsa_blind (const void *message,
3119 size_t message_size,
2705 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, 3120 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
2706 struct GNUNET_CRYPTO_RsaPublicKey *pkey, 3121 struct GNUNET_CRYPTO_RsaPublicKey *pkey,
2707 void **buf, 3122 struct GNUNET_CRYPTO_RsaBlindedMessage *bm);
2708 size_t *buf_size);
2709 3123
2710 3124
2711/** 3125/**
2712 * 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.
2713 * 3127 *
2714 * @param key private key to use for the signing 3128 * @param key private key to use for the signing
2715 * @param msg the (blinded) message to sign 3129 * @param bm the (blinded) message to sign
2716 * @param msg_len number of bytes in @a msg to sign
2717 * @return NULL on error, signature on success 3130 * @return NULL on error, signature on success
2718 */ 3131 */
2719struct GNUNET_CRYPTO_RsaSignature * 3132struct GNUNET_CRYPTO_RsaSignature *
2720GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3133GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2721 const void *msg, 3134 const struct
2722 size_t msg_len); 3135 GNUNET_CRYPTO_RsaBlindedMessage *bm);
2723 3136
2724 3137
2725/** 3138/**
2726 * Create and sign a full domain hash of a message. 3139 * Create and sign a full domain hash of a message.
2727 * 3140 *
2728 * @param key private key to use for the signing 3141 * @param key private key to use for the signing
2729 * @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
2730 * @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
2731 */ 3145 */
2732struct GNUNET_CRYPTO_RsaSignature * 3146struct GNUNET_CRYPTO_RsaSignature *
2733GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3147GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2734 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);
2735 3161
2736 3162
2737/** 3163/**
2738 * Free memory occupied by signature. 3164 * Free memory occupied by signature.
2739 * 3165 *
2740 * @param sig memory to free 3166 * @param[in] sig memory to free
2741 */ 3167 */
2742void 3168void
2743GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig); 3169GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig);
@@ -2765,8 +3191,9 @@ GNUNET_CRYPTO_rsa_signature_encode (
2765 * @return NULL on error 3191 * @return NULL on error
2766 */ 3192 */
2767struct GNUNET_CRYPTO_RsaSignature * 3193struct GNUNET_CRYPTO_RsaSignature *
2768GNUNET_CRYPTO_rsa_signature_decode (const void *buf, 3194GNUNET_CRYPTO_rsa_signature_decode (
2769 size_t buf_size); 3195 const void *buf,
3196 size_t buf_size);
2770 3197
2771 3198
2772/** 3199/**
@@ -2776,7 +3203,8 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf,
2776 * @return the duplicate key; NULL upon error 3203 * @return the duplicate key; NULL upon error
2777 */ 3204 */
2778struct GNUNET_CRYPTO_RsaSignature * 3205struct GNUNET_CRYPTO_RsaSignature *
2779GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig); 3206GNUNET_CRYPTO_rsa_signature_dup (
3207 const struct GNUNET_CRYPTO_RsaSignature *sig);
2780 3208
2781 3209
2782/** 3210/**
@@ -2799,13 +3227,15 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
2799 * 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
2800 * signature is valid with respect to the given public key. 3228 * signature is valid with respect to the given public key.
2801 * 3229 *
2802 * @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
2803 * @param sig signature that is being validated 3232 * @param sig signature that is being validated
2804 * @param public_key public key of the signer 3233 * @param public_key public key of the signer
2805 * @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
2806 */ 3235 */
2807enum GNUNET_GenericReturnValue 3236enum GNUNET_GenericReturnValue
2808GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, 3237GNUNET_CRYPTO_rsa_verify (const void *message,
3238 size_t message_size,
2809 const struct GNUNET_CRYPTO_RsaSignature *sig, 3239 const struct GNUNET_CRYPTO_RsaSignature *sig,
2810 const struct GNUNET_CRYPTO_RsaPublicKey *public_key); 3240 const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
2811 3241
@@ -2845,10 +3275,11 @@ GNUNET_CRYPTO_cs_private_key_get_public (
2845 * @param[out] r array containing derived secrets r0 and r1 3275 * @param[out] r array containing derived secrets r0 and r1
2846 */ 3276 */
2847void 3277void
2848GNUNET_CRYPTO_cs_r_derive (const struct GNUNET_CRYPTO_CsNonce *nonce, 3278GNUNET_CRYPTO_cs_r_derive (
2849 const char *seed, 3279 const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
2850 const struct GNUNET_CRYPTO_CsPrivateKey *lts, 3280 const char *seed,
2851 struct GNUNET_CRYPTO_CsRSecret r[2]); 3281 const struct GNUNET_CRYPTO_CsPrivateKey *lts,
3282 struct GNUNET_CRYPTO_CsRSecret r[2]);
2852 3283
2853 3284
2854/** 3285/**
@@ -2858,27 +3289,57 @@ GNUNET_CRYPTO_cs_r_derive (const struct GNUNET_CRYPTO_CsNonce *nonce,
2858 * @param[out] r_pub where to write the public key 3289 * @param[out] r_pub where to write the public key
2859 */ 3290 */
2860void 3291void
2861GNUNET_CRYPTO_cs_r_get_public (const struct GNUNET_CRYPTO_CsRSecret *r_priv, 3292GNUNET_CRYPTO_cs_r_get_public (
2862 struct GNUNET_CRYPTO_CsRPublic *r_pub); 3293 const struct GNUNET_CRYPTO_CsRSecret *r_priv,
3294 struct GNUNET_CRYPTO_CsRPublic *r_pub);
3295
2863 3296
2864/** 3297/**
2865 * Derives new random blinding factors. 3298 * Derives new random blinding factors.
2866 * In original papers blinding factors are generated randomly 3299 * In original papers blinding factors are generated randomly
2867 * To provide abort-idempotency, blinding factors need to be derived but still need to be UNPREDICTABLE 3300 * To provide abort-idempotency, blinding factors need to be derived but still need to be UNPREDICTABLE.
2868 * To ensure unpredictability a new nonce has to be used. 3301 * To ensure unpredictability a new nonce has to be used.
2869 * Uses HKDF internally 3302 * Uses HKDF internally.
2870 * 3303 *
2871 * @param blind_seed is the blinding seed to derive blinding factors 3304 * @param blind_seed is the blinding seed to derive blinding factors
2872 * @param[out] bs array containing the two derived blinding secrets 3305 * @param[out] bs array containing the two derived blinding secrets
2873 */ 3306 */
2874void 3307void
2875GNUNET_CRYPTO_cs_blinding_secrets_derive ( 3308GNUNET_CRYPTO_cs_blinding_secrets_derive (
2876 const struct GNUNET_CRYPTO_CsNonce *blind_seed, 3309 const struct GNUNET_CRYPTO_CsBlindingNonce *blind_seed,
2877 struct GNUNET_CRYPTO_CsBlindingSecret bs[2]); 3310 struct GNUNET_CRYPTO_CsBlindingSecret bs[2]);
2878 3311
2879 3312
2880/** 3313/**
2881 * Calculate two blinded c's 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.
2882 * Comment: One would be insecure due to Wagner's algorithm solving ROS 3343 * Comment: One would be insecure due to Wagner's algorithm solving ROS
2883 * 3344 *
2884 * @param bs array of the two blinding factor structs each containing alpha and beta 3345 * @param bs array of the two blinding factor structs each containing alpha and beta
@@ -2887,7 +3348,7 @@ GNUNET_CRYPTO_cs_blinding_secrets_derive (
2887 * @param msg the message to blind in preparation for signing 3348 * @param msg the message to blind in preparation for signing
2888 * @param msg_len length of message msg 3349 * @param msg_len length of message msg
2889 * @param[out] blinded_c array of the two blinded c's 3350 * @param[out] blinded_c array of the two blinded c's
2890 * @param[out] blinded_r_pub array of the two blinded R 3351 * @param[out] r_pub_blind array of the two blinded R
2891 */ 3352 */
2892void 3353void
2893GNUNET_CRYPTO_cs_calc_blinded_c ( 3354GNUNET_CRYPTO_cs_calc_blinded_c (
@@ -2897,32 +3358,49 @@ GNUNET_CRYPTO_cs_calc_blinded_c (
2897 const void *msg, 3358 const void *msg,
2898 size_t msg_len, 3359 size_t msg_len,
2899 struct GNUNET_CRYPTO_CsC blinded_c[2], 3360 struct GNUNET_CRYPTO_CsC blinded_c[2],
2900 struct GNUNET_CRYPTO_CsRPublic blinded_r_pub[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};
2901 3382
2902 3383
2903/** 3384/**
2904 * Sign a blinded c 3385 * Sign a blinded @a c.
2905 * This function derives b from a nonce and a longterm secret 3386 * This function derives b from a nonce and a longterm secret.
2906 * In original papers b is generated randomly 3387 * In the original papers b is generated randomly.
2907 * To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE. 3388 * To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE.
2908 * To ensure unpredictability a new nonce has to be used for every signature 3389 * To ensure unpredictability a new nonce has to be used for every signature.
2909 * HKDF is used internally for derivation 3390 * HKDF is used internally for derivation.
2910 * r0 and r1 can be derived prior by using GNUNET_CRYPTO_cs_r_derive 3391 * r0 and r1 can be derived prior by using GNUNET_CRYPTO_cs_r_derive.
2911 * 3392 *
2912 * @param priv private key to use for the signing and as LTS in HKDF 3393 * @param priv private key to use for the signing and as LTS in HKDF
2913 * @param r array of the two secret nonce from the signer 3394 * @param r array of the two secret inputs from the signer
2914 * @param c array of the two blinded c to sign c_b 3395 * @param bm blinded message, including array of the two blinded c to sign c_b and the random nonce
2915 * @param nonce is a random nonce 3396 * @param[out] cs_blind_sig where to write the blind signature
2916 * @param[out] blinded_signature_scalar where to write the signature
2917 * @return 0 or 1 for b (see Clause Blind Signature Scheme)
2918 */ 3397 */
2919unsigned int 3398void
2920GNUNET_CRYPTO_cs_sign_derive ( 3399GNUNET_CRYPTO_cs_sign_derive (
2921 const struct GNUNET_CRYPTO_CsPrivateKey *priv, 3400 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
2922 const struct GNUNET_CRYPTO_CsRSecret r[2], 3401 const struct GNUNET_CRYPTO_CsRSecret r[2],
2923 const struct GNUNET_CRYPTO_CsC c[2], 3402 const struct GNUNET_CRYPTO_CsBlindedMessage *bm,
2924 const struct GNUNET_CRYPTO_CsNonce *nonce, 3403 struct GNUNET_CRYPTO_CsBlindSignature *cs_blind_sig);
2925 struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar);
2926 3404
2927 3405
2928/** 3406/**
@@ -2950,11 +3428,1065 @@ GNUNET_CRYPTO_cs_unblind (
2950 * @returns #GNUNET_YES on success, #GNUNET_SYSERR if signature invalid 3428 * @returns #GNUNET_YES on success, #GNUNET_SYSERR if signature invalid
2951 */ 3429 */
2952enum GNUNET_GenericReturnValue 3430enum GNUNET_GenericReturnValue
2953GNUNET_CRYPTO_cs_verify (const struct GNUNET_CRYPTO_CsSignature *sig, 3431GNUNET_CRYPTO_cs_verify (
2954 const struct GNUNET_CRYPTO_CsPublicKey *pub, 3432 const struct GNUNET_CRYPTO_CsSignature *sig,
2955 const void *msg, 3433 const struct GNUNET_CRYPTO_CsPublicKey *pub,
2956 size_t msg_len); 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
2957 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);
2958 4490
2959#if 0 /* keep Emacsens' auto-indent happy */ 4491#if 0 /* keep Emacsens' auto-indent happy */
2960{ 4492{
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h
index bdf3843b1..967170085 100644
--- a/src/include/gnunet_curl_lib.h
+++ b/src/include/gnunet_curl_lib.h
@@ -433,7 +433,7 @@ GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
433 * 433 *
434 * @returns #GNUNET_YES iff given a valid scope ID 434 * @returns #GNUNET_YES iff given a valid scope ID
435 */ 435 */
436int 436enum GNUNET_GenericReturnValue
437GNUNET_CURL_is_valid_scope_id (const char *scope_id); 437GNUNET_CURL_is_valid_scope_id (const char *scope_id);
438 438
439 439
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 3d1264991..a1ea31c25 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -43,7 +43,6 @@
43 43
44#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
45#include "gnunet_block_lib.h" 45#include "gnunet_block_lib.h"
46#include "gnunet_hello_lib.h"
47 46
48#ifdef __cplusplus 47#ifdef __cplusplus
49extern "C" 48extern "C"
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index b14c5e59d..2aec55851 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -32,7 +32,7 @@
32 * @{ 32 * @{
33 */ 33 */
34 34
35#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 35#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
36#error "Only <gnunet_util_lib.h> can be included directly." 36#error "Only <gnunet_util_lib.h> can be included directly."
37#endif 37#endif
38 38
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index 8064b554b..9a84f346f 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -84,6 +84,7 @@
84#define GNUNET_DNSPARSER_TYPE_NSEC3 50 84#define GNUNET_DNSPARSER_TYPE_NSEC3 50
85#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51 85#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
86#define GNUNET_DNSPARSER_TYPE_TLSA 52 86#define GNUNET_DNSPARSER_TYPE_TLSA 52
87#define GNUNET_DNSPARSER_TYPE_SMIMEA 53
87#define GNUNET_DNSPARSER_TYPE_HIP 55 88#define GNUNET_DNSPARSER_TYPE_HIP 55
88#define GNUNET_DNSPARSER_TYPE_CDS 59 89#define GNUNET_DNSPARSER_TYPE_CDS 59
89#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60 90#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
@@ -178,6 +179,33 @@ struct GNUNET_DNSPARSER_SrvRecord
178 179
179 180
180/** 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/**
181 * DNS CERT types as defined in RFC 4398. 209 * DNS CERT types as defined in RFC 4398.
182 */ 210 */
183enum GNUNET_DNSPARSER_CertType 211enum GNUNET_DNSPARSER_CertType
@@ -479,6 +507,11 @@ struct GNUNET_DNSPARSER_Record
479 struct GNUNET_DNSPARSER_SrvRecord *srv; 507 struct GNUNET_DNSPARSER_SrvRecord *srv;
480 508
481 /** 509 /**
510 * URI data for URI records.
511 */
512 struct GNUNET_DNSPARSER_UriRecord *uri;
513
514 /**
482 * Raw data for all other types. 515 * Raw data for all other types.
483 */ 516 */
484 struct GNUNET_DNSPARSER_RawRecord raw; 517 struct GNUNET_DNSPARSER_RawRecord raw;
@@ -743,6 +776,25 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst,
743 size_t *off, 776 size_t *off,
744 const struct GNUNET_DNSPARSER_SrvRecord *srv); 777 const struct GNUNET_DNSPARSER_SrvRecord *srv);
745 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
746/* ***************** low-level parsing API ******************** */ 798/* ***************** low-level parsing API ******************** */
747 799
748/** 800/**
@@ -853,6 +905,21 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
853 size_t udp_payload_length, 905 size_t udp_payload_length,
854 size_t *off); 906 size_t *off);
855 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
856/* ***************** low-level duplication API ******************** */ 923/* ***************** low-level duplication API ******************** */
857 924
858/** 925/**
@@ -909,6 +976,16 @@ GNUNET_DNSPARSER_duplicate_srv_record (const struct
909 GNUNET_DNSPARSER_SrvRecord *r); 976 GNUNET_DNSPARSER_SrvRecord *r);
910 977
911 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
912/* ***************** low-level deallocation API ******************** */ 989/* ***************** low-level deallocation API ******************** */
913 990
914/** 991/**
@@ -939,6 +1016,15 @@ GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv);
939 1016
940 1017
941/** 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/**
942 * Free SOA information record. 1028 * Free SOA information record.
943 * 1029 *
944 * @param soa record to free 1030 * @param soa record to free
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 c8e99826a..000000000
--- a/src/include/gnunet_fragmentation_lib.h
+++ /dev/null
@@ -1,235 +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 * @addtogroup Backbone
22 * @{
23 *
24 * @author Christian Grothoff
25 *
26 * @file
27 * Library to help fragment messages
28 *
29 * @defgroup fragmentation Fragmentation library
30 * Library to help fragment messages
31 * @{
32 *
33 * @todo Consider additional flow-control for sending from
34 * fragmentation based on continuations.
35 */
36
37#ifndef GNUNET_FRAGMENTATION_LIB_H
38#define GNUNET_FRAGMENTATION_LIB_H
39
40
41#include "gnunet_util_lib.h"
42#include "gnunet_statistics_service.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 * Fragmentation context.
55 */
56struct GNUNET_FRAGMENT_Context;
57
58
59/**
60 * Function that is called with messages created by the fragmentation
61 * module. In the case of the 'proc' callback of the
62 * #GNUNET_FRAGMENT_context_create() function, this function must
63 * eventually call #GNUNET_FRAGMENT_context_transmission_done().
64 *
65 * @param cls closure
66 * @param msg the message that was created
67 */
68typedef void
69(*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
70 const struct GNUNET_MessageHeader *msg);
71
72
73/**
74 * Create a fragmentation context for the given message.
75 * Fragments the message into fragments of size @a mtu or
76 * less. Calls @a proc on each un-acknowledged fragment,
77 * using both the expected @a msg_delay between messages and
78 * acknowledgements and the given @a tracker to guide the
79 * frequency of calls to @a proc.
80 *
81 * @param stats statistics context
82 * @param mtu the maximum message size for each fragment
83 * @param tracker bandwidth tracker to use for flow control (can be NULL)
84 * @param msg_delay initial delay to insert between fragment transmissions
85 * based on previous messages
86 * @param ack_delay expected delay between fragment transmission
87 * and ACK based on previous messages
88 * @param msg the message to fragment
89 * @param proc function to call for each fragment to transmit
90 * @param proc_cls closure for proc
91 * @return the fragmentation context
92 */
93struct GNUNET_FRAGMENT_Context *
94GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
95 uint16_t mtu,
96 struct GNUNET_BANDWIDTH_Tracker *tracker,
97 struct GNUNET_TIME_Relative msg_delay,
98 struct GNUNET_TIME_Relative ack_delay,
99 const struct GNUNET_MessageHeader *msg,
100 GNUNET_FRAGMENT_MessageProcessor proc,
101 void *proc_cls);
102
103
104/**
105 * Continuation to call from the 'proc' function after the fragment
106 * has been transmitted (and hence the next fragment can now be
107 * given to proc).
108 *
109 * @param fc fragmentation context
110 */
111void
112GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
113
114
115/**
116 * Process an acknowledgement message we got from the other
117 * side (to control re-transmits).
118 *
119 * @param fc fragmentation context
120 * @param msg acknowledgement message we received
121 * @return #GNUNET_OK if this ack completes the work of the 'fc'
122 * (all fragments have been received);
123 * #GNUNET_NO if more messages are pending
124 * #GNUNET_SYSERR if this ack is not valid for this fc
125 */
126int
127GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
128 const struct GNUNET_MessageHeader *msg);
129
130
131/**
132 * Destroy the given fragmentation context (stop calling 'proc', free
133 * resources).
134 *
135 * @param fc fragmentation context
136 * @param msg_delay where to store average delay between individual message transmissions the
137 * last message (OUT only)
138 * @param ack_delay where to store average delay between transmission and ACK for the
139 * last message, set to FOREVER if the message was not fully transmitted (OUT only)
140 */
141void
142GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
143 struct GNUNET_TIME_Relative *msg_delay,
144 struct GNUNET_TIME_Relative *ack_delay);
145
146
147/**
148 * Convert an ACK message to a printable format suitable for logging.
149 *
150 * @param ack message to print
151 * @return ack in human-readable format
152 */
153const char *
154GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack);
155
156
157/**
158 * Defragmentation context (one per connection).
159 */
160struct GNUNET_DEFRAGMENT_Context;
161
162
163/**
164 * Function that is called with acknowledgement messages created by
165 * the fragmentation module. Acknowledgements are cumulative,
166 * so it is OK to only transmit the 'latest' ack message for the same
167 * message ID.
168 *
169 * @param cls closure
170 * @param id unique message ID (modulo collisions)
171 * @param msg the message that was created
172 */
173typedef void
174(*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
175 uint32_t id,
176 const struct GNUNET_MessageHeader *msg);
177
178
179/**
180 * Create a defragmentation context.
181 *
182 * @param stats statistics context
183 * @param mtu the maximum message size for each fragment
184 * @param num_msgs how many fragmented messages
185 * to we defragment at most at the same time?
186 * @param cls closure for @a proc and @a ackp
187 * @param proc function to call with defragmented messages
188 * @param ackp function to call with acknowledgements (to send
189 * back to the other side)
190 * @return the defragmentation context
191 */
192struct GNUNET_DEFRAGMENT_Context *
193GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
194 uint16_t mtu,
195 unsigned int num_msgs,
196 void *cls,
197 GNUNET_FRAGMENT_MessageProcessor proc,
198 GNUNET_DEFRAGMENT_AckProcessor ackp);
199
200
201/**
202 * Destroy the given defragmentation context.
203 *
204 * @param dc defragmentation context
205 */
206void
207GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
208
209
210/**
211 * We have received a fragment. Process it.
212 *
213 * @param dc the context
214 * @param msg the message that was received
215 * @return #GNUNET_OK on success,
216 * #GNUNET_NO if this was a duplicate,
217 * #GNUNET_SYSERR on error
218 */
219int
220GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
221 const struct GNUNET_MessageHeader *msg);
222
223
224#if 0 /* keep Emacsens' auto-indent happy */
225{
226#endif
227#ifdef __cplusplus
228}
229#endif
230
231#endif
232
233/** @} */ /* end of group */
234
235/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_friends_lib.h b/src/include/gnunet_friends_lib.h
deleted file mode 100644
index 4f4d5e88b..000000000
--- a/src/include/gnunet_friends_lib.h
+++ /dev/null
@@ -1,124 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * Library to read and write the FRIENDS file
29 *
30 * @defgroup friends Friends library
31 * Library to read and write the FRIENDS file
32 * @{
33 */
34#ifndef GNUNET_FRIENDS_LIB_H
35#define GNUNET_FRIENDS_LIB_H
36
37#ifdef __cplusplus
38extern "C"
39{
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 * Signature of a function called on each friend found.
51 *
52 * @param cls closure
53 * @param friend_id peer identity of the friend
54 */
55typedef void (*GNUNET_FRIENDS_Callback)(void *cls,
56 const struct
57 GNUNET_PeerIdentity *friend_id);
58
59
60/**
61 * Parse the FRIENDS file.
62 *
63 * @param cfg our configuration
64 * @param cb function to call on each friend found
65 * @param cb_cls closure for @a cb
66 * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors
67 */
68int
69GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
70 GNUNET_FRIENDS_Callback cb,
71 void *cb_cls);
72
73
74/**
75 * Handle for writing a friends file.
76 */
77struct GNUNET_FRIENDS_Writer;
78
79
80/**
81 * Start writing a fresh FRIENDS file. Will make a backup of the
82 * old one.
83 *
84 * @param cfg configuration to use.
85 * @return NULL on error
86 */
87struct GNUNET_FRIENDS_Writer *
88GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
89
90
91/**
92 * Finish writing out the friends file.
93 *
94 * @param w write handle
95 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
96 */
97int
98GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w);
99
100
101/**
102 * Add a friend to the friends file.
103 *
104 * @param w write handle
105 * @param friend_id friend to add
106 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
107 */
108int
109GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
110 const struct GNUNET_PeerIdentity *friend_id);
111
112
113#if 0 /* keep Emacsens' auto-indent happy */
114{
115#endif
116#ifdef __cplusplus
117}
118#endif
119
120#endif
121
122/** @} */ /* end of group */
123
124/** @} */ /* end of group addition to backbone */
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 5c271c71f..a05e07ac5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -525,6 +525,17 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
525 525
526 526
527/** 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/**
528 * Is this a location URI? 539 * Is this a location URI?
529 * 540 *
530 * @param uri the uri to check 541 * @param uri the uri to check
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index 390e8c153..91ba362e5 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -33,7 +33,7 @@
33 * @{ 33 * @{
34 */ 34 */
35 35
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 36#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly." 37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif 38#endif
39 39
@@ -275,12 +275,12 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName,
275 argumentHelp, \ 275 argumentHelp, \
276 description, \ 276 description, \
277 val) \ 277 val) \
278 GNUNET_GETOPT_option_base32_fixed_size (shortName, \ 278 GNUNET_GETOPT_option_base32_fixed_size (shortName, \
279 name, \ 279 name, \
280 argumentHelp, \ 280 argumentHelp, \
281 description, \ 281 description, \
282 val, \ 282 val, \
283 sizeof(*val)) 283 sizeof(*val))
284 284
285 285
286/** 286/**
@@ -481,9 +481,9 @@ GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt);
481 * Marker for the end of the list of options. 481 * Marker for the end of the list of options.
482 */ 482 */
483#define GNUNET_GETOPT_OPTION_END \ 483#define GNUNET_GETOPT_OPTION_END \
484 { \ 484 { \
485 '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \ 485 '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
486 } 486 }
487 487
488 488
489/** 489/**
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 1fcf7aa8b..e7ed2d3c2 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -137,7 +137,7 @@ enum GNUNET_GNS_LocalOptions
137struct GNUNET_GNS_LookupRequest * 137struct GNUNET_GNS_LookupRequest *
138GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 138GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
139 const char *name, 139 const char *name,
140 const struct GNUNET_IDENTITY_PublicKey *zone, 140 const struct GNUNET_CRYPTO_PublicKey *zone,
141 uint32_t type, 141 uint32_t type,
142 enum GNUNET_GNS_LocalOptions options, 142 enum GNUNET_GNS_LocalOptions options,
143 GNUNET_GNS_LookupResultProcessor proc, 143 GNUNET_GNS_LookupResultProcessor proc,
@@ -161,7 +161,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
161struct GNUNET_GNS_LookupRequest * 161struct GNUNET_GNS_LookupRequest *
162GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, 162GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
163 const char *name, 163 const char *name,
164 const struct GNUNET_IDENTITY_PublicKey *zone, 164 const struct GNUNET_CRYPTO_PublicKey *zone,
165 uint32_t type, 165 uint32_t type,
166 enum GNUNET_GNS_LocalOptions options, 166 enum GNUNET_GNS_LocalOptions options,
167 uint16_t recursion_depth_limit, 167 uint16_t recursion_depth_limit,
@@ -227,6 +227,16 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
227void * 227void *
228GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); 228GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
229 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);
230 240
231#if 0 /* keep Emacsens' auto-indent happy */ 241#if 0 /* keep Emacsens' auto-indent happy */
232{ 242{
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index 3aee30117..b4e45727b 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -38,6 +38,7 @@
38#define GNUNET_GNSRECORD_LIB_H 38#define GNUNET_GNSRECORD_LIB_H
39 39
40 40
41#include "gnunet_common.h"
41#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
42 43
43#ifdef __cplusplus 44#ifdef __cplusplus
@@ -120,6 +121,10 @@ enum GNUNET_GNSRECORD_Flags
120 */ 121 */
121 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13), 122 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
122 123
124 /**
125 * Maintenance records. E.g. TOMBSTONEs
126 */
127 GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2),
123 128
124 /** 129 /**
125 * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation. 130 * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation.
@@ -326,6 +331,31 @@ struct GNUNET_GNSRECORD_BoxRecord
326 /* followed by the 'original' record */ 331 /* followed by the 'original' record */
327}; 332};
328 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
329/** 359/**
330 * 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
331 * namespace. 361 * namespace.
@@ -338,7 +368,7 @@ struct GNUNET_GNSRECORD_ReverseRecord
338 /** 368 /**
339 * 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
340 */ 370 */
341 struct GNUNET_IDENTITY_PublicKey pkey; 371 struct GNUNET_CRYPTO_PublicKey pkey;
342 372
343 /** 373 /**
344 * The expiration time of the delegation 374 * The expiration time of the delegation
@@ -493,7 +523,7 @@ GNUNET_GNSRECORD_string_normalize (const char *src);
493 * #GNUNET_GNSRECORD_z2s. 523 * #GNUNET_GNSRECORD_z2s.
494 */ 524 */
495const char * 525const char *
496GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); 526GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z);
497 527
498 528
499/** 529/**
@@ -507,7 +537,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z);
507 * key in an encoding suitable for DNS labels. 537 * key in an encoding suitable for DNS labels.
508 */ 538 */
509const char * 539const char *
510GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); 540GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey);
511 541
512 542
513/** 543/**
@@ -521,7 +551,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey);
521 */ 551 */
522int 552int
523GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 553GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
524 struct GNUNET_IDENTITY_PublicKey *pkey); 554 struct GNUNET_CRYPTO_PublicKey *pkey);
525 555
526 556
527/** 557/**
@@ -533,7 +563,7 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
533 */ 563 */
534void 564void
535GNUNET_GNSRECORD_query_from_private_key ( 565GNUNET_GNSRECORD_query_from_private_key (
536 const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, 566 const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label,
537 struct GNUNET_HashCode *query); 567 struct GNUNET_HashCode *query);
538 568
539 569
@@ -547,7 +577,7 @@ GNUNET_GNSRECORD_query_from_private_key (
547 */ 577 */
548void 578void
549GNUNET_GNSRECORD_query_from_public_key ( 579GNUNET_GNSRECORD_query_from_public_key (
550 const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, 580 const struct GNUNET_CRYPTO_PublicKey *pub, const char *label,
551 struct GNUNET_HashCode *query); 581 struct GNUNET_HashCode *query);
552 582
553 583
@@ -561,7 +591,7 @@ GNUNET_GNSRECORD_query_from_public_key (
561 */ 591 */
562ssize_t 592ssize_t
563GNUNET_GNSRECORD_block_calculate_size (const struct 593GNUNET_GNSRECORD_block_calculate_size (const struct
564 GNUNET_IDENTITY_PrivateKey *key, 594 GNUNET_CRYPTO_PrivateKey *key,
565 const struct GNUNET_GNSRECORD_Data *rd, 595 const struct GNUNET_GNSRECORD_Data *rd,
566 unsigned int rd_count); 596 unsigned int rd_count);
567 597
@@ -575,7 +605,7 @@ GNUNET_GNSRECORD_block_calculate_size (const struct
575 */ 605 */
576enum GNUNET_GenericReturnValue 606enum GNUNET_GenericReturnValue
577GNUNET_GNSRECORD_block_sign (const struct 607GNUNET_GNSRECORD_block_sign (const struct
578 GNUNET_IDENTITY_PrivateKey *key, 608 GNUNET_CRYPTO_PrivateKey *key,
579 const char *label, 609 const char *label,
580 struct GNUNET_GNSRECORD_Block *block); 610 struct GNUNET_GNSRECORD_Block *block);
581 611
@@ -591,7 +621,7 @@ GNUNET_GNSRECORD_block_sign (const struct
591 * @return GNUNET_OK on success 621 * @return GNUNET_OK on success
592 */ 622 */
593enum GNUNET_GenericReturnValue 623enum GNUNET_GenericReturnValue
594GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, 624GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key,
595 struct GNUNET_TIME_Absolute expire, 625 struct GNUNET_TIME_Absolute expire,
596 const char *label, 626 const char *label,
597 const struct GNUNET_GNSRECORD_Data *rd, 627 const struct GNUNET_GNSRECORD_Data *rd,
@@ -616,7 +646,7 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key,
616 */ 646 */
617enum GNUNET_GenericReturnValue 647enum GNUNET_GenericReturnValue
618GNUNET_GNSRECORD_block_create_unsigned (const struct 648GNUNET_GNSRECORD_block_create_unsigned (const struct
619 GNUNET_IDENTITY_PrivateKey *key, 649 GNUNET_CRYPTO_PrivateKey *key,
620 struct GNUNET_TIME_Absolute expire, 650 struct GNUNET_TIME_Absolute expire,
621 const char *label, 651 const char *label,
622 const struct GNUNET_GNSRECORD_Data *rd, 652 const struct GNUNET_GNSRECORD_Data *rd,
@@ -638,7 +668,7 @@ GNUNET_GNSRECORD_block_create_unsigned (const struct
638 * @return GNUNET_OK on success. 668 * @return GNUNET_OK on success.
639 */ 669 */
640enum GNUNET_GenericReturnValue 670enum GNUNET_GenericReturnValue
641GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, 671GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key,
642 struct GNUNET_TIME_Absolute expire, 672 struct GNUNET_TIME_Absolute expire,
643 const char *label, 673 const char *label,
644 const struct GNUNET_GNSRECORD_Data *rd, 674 const struct GNUNET_GNSRECORD_Data *rd,
@@ -653,7 +683,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key,
653 * @param block block to verify 683 * @param block block to verify
654 * @return #GNUNET_OK if the signature is valid 684 * @return #GNUNET_OK if the signature is valid
655 */ 685 */
656int 686enum GNUNET_GenericReturnValue
657GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); 687GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
658 688
659 689
@@ -668,10 +698,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
668 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was 698 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was
669 * not well-formed 699 * not well-formed
670 */ 700 */
671int 701enum GNUNET_GenericReturnValue
672GNUNET_GNSRECORD_block_decrypt ( 702GNUNET_GNSRECORD_block_decrypt (
673 const struct GNUNET_GNSRECORD_Block *block, 703 const struct GNUNET_GNSRECORD_Block *block,
674 const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, 704 const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label,
675 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); 705 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls);
676 706
677 707
@@ -682,7 +712,7 @@ GNUNET_GNSRECORD_block_decrypt (
682 * @param b another record 712 * @param b another record
683 * @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.
684 */ 714 */
685int 715enum GNUNET_GenericReturnValue
686GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, 716GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
687 const struct GNUNET_GNSRECORD_Data *b); 717 const struct GNUNET_GNSRECORD_Data *b);
688 718
@@ -751,7 +781,7 @@ enum GNUNET_GenericReturnValue
751GNUNET_GNSRECORD_identity_from_data (const char *data, 781GNUNET_GNSRECORD_identity_from_data (const char *data,
752 size_t data_size, 782 size_t data_size,
753 uint32_t type, 783 uint32_t type,
754 struct GNUNET_IDENTITY_PublicKey *key); 784 struct GNUNET_CRYPTO_PublicKey *key);
755 785
756 786
757/** 787/**
@@ -765,7 +795,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data,
765 */ 795 */
766enum GNUNET_GenericReturnValue 796enum GNUNET_GenericReturnValue
767GNUNET_GNSRECORD_data_from_identity (const struct 797GNUNET_GNSRECORD_data_from_identity (const struct
768 GNUNET_IDENTITY_PublicKey *key, 798 GNUNET_CRYPTO_PublicKey *key,
769 char **data, 799 char **data,
770 size_t *data_size, 800 size_t *data_size,
771 uint32_t *type); 801 uint32_t *type);
@@ -828,6 +858,135 @@ GNUNET_GNSRECORD_normalize_record_set (const char *label,
828enum GNUNET_GenericReturnValue 858enum GNUNET_GenericReturnValue
829GNUNET_GNSRECORD_label_check (const char*label, char **emsg); 859GNUNET_GNSRECORD_label_check (const char*label, char **emsg);
830 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);
989
831#if 0 /* keep Emacsens' auto-indent happy */ 990#if 0 /* keep Emacsens' auto-indent happy */
832{ 991{
833#endif 992#endif
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h
deleted file mode 100644
index 20a61cbfb..000000000
--- a/src/include/gnunet_hello_lib.h
+++ /dev/null
@@ -1,545 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 * @file
27 * Helper library for handling HELLOs
28 *
29 * @defgroup hello Hello library
30 * Helper library for handling HELLOs
31 *
32 * @see [Documentation](https://gnunet.org/gnunets-hostlist-subsystem)
33 *
34 * @{
35 */
36
37#ifndef GNUNET_HELLO_LIB_H
38#define GNUNET_HELLO_LIB_H
39
40#ifdef __cplusplus
41extern "C" {
42#if 0 /* keep Emacsens' auto-indent happy */
43}
44#endif
45#endif
46
47
48#include "gnunet_util_lib.h"
49
50/**
51 * Prefix that every HELLO URI must start with.
52 */
53#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
54
55/**
56 * Prefix that every FRIEND HELLO URI must start with.
57 */
58#define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
59
60/**
61 * Separator used in HELLO URI
62 */
63#define GNUNET_HELLO_URI_SEP '+'
64
65
66/**
67 * Additional local information about an address
68 *
69 * These information are only valid for the local peer and are not serialized
70 * when a #GNUNET_HELLO_Message is created
71 */
72enum GNUNET_HELLO_AddressInfo
73{
74 /**
75 * No additional information
76 */
77 GNUNET_HELLO_ADDRESS_INFO_NONE = 0,
78
79 /**
80 * This is an inbound address and cannot be used to initiate an outbound
81 * connection to another peer
82 */
83 GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1
84};
85
86
87/**
88 * An address for communicating with a peer. We frequently
89 * need this tuple and the components cannot really be
90 * separated. This is NOT the format that would be used
91 * on the wire.
92 */
93struct GNUNET_HELLO_Address
94{
95 /**
96 * For which peer is this an address?
97 */
98 struct GNUNET_PeerIdentity peer;
99
100 /**
101 * Name of the transport plugin enabling the communication using
102 * this address.
103 */
104 const char *transport_name;
105
106 /**
107 * Binary representation of the address (plugin-specific).
108 */
109 const void *address;
110
111 /**
112 * Number of bytes in @e address.
113 */
114 size_t address_length;
115
116 /**
117 * Extended information about address
118 *
119 * This field contains additional #GNUNET_HELLO_AddressInfo flags e.g.
120 * to indicate an address is inbound and cannot be used to initiate an
121 * outbound connection.
122 *
123 * These information are only valid for the local peer and are not serialized
124 * when a #GNUNET_HELLO_Message is created
125 */
126 enum GNUNET_HELLO_AddressInfo local_info;
127};
128
129
130/**
131 * Allocate an address struct.
132 *
133 * @param peer the peer
134 * @param transport_name plugin name
135 * @param address binary address
136 * @param address_length number of bytes in @a address
137 * @param local_info additional local information for the address
138 * @return the address struct
139 */
140struct GNUNET_HELLO_Address *
141GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
142 const char *transport_name,
143 const void *address,
144 size_t address_length,
145 enum GNUNET_HELLO_AddressInfo local_info);
146
147
148/**
149 * Copy an address struct.
150 *
151 * @param address address to copy
152 * @return a copy of the address struct
153 */
154struct GNUNET_HELLO_Address *
155GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
156
157
158/**
159 * Compare two addresses. Does NOT compare the peer identity,
160 * that is assumed already to match!
161 *
162 * @param a1 first address
163 * @param a2 second address
164 * @return 0 if the addresses are equal, -1 if @a a1< @a a2, 1 if @a a1> @a a2.
165 */
166int
167GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
168 const struct GNUNET_HELLO_Address *a2);
169
170
171/**
172 * Get the size of an address struct.
173 *
174 * @param address address
175 * @return the size
176 */
177size_t
178GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
179
180
181/**
182 * Check if an address has a local option set
183 *
184 * @param address the address to check
185 * @param option the respective option to check for
186 * @return #GNUNET_YES or #GNUNET_NO
187 */
188int
189GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address,
190 enum GNUNET_HELLO_AddressInfo option);
191
192
193/**
194 * Free an address.
195 *
196 * @param addr address to free
197 */
198#define GNUNET_HELLO_address_free(addr) GNUNET_free (addr)
199
200
201GNUNET_NETWORK_STRUCT_BEGIN
202
203/**
204 * A HELLO message is used to exchange information about
205 * transports with other peers. This struct is always
206 * followed by the actual network addresses which have
207 * the format:
208 *
209 * 1) transport-name (0-terminated)
210 * 2) address-length (uint16_t, network byte order; possibly
211 * unaligned!)
212 * 3) address expiration (`struct GNUNET_TIME_AbsoluteNBO`); possibly
213 * unaligned!)
214 * 4) address (address-length bytes; possibly unaligned!)
215 */
216struct GNUNET_HELLO_Message
217{
218 /**
219 * Type will be #GNUNET_MESSAGE_TYPE_HELLO.
220 */
221 struct GNUNET_MessageHeader header;
222
223 /**
224 * Use in F2F mode: Do not gossip this HELLO message
225 */
226 uint32_t friend_only GNUNET_PACKED;
227
228 /**
229 * The public key of the peer.
230 */
231 struct GNUNET_CRYPTO_EddsaPublicKey publicKey;
232};
233GNUNET_NETWORK_STRUCT_END
234
235
236/**
237 * Return HELLO type
238 *
239 * @param h HELLO Message to test
240 * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise
241 */
242int
243GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h);
244
245
246/**
247 * Copy the given address information into
248 * the given buffer using the format of HELLOs.
249 *
250 * @param address address to add
251 * @param expiration expiration for the address
252 * @param target where to copy the address
253 * @param max maximum number of bytes to copy to @a target
254 * @return number of bytes copied, 0 if
255 * the target buffer was not big enough.
256 */
257size_t
258GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
259 struct GNUNET_TIME_Absolute expiration,
260 char *target,
261 size_t max);
262
263
264/**
265 * Callback function used to fill a buffer of max bytes with a list of
266 * addresses in the format used by HELLOs. Should use
267 * #GNUNET_HELLO_add_address() as a helper function.
268 *
269 * @param cls closure
270 * @param max maximum number of bytes that can be written to @a buf
271 * @param buf where to write the address information
272 * @return number of bytes written or 0, #GNUNET_SYSERR to signal the
273 * end of the iteration.
274 */
275typedef ssize_t
276(*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
277 size_t max,
278 void *buf);
279
280
281/**
282 * Construct a HELLO message given the public key,
283 * expiration time and an iterator that spews the
284 * transport addresses.
285 *
286 * If friend only is set to #GNUNET_YES we create a FRIEND_HELLO which
287 * will not be gossiped to other peers.
288 *
289 * @param public_key public key to include in the HELLO
290 * @param addrgen callback to invoke to get addresses
291 * @param addrgen_cls closure for @a addrgen
292 * @param friend_only should the returned HELLO be only visible to friends?
293 * @return the hello message
294 */
295struct GNUNET_HELLO_Message *
296GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
297 GNUNET_HELLO_GenerateAddressListCallback addrgen,
298 void *addrgen_cls,
299 int friend_only);
300
301
302/**
303 * Return the size of the given HELLO message.
304 *
305 * @param hello to inspect
306 * @return the size, 0 if HELLO is invalid
307 */
308uint16_t
309GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
310
311
312/**
313 * Construct a HELLO message by merging the
314 * addresses in two existing HELLOs (which
315 * must be for the same peer).
316 *
317 * @param h1 first HELLO message
318 * @param h2 the second HELLO message
319 * @return the combined hello message
320 */
321struct GNUNET_HELLO_Message *
322GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
323 const struct GNUNET_HELLO_Message *h2);
324
325
326/**
327 * Test if two HELLO messages contain the same addresses.
328 * If they only differ in expiration time, the lowest
329 * expiration time larger than 'now' where they differ
330 * is returned.
331 *
332 * @param h1 first HELLO message
333 * @param h2 the second HELLO message
334 * @param now time to use for deciding which addresses have
335 * expired and should not be considered at all
336 * @return absolute time forever if the two HELLOs are
337 * totally identical; smallest timestamp >= now if
338 * they only differ in timestamps;
339 * zero if the some addresses with expirations >= now
340 * do not match at all
341 */
342struct GNUNET_TIME_Absolute
343GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
344 const struct GNUNET_HELLO_Message *h2,
345 struct GNUNET_TIME_Absolute now);
346
347
348/**
349 * Iterator callback to go over all addresses.
350 *
351 * @param cls closure
352 * @param address the address
353 * @param expiration expiration time
354 * @return #GNUNET_OK to keep the address,
355 * #GNUNET_NO to delete it from the HELLO
356 * #GNUNET_SYSERR to stop iterating (but keep current address)
357 */
358typedef int (*GNUNET_HELLO_AddressIterator) (
359 void *cls,
360 const struct GNUNET_HELLO_Address *address,
361 struct GNUNET_TIME_Absolute expiration);
362
363
364/**
365 * When does the last address in the given HELLO expire?
366 *
367 * @param msg HELLO to inspect
368 * @return time the last address expires, 0 if there are no addresses in the HELLO
369 */
370struct GNUNET_TIME_Absolute
371GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
372
373
374/**
375 * Iterate over all of the addresses in the HELLO.
376 *
377 * @param msg HELLO to iterate over; client does not need to
378 * have verified that msg is well-formed (beyond starting
379 * with a GNUNET_MessageHeader of the right type).
380 * @param return_modified if a modified copy should be returned,
381 * otherwise NULL will be returned
382 * @param it iterator to call on each address
383 * @param it_cls closure for @a it
384 * @return the modified HELLO or NULL
385 */
386struct GNUNET_HELLO_Message *
387GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
388 int return_modified,
389 GNUNET_HELLO_AddressIterator it,
390 void *it_cls);
391
392
393/**
394 * Iterate over addresses in @a new_hello that are NOT already present
395 * in @a old_hello. Note that if the address is present in @a old_hello
396 * but the expiration time in @a new_hello is more recent, the
397 * iterator is also called.
398 *
399 * @param new_hello a HELLO message
400 * @param old_hello a HELLO message
401 * @param expiration_limit ignore addresses in old_hello
402 * that expired before the given time stamp
403 * @param it iterator to call on each address
404 * @param it_cls closure for @a it
405 */
406void
407GNUNET_HELLO_iterate_new_addresses (
408 const struct GNUNET_HELLO_Message *new_hello,
409 const struct GNUNET_HELLO_Message *old_hello,
410 struct GNUNET_TIME_Absolute expiration_limit,
411 GNUNET_HELLO_AddressIterator it,
412 void *it_cls);
413
414
415/**
416 * Get the peer identity from a HELLO message.
417 *
418 * @param hello the hello message
419 * @param peer where to store the peer's identity
420 * @return #GNUNET_SYSERR if the HELLO was malformed
421 */
422int
423GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
424 struct GNUNET_PeerIdentity *peer);
425
426
427/**
428 * Get the header from a HELLO message, used so other code
429 * can correctly send HELLO messages.
430 *
431 * @param hello the hello message
432 *
433 * @return header or NULL if the HELLO was malformed
434 */
435struct GNUNET_MessageHeader *
436GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
437
438
439/**
440 * Helper function to load/access transport plugins.
441 * FIXME: pass closure!
442 *
443 * @param name name of the transport plugin to load
444 * @return NULL if a plugin with name @a name is not known/loadable
445 */
446typedef struct GNUNET_TRANSPORT_PluginFunctions *(
447*GNUNET_HELLO_TransportPluginsFind) (const char *name);
448
449
450/**
451 * Compose a hello URI string from a hello message.
452 *
453 * @param hello Hello message
454 * @param plugins_find Function to find transport plugins by name
455 * @return Hello URI string
456 */
457char *
458GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
459 GNUNET_HELLO_TransportPluginsFind plugins_find);
460
461
462/**
463 * Parse a hello URI string to a hello message.
464 *
465 * @param uri URI string to parse
466 * @param pubkey Pointer to struct where public key is parsed
467 * @param hello Pointer to struct where hello message is parsed
468 * @param plugins_find Function to find transport plugins by name
469 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors
470 */
471int
472GNUNET_HELLO_parse_uri (const char *uri,
473 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey,
474 struct GNUNET_HELLO_Message **hello,
475 GNUNET_HELLO_TransportPluginsFind plugins_find);
476
477
478/* NG API */
479#include "gnunet_nt_lib.h"
480
481
482/**
483 * Build address record by signing raw information with private key.
484 *
485 * @param address text address to sign
486 * @param nt network type of @a address
487 * @param mono_time when was @a address valid
488 * @param private_key signing key to use
489 * @param[out] result where to write address record (allocated)
490 * @param[out] result_size set to size of @a result
491 */
492void
493GNUNET_HELLO_sign_address (
494 const char *address,
495 enum GNUNET_NetworkType nt,
496 struct GNUNET_TIME_Absolute mono_time,
497 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
498 void **result,
499 size_t *result_size);
500
501
502/**
503 * Check signature and extract address record.
504 *
505 * @param raw raw signed address
506 * @param raw_size size of @a raw
507 * @param pid public key to use for signature verification
508 * @param[out] nt set to network type
509 * @param[out] mono_time when was the address generated
510 * @return NULL on error, otherwise the address
511 */
512char *
513GNUNET_HELLO_extract_address (const void *raw,
514 size_t raw_size,
515 const struct GNUNET_PeerIdentity *pid,
516 enum GNUNET_NetworkType *nt,
517 struct GNUNET_TIME_Absolute *mono_time);
518
519
520/**
521 * Given an address as a string, extract the prefix that identifies
522 * the communicator offering transmissions to that address.
523 *
524 * @param address a peer's address
525 * @return NULL if the address is mal-formed, otherwise the prefix
526 */
527char *
528GNUNET_HELLO_address_to_prefix (const char *address);
529
530
531#if 0 /* keep Emacsens' auto-indent happy */
532{
533#endif
534#ifdef __cplusplus
535}
536#endif
537
538/* ifndef GNUNET_HELLO_LIB_H */
539#endif
540
541/** @} */ /* end of group */
542
543/** @} */ /* end of group addition */
544
545/* end of gnunet_hello_lib.h */
diff --git a/src/include/gnunet_hello_uri_lib.h b/src/include/gnunet_hello_uri_lib.h
index bba7078e6..aecda0885 100644
--- a/src/include/gnunet_hello_uri_lib.h
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -70,6 +70,13 @@ GNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid);
70 70
71 71
72/** 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/**
73 * Release resources of a @a builder. 80 * Release resources of a @a builder.
74 * 81 *
75 * @param[in] builder to free 82 * @param[in] builder to free
@@ -111,6 +118,17 @@ GNUNET_HELLO_builder_from_url (const char *url);
111 118
112 119
113/** 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/**
114 * Generate envelope with GNUnet HELLO message (including 132 * Generate envelope with GNUnet HELLO message (including
115 * peer ID) from a @a builder 133 * peer ID) from a @a builder
116 * 134 *
@@ -120,7 +138,8 @@ GNUNET_HELLO_builder_from_url (const char *url);
120 */ 138 */
121struct GNUNET_MQ_Envelope * 139struct GNUNET_MQ_Envelope *
122GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, 140GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
123 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv); 141 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
142 struct GNUNET_TIME_Relative expiration_time);
124 143
125 144
126/** 145/**
@@ -133,7 +152,8 @@ GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
133struct GNUNET_MessageHeader * 152struct GNUNET_MessageHeader *
134GNUNET_HELLO_builder_to_dht_hello_msg ( 153GNUNET_HELLO_builder_to_dht_hello_msg (
135 const struct GNUNET_HELLO_Builder *builder, 154 const struct GNUNET_HELLO_Builder *builder,
136 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv); 155 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
156 struct GNUNET_TIME_Relative expiration_time);
137 157
138 158
139/** 159/**
@@ -162,7 +182,8 @@ enum GNUNET_GenericReturnValue
162GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder, 182GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder,
163 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 183 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
164 void *block, 184 void *block,
165 size_t *block_size); 185 size_t *block_size,
186 struct GNUNET_TIME_Relative expiration_time);
166 187
167 188
168/** 189/**
@@ -199,6 +220,7 @@ GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder,
199 */ 220 */
200typedef void 221typedef void
201(*GNUNET_HELLO_UriCallback) (void *cls, 222(*GNUNET_HELLO_UriCallback) (void *cls,
223 const struct GNUNET_PeerIdentity* pid,
202 const char *uri); 224 const char *uri);
203 225
204 226
@@ -206,13 +228,12 @@ typedef void
206 * Iterate over URIs in a builder. 228 * Iterate over URIs in a builder.
207 * 229 *
208 * @param builder builder to iterate over 230 * @param builder builder to iterate over
209 * @param[out] pid set to the peer the @a builder is for
210 * @param uc callback invoked for each URI, can be NULL 231 * @param uc callback invoked for each URI, can be NULL
211 * @param uc_cls closure for @a addrgen 232 * @param uc_cls closure for @a addrgen
233 * @return pid of the peer the @a builder is for, can be NULL
212 */ 234 */
213void 235const struct GNUNET_PeerIdentity *
214GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, 236GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
215 struct GNUNET_PeerIdentity *pid,
216 GNUNET_HELLO_UriCallback uc, 237 GNUNET_HELLO_UriCallback uc,
217 void *uc_cls); 238 void *uc_cls);
218 239
@@ -237,6 +258,35 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello,
237 struct GNUNET_TIME_Absolute *block_expiration); 258 struct GNUNET_TIME_Absolute *block_expiration);
238 259
239 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
240#if 0 /* keep Emacsens' auto-indent happy */ 290#if 0 /* keep Emacsens' auto-indent happy */
241{ 291{
242#endif 292#endif
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h
index 2279abb24..57630c45c 100644
--- a/src/include/gnunet_helper_lib.h
+++ b/src/include/gnunet_helper_lib.h
@@ -38,7 +38,7 @@
38 * @{ 38 * @{
39 */ 39 */
40 40
41#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 41#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
42#error "Only <gnunet_util_lib.h> can be included directly." 42#error "Only <gnunet_util_lib.h> can be included directly."
43#endif 43#endif
44 44
@@ -99,8 +99,9 @@ GNUNET_HELPER_start (int with_control_pipe,
99 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper 99 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
100 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 100 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
101 */ 101 */
102int 102enum GNUNET_GenericReturnValue
103GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill); 103GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
104 int soft_kill);
104 105
105 106
106/** 107/**
@@ -111,7 +112,7 @@ GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
111 * @param h the helper handle 112 * @param h the helper handle
112 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 113 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
113 */ 114 */
114int 115enum GNUNET_GenericReturnValue
115GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h); 116GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
116 117
117 118
@@ -144,8 +145,10 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
144 * #GNUNET_NO if helper process died 145 * #GNUNET_NO if helper process died
145 * #GNUNET_SYSERR during GNUNET_HELPER_destroy 146 * #GNUNET_SYSERR during GNUNET_HELPER_destroy
146 */ 147 */
147typedef void (*GNUNET_HELPER_Continuation)(void *cls, 148typedef void
148 int result); 149(*GNUNET_HELPER_Continuation)(
150 void *cls,
151 enum GNUNET_GenericReturnValue result);
149 152
150 153
151/** 154/**
@@ -170,7 +173,7 @@ struct GNUNET_HELPER_SendHandle;
170struct GNUNET_HELPER_SendHandle * 173struct GNUNET_HELPER_SendHandle *
171GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 174GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
172 const struct GNUNET_MessageHeader *msg, 175 const struct GNUNET_MessageHeader *msg,
173 int can_drop, 176 bool can_drop,
174 GNUNET_HELPER_Continuation cont, 177 GNUNET_HELPER_Continuation cont,
175 void *cont_cls); 178 void *cont_cls);
176 179
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index 67327af5d..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
@@ -45,6 +45,7 @@
45#ifndef GNUNET_IDENTITY_SERVICE_H 45#ifndef GNUNET_IDENTITY_SERVICE_H
46#define GNUNET_IDENTITY_SERVICE_H 46#define GNUNET_IDENTITY_SERVICE_H
47 47
48#include "gnunet_common.h"
48#ifdef __cplusplus 49#ifdef __cplusplus
49extern "C" { 50extern "C" {
50#if 0 /* keep Emacsens' auto-indent happy */ 51#if 0 /* keep Emacsens' auto-indent happy */
@@ -61,20 +62,6 @@ extern "C" {
61 */ 62 */
62#define GNUNET_IDENTITY_VERSION 0x00000100 63#define GNUNET_IDENTITY_VERSION 0x00000100
63 64
64enum GNUNET_IDENTITY_KeyType
65{
66 /**
67 * The identity type. The value is the same as the
68 * PKEY record type.
69 */
70 GNUNET_IDENTITY_TYPE_ECDSA = 65536,
71
72 /**
73 * EDDSA identity. The value is the same as the EDKEY
74 * record type.
75 */
76 GNUNET_IDENTITY_TYPE_EDDSA = 65556
77};
78 65
79/** 66/**
80 * Handle to access the identity service. 67 * Handle to access the identity service.
@@ -87,89 +74,6 @@ struct GNUNET_IDENTITY_Handle;
87struct GNUNET_IDENTITY_Ego; 74struct GNUNET_IDENTITY_Ego;
88 75
89/** 76/**
90 * A private key for an identity as per LSD0001.
91 * Note that these types are NOT packed and MUST NOT be used in RPC
92 * messages. Use the respective serialization functions.
93 */
94struct GNUNET_IDENTITY_PrivateKey
95{
96 /**
97 * Type of public key.
98 * Defined by the GNS zone type value.
99 * In NBO.
100 */
101 uint32_t type;
102
103 union
104 {
105 /**
106 * An ECDSA identity key.
107 */
108 struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key;
109
110 /**
111 * AN EdDSA identtiy key
112 */
113 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key;
114 };
115};
116
117
118/**
119 * An identity key as per LSD0001.
120 */
121struct GNUNET_IDENTITY_PublicKey
122{
123 /**
124 * Type of public key.
125 * Defined by the GNS zone type value.
126 * In NBO.
127 */
128 uint32_t type;
129
130 union
131 {
132 /**
133 * An ECDSA identity key.
134 */
135 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key;
136
137 /**
138 * AN EdDSA identtiy key
139 */
140 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key;
141 };
142};
143
144
145/**
146 * An identity signature as per LSD0001.
147 */
148struct GNUNET_IDENTITY_Signature
149{
150 /**
151 * Type of signature.
152 * Defined by the GNS zone type value.
153 * In NBO.
154 */
155 uint32_t type;
156
157 union
158 {
159 /**
160 * An ECDSA signature
161 */
162 struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature;
163
164 /**
165 * AN EdDSA signature
166 */
167 struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
168 };
169};
170
171
172/**
173 * Handle for an operation with the identity service. 77 * Handle for an operation with the identity service.
174 */ 78 */
175struct GNUNET_IDENTITY_Operation; 79struct GNUNET_IDENTITY_Operation;
@@ -181,7 +85,7 @@ struct GNUNET_IDENTITY_Operation;
181 * @param ego the ego 85 * @param ego the ego
182 * @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
183 */ 87 */
184const struct GNUNET_IDENTITY_PrivateKey * 88const struct GNUNET_CRYPTO_PrivateKey *
185GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); 89GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego);
186 90
187 91
@@ -202,7 +106,17 @@ GNUNET_IDENTITY_ego_get_anonymous (void);
202 */ 106 */
203void 107void
204GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, 108GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
205 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);
206 120
207 121
208/** 122/**
@@ -325,7 +239,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
325typedef void 239typedef void
326(*GNUNET_IDENTITY_CreateContinuation) ( 240(*GNUNET_IDENTITY_CreateContinuation) (
327 void *cls, 241 void *cls,
328 const struct GNUNET_IDENTITY_PrivateKey *pk, 242 const struct GNUNET_CRYPTO_PrivateKey *pk,
329 enum GNUNET_ErrorCode ec); 243 enum GNUNET_ErrorCode ec);
330 244
331 245
@@ -343,8 +257,8 @@ typedef void
343struct GNUNET_IDENTITY_Operation * 257struct GNUNET_IDENTITY_Operation *
344GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, 258GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
345 const char *name, 259 const char *name,
346 const struct GNUNET_IDENTITY_PrivateKey *privkey, 260 const struct GNUNET_CRYPTO_PrivateKey *privkey,
347 enum GNUNET_IDENTITY_KeyType ktype, 261 enum GNUNET_CRYPTO_KeyType ktype,
348 GNUNET_IDENTITY_CreateContinuation cont, 262 GNUNET_IDENTITY_CreateContinuation cont,
349 void *cont_cls); 263 void *cont_cls);
350 264
@@ -395,433 +309,6 @@ void
395GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); 309GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
396 310
397 311
398/**
399 * Get the compacted length of a #GNUNET_IDENTITY_PublicKey.
400 * Compacted means that it returns the minimum number of bytes this
401 * key is long, as opposed to the union structure inside
402 * #GNUNET_IDENTITY_PublicKey.
403 * Useful for compact serializations.
404 *
405 * @param key the key.
406 * @return -1 on error, else the compacted length of the key.
407 */
408ssize_t
409GNUNET_IDENTITY_public_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
410
411/**
412 * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
413 * The buffer has to contain at least the compacted length of
414 * a #GNUNET_IDENTITY_PublicKey in bytes.
415 * If the buffer is too small, the function returns -1 as error.
416 * If the buffer does not contain a valid key, it returns -2 as error.
417 *
418 * @param buffer the buffer
419 * @param len the length of buffer
420 * @param key the key
421 * @param the amount of bytes read from the buffer
422 * @return GNUNET_SYSERR on error
423 */
424enum GNUNET_GenericReturnValue
425GNUNET_IDENTITY_read_public_key_from_buffer (const void *buffer,
426 size_t len,
427 struct
428 GNUNET_IDENTITY_PublicKey *key,
429 size_t *read);
430
431/**
432 * Get the compacted length of a #GNUNET_IDENTITY_PrivateKey.
433 * Compacted means that it returns the minimum number of bytes this
434 * key is long, as opposed to the union structure inside
435 * #GNUNET_IDENTITY_PrivateKey.
436 * Useful for compact serializations.
437 *
438 * @param key the key.
439 * @return -1 on error, else the compacted length of the key.
440 */
441ssize_t
442GNUNET_IDENTITY_private_key_get_length (const struct
443 GNUNET_IDENTITY_PrivateKey *key);
444
445
446/**
447 * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer.
448 * The buffer requires space for at least the compacted length of
449 * a #GNUNET_IDENTITY_PublicKey in bytes.
450 * If the buffer is too small, the function returns -1 as error.
451 * If the key is not valid, it returns -2 as error.
452 *
453 * @param key the key
454 * @param buffer the buffer
455 * @param len the length of buffer
456 * @return -1 or -2 on error, else the amount of bytes written to the buffer
457 */
458ssize_t
459GNUNET_IDENTITY_write_public_key_to_buffer (const struct
460 GNUNET_IDENTITY_PublicKey *key,
461 void*buffer,
462 size_t len);
463
464
465/**
466 * Reads a #GNUNET_IDENTITY_PrivateKey from a compact buffer.
467 * The buffer has to contain at least the compacted length of
468 * a #GNUNET_IDENTITY_PrivateKey in bytes.
469 * If the buffer is too small, the function returns GNUNET_SYSERR as error.
470 *
471 * @param buffer the buffer
472 * @param len the length of buffer
473 * @param key the key
474 * @param the amount of bytes read from the buffer
475 * @return GNUNET_SYSERR on error
476 */
477enum GNUNET_GenericReturnValue
478GNUNET_IDENTITY_read_private_key_from_buffer (const void*buffer,
479 size_t len,
480 struct
481 GNUNET_IDENTITY_PrivateKey *key,
482 size_t *read);
483
484
485/**
486 * Writes a #GNUNET_IDENTITY_PrivateKey to a compact buffer.
487 * The buffer requires space for at least the compacted length of
488 * a #GNUNET_IDENTITY_PrivateKey in bytes.
489 * If the buffer is too small, the function returns -1 as error.
490 * If the key is not valid, it returns -2 as error.
491 *
492 * @param key the key
493 * @param buffer the buffer
494 * @param len the length of buffer
495 * @return -1 or -2 on error, else the amount of bytes written to the buffer
496 */
497ssize_t
498GNUNET_IDENTITY_write_private_key_to_buffer (const struct
499 GNUNET_IDENTITY_PrivateKey *key,
500 void*buffer,
501 size_t len);
502
503
504/**
505 * Get the compacted length of a #GNUNET_IDENTITY_Signature.
506 * Compacted means that it returns the minimum number of bytes this
507 * signature is long, as opposed to the union structure inside
508 * #GNUNET_IDENTITY_Signature.
509 * Useful for compact serializations.
510 *
511 * @param sig the signature.
512 * @return -1 on error, else the compacted length of the signature.
513 */
514ssize_t
515GNUNET_IDENTITY_signature_get_length (const struct
516 GNUNET_IDENTITY_Signature *sig);
517
518
519/**
520 * Get the compacted length of a signature by type.
521 * Compacted means that it returns the minimum number of bytes this
522 * signature is long, as opposed to the union structure inside
523 * #GNUNET_IDENTITY_Signature.
524 * Useful for compact serializations.
525 *
526 * @param sig the signature.
527 * @return -1 on error, else the compacted length of the signature.
528 */
529ssize_t
530GNUNET_IDENTITY_signature_get_raw_length_by_type (const uint32_t type);
531
532
533
534/**
535 * Reads a #GNUNET_IDENTITY_Signature from a compact buffer.
536 * The buffer has to contain at least the compacted length of
537 * a #GNUNET_IDENTITY_Signature in bytes.
538 * If the buffer is too small, the function returns -1 as error.
539 * If the buffer does not contain a valid key, it returns -2 as error.
540 *
541 * @param sig the signature
542 * @param buffer the buffer
543 * @param len the length of buffer
544 * @return -1 or -2 on error, else the amount of bytes read from the buffer
545 */
546ssize_t
547GNUNET_IDENTITY_read_signature_from_buffer (struct
548 GNUNET_IDENTITY_Signature *sig,
549 const void*buffer,
550 size_t len);
551
552
553/**
554 * Writes a #GNUNET_IDENTITY_Signature to a compact buffer.
555 * The buffer requires space for at least the compacted length of
556 * a #GNUNET_IDENTITY_Signature in bytes.
557 * If the buffer is too small, the function returns -1 as error.
558 * If the key is not valid, it returns -2 as error.
559 *
560 * @param sig the signature
561 * @param buffer the buffer
562 * @param len the length of buffer
563 * @return -1 or -2 on error, else the amount of bytes written to the buffer
564 */
565ssize_t
566GNUNET_IDENTITY_write_signature_to_buffer (const struct
567 GNUNET_IDENTITY_Signature *sig,
568 void*buffer,
569 size_t len);
570
571
572/**
573 * @brief Sign a given block.
574 *
575 * The @a purpose data is the beginning of the data of which the signature is
576 * to be created. The `size` field in @a purpose must correctly indicate the
577 * number of bytes of the data structure, including its header. If possible,
578 * use #GNUNET_IDENTITY_sign() instead of this function.
579 *
580 * @param priv private key to use for the signing
581 * @param purpose what to sign (size, purpose)
582 * @param[out] sig where to write the signature
583 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
584 */
585enum GNUNET_GenericReturnValue
586GNUNET_IDENTITY_sign_ (const struct
587 GNUNET_IDENTITY_PrivateKey *priv,
588 const struct
589 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
590 struct GNUNET_IDENTITY_Signature *sig);
591
592/**
593 * @brief Sign a given block.
594 *
595 * The @a purpose data is the beginning of the data of which the signature is
596 * to be created. The `size` field in @a purpose must correctly indicate the
597 * number of bytes of the data structure, including its header.
598 * The signature payload and length depends on the key type.
599 *
600 * @param priv private key to use for the signing
601 * @param purpose what to sign (size, purpose)
602 * @param[out] sig where to write the signature
603 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
604 */
605enum GNUNET_GenericReturnValue
606GNUNET_IDENTITY_sign_raw_ (const struct
607 GNUNET_IDENTITY_PrivateKey *priv,
608 const struct
609 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
610 unsigned char *sig);
611
612
613/**
614 * @brief Sign a given block with #GNUNET_IDENTITY_PrivateKey.
615 *
616 * The @a ps data must be a fixed-size struct for which the signature is to be
617 * created. The `size` field in @a ps->purpose must correctly indicate the
618 * number of bytes of the data structure, including its header.
619 *
620 * @param priv private key to use for the signing
621 * @param ps packed struct with what to sign, MUST begin with a purpose
622 * @param[out] sig where to write the signature
623 */
624#define GNUNET_IDENTITY_sign(priv,ps,sig) do { \
625 /* check size is set correctly */ \
626 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
627 /* check 'ps' begins with the purpose */ \
628 GNUNET_static_assert (((void*) (ps)) == \
629 ((void*) &(ps)->purpose)); \
630 GNUNET_assert (GNUNET_OK == \
631 GNUNET_IDENTITY_sign_ (priv, \
632 &(ps)->purpose, \
633 sig)); \
634} while (0)
635
636
637/**
638 * @brief Verify a given signature.
639 *
640 * The @a validate data is the beginning of the data of which the signature
641 * is to be verified. The `size` field in @a validate must correctly indicate
642 * the number of bytes of the data structure, including its header. If @a
643 * purpose does not match the purpose given in @a validate (the latter must be
644 * in big endian), signature verification fails. If possible,
645 * use #GNUNET_IDENTITY_signature_verify() instead of this function (only if @a validate
646 * is not fixed-size, you must use this function directly).
647 *
648 * @param purpose what is the purpose that the signature should have?
649 * @param validate block to validate (size, purpose, data)
650 * @param sig signature that is being validated
651 * @param pub public key of the signer
652 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
653 */
654enum GNUNET_GenericReturnValue
655GNUNET_IDENTITY_signature_verify_ (uint32_t purpose,
656 const struct
657 GNUNET_CRYPTO_EccSignaturePurpose *validate,
658 const struct GNUNET_IDENTITY_Signature *sig,
659 const struct
660 GNUNET_IDENTITY_PublicKey *pub);
661
662/**
663 * @brief Verify a given signature.
664 *
665 * The @a validate data is the beginning of the data of which the signature
666 * is to be verified. The `size` field in @a validate must correctly indicate
667 * the number of bytes of the data structure, including its header. If @a
668 * purpose does not match the purpose given in @a validate (the latter must be
669 * in big endian), signature verification fails.
670 *
671 * @param purpose what is the purpose that the signature should have?
672 * @param validate block to validate (size, purpose, data)
673 * @param sig signature that is being validated
674 * @param pub public key of the signer
675 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
676 */
677enum GNUNET_GenericReturnValue
678GNUNET_IDENTITY_signature_verify_raw_ (uint32_t purpose,
679 const struct
680 GNUNET_CRYPTO_EccSignaturePurpose *
681 validate,
682 const unsigned char *sig,
683 const struct
684 GNUNET_IDENTITY_PublicKey *pub);
685
686
687/**
688 * @brief Verify a given signature with #GNUNET_IDENTITY_PublicKey.
689 *
690 * The @a ps data must be a fixed-size struct for which the signature is to be
691 * created. The `size` field in @a ps->purpose must correctly indicate the
692 * number of bytes of the data structure, including its header.
693 *
694 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
695 * (except in host byte order)
696 * @param ps packed struct with what to sign, MUST begin with a purpose
697 * @param sig where to read the signature from
698 * @param pub public key to use for the verifying
699 */
700#define GNUNET_IDENTITY_signature_verify(purp,ps,sig,pub) ({ \
701 /* check size is set correctly */ \
702 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
703 /* check 'ps' begins with the purpose */ \
704 GNUNET_static_assert (((void*) (ps)) == \
705 ((void*) &(ps)->purpose)); \
706 GNUNET_IDENTITY_signature_verify_ (purp, \
707 &(ps)->purpose, \
708 sig, \
709 pub); \
710 })
711
712
713/**
714 * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a
715 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
716 * using ecdh to derive a symmetric key.
717 *
718 * @param block the block to encrypt
719 * @param size the size of the @a block
720 * @param pub public key to use for ecdh
721 * @param ecc where to write the ecc public key
722 * @param result the output parameter in which to store the encrypted result
723 * can be the same or overlap with @c block
724 * @returns the size of the encrypted block, -1 for errors.
725 * Due to the use of CFB and therefore an effective stream cipher,
726 * this size should be the same as @c len.
727 */
728ssize_t
729GNUNET_IDENTITY_encrypt (const void *block,
730 size_t size,
731 const struct GNUNET_IDENTITY_PublicKey *pub,
732 struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
733 void *result);
734
735
736/**
737 * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given
738 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
739 *
740 * @param block the data to decrypt, encoded as returned by encrypt
741 * @param size the size of the @a block to decrypt
742 * @param priv private key to use for ecdh
743 * @param ecc the ecc public key
744 * @param result address to store the result at
745 * can be the same or overlap with @c block
746 * @return -1 on failure, size of decrypted block on success.
747 * Due to the use of CFB and therefore an effective stream cipher,
748 * this size should be the same as @c size.
749 */
750ssize_t
751GNUNET_IDENTITY_decrypt (const void *block,
752 size_t size,
753 const struct
754 GNUNET_IDENTITY_PrivateKey *priv,
755 const struct
756 GNUNET_CRYPTO_EcdhePublicKey *ecc,
757 void *result);
758
759
760/**
761 * Creates a (Base32) string representation of the public key.
762 * The resulting string encodes a compacted representation of the key.
763 * See also #GNUNET_IDENTITY_key_get_length.
764 *
765 * @param key the key.
766 * @return the string representation of the key, or NULL on error.
767 */
768char *
769GNUNET_IDENTITY_public_key_to_string (const struct
770 GNUNET_IDENTITY_PublicKey *key);
771
772
773/**
774 * Creates a (Base32) string representation of the private key.
775 * The resulting string encodes a compacted representation of the key.
776 * See also #GNUNET_IDENTITY_key_get_length.
777 *
778 * @param key the key.
779 * @return the string representation of the key, or NULL on error.
780 */
781char *
782GNUNET_IDENTITY_private_key_to_string (const struct
783 GNUNET_IDENTITY_PrivateKey *key);
784
785
786/**
787 * Parses a (Base32) string representation of the public key.
788 * See also #GNUNET_IDENTITY_public_key_to_string.
789 *
790 * @param str the encoded key.
791 * @param key where to write the key.
792 * @return GNUNET_SYSERR on error.
793 */
794enum GNUNET_GenericReturnValue
795GNUNET_IDENTITY_public_key_from_string (const char*str,
796 struct GNUNET_IDENTITY_PublicKey *key);
797
798
799/**
800 * Parses a (Base32) string representation of the private key.
801 * See also #GNUNET_IDENTITY_private_key_to_string.
802 *
803 * @param str the encoded key.
804 * @param key where to write the key.
805 * @return GNUNET_SYSERR on error.
806 */
807enum GNUNET_GenericReturnValue
808GNUNET_IDENTITY_private_key_from_string (const char*str,
809 struct GNUNET_IDENTITY_PrivateKey *key);
810
811
812/**
813 * Retrieves the public key representation of a private key.
814 *
815 * @param privkey the private key.
816 * @param key the public key result.
817 * @return GNUNET_SYSERR on error.
818 */
819enum GNUNET_GenericReturnValue
820GNUNET_IDENTITY_key_get_public (const struct
821 GNUNET_IDENTITY_PrivateKey *privkey,
822 struct GNUNET_IDENTITY_PublicKey *key);
823
824
825/* ************* convenience API to lookup an ego ***************** */ 312/* ************* convenience API to lookup an ego ***************** */
826 313
827/** 314/**
@@ -874,7 +361,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
874typedef void 361typedef void
875(*GNUNET_IDENTITY_EgoSuffixCallback) ( 362(*GNUNET_IDENTITY_EgoSuffixCallback) (
876 void *cls, 363 void *cls,
877 const struct GNUNET_IDENTITY_PrivateKey *priv, 364 const struct GNUNET_CRYPTO_PrivateKey *priv,
878 const char *ego_name); 365 const char *ego_name);
879 366
880 367
@@ -897,11 +384,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup;
897 * @return handle to abort the operation 384 * @return handle to abort the operation
898 */ 385 */
899struct GNUNET_IDENTITY_EgoSuffixLookup * 386struct GNUNET_IDENTITY_EgoSuffixLookup *
900GNUNET_IDENTITY_ego_lookup_by_suffix (const struct 387GNUNET_IDENTITY_ego_lookup_by_suffix (
901 GNUNET_CONFIGURATION_Handle *cfg, 388 const struct GNUNET_CONFIGURATION_Handle *cfg,
902 const char *suffix, 389 const char *suffix,
903 GNUNET_IDENTITY_EgoSuffixCallback cb, 390 GNUNET_IDENTITY_EgoSuffixCallback cb,
904 void *cb_cls); 391 void *cb_cls);
905 392
906 393
907/** 394/**
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index a65293a7c..2059e127f 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -142,7 +142,13 @@ GNUNET_JSON_parse (const json_t *root,
142 142
143/** 143/**
144 * Frees all elements allocated during a #GNUNET_JSON_parse() 144 * Frees all elements allocated during a #GNUNET_JSON_parse()
145 * 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.
146 * 152 *
147 * @param spec specification of the parse operation 153 * @param spec specification of the parse operation
148 */ 154 */
@@ -246,7 +252,8 @@ GNUNET_JSON_spec_string (const char *name,
246 252
247 253
248/** 254/**
249 * JSON object. 255 * JSON object or array. Reference counter is
256 * incremented.
250 * 257 *
251 * @param name name of the JSON field 258 * @param name name of the JSON field
252 * @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
@@ -257,6 +264,28 @@ GNUNET_JSON_spec_json (const char *name,
257 264
258 265
259/** 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/**
260 * boolean. 289 * boolean.
261 * 290 *
262 * @param name name of the JSON field 291 * @param name name of the JSON field
@@ -268,6 +297,17 @@ GNUNET_JSON_spec_bool (const char *name,
268 297
269 298
270/** 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/**
271 * 8-bit integer. 311 * 8-bit integer.
272 * 312 *
273 * @param name name of the JSON field 313 * @param name name of the JSON field
@@ -390,6 +430,39 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
390 struct GNUNET_CRYPTO_RsaSignature **sig); 430 struct GNUNET_CRYPTO_RsaSignature **sig);
391 431
392 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 a 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
393/* ****************** Generic generator interface ******************* */ 466/* ****************** Generic generator interface ******************* */
394 467
395 468
@@ -681,6 +754,19 @@ GNUNET_JSON_pack_bool (const char *name,
681 754
682/** 755/**
683 * 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
684 * string. 770 * string.
685 * 771 *
686 * @param name name of the field to add to the object 772 * @param name name of the field to add to the object
@@ -913,6 +999,44 @@ GNUNET_JSON_pack_rsa_signature (const char *name,
913 const struct GNUNET_CRYPTO_RsaSignature *sig); 999 const struct GNUNET_CRYPTO_RsaSignature *sig);
914 1000
915 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
916#endif 1040#endif
917 1041
918/* end of gnunet_json_lib.h */ 1042/* end of gnunet_json_lib.h */
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index d798c975a..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--2022 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,20 +39,14 @@ extern "C" {
39#endif 39#endif
40#endif 40#endif
41 41
42#include "gnunet_common.h"
43#include "gnunet_configuration_lib.h"
44#include "gnunet_identity_service.h"
45#include "gnunet_protocols.h"
46#include "gnunet_scheduler_lib.h"
47#include "gnunet_time_lib.h"
48#include "gnunet_util_lib.h" 42#include "gnunet_util_lib.h"
49 43
50/** 44/**
51 * Version number of GNUnet Messenger API. 45 * Version number of GNUnet Messenger API.
52 * 46 *
53 * Current version of the Messenger: 0.1 47 * Current version of the Messenger: 0.4
54 */ 48 */
55#define GNUNET_MESSENGER_VERSION 0x00000001 49#define GNUNET_MESSENGER_VERSION 0x00000004
56 50
57/** 51/**
58 * Identifier of GNUnet MESSENGER Service. 52 * Identifier of GNUnet MESSENGER Service.
@@ -90,12 +84,12 @@ struct GNUNET_MESSENGER_RoomEntryRecord
90 /** 84 /**
91 * The hash identifying the port of the room. 85 * The hash identifying the port of the room.
92 */ 86 */
93 struct GNUNET_HashCode key; 87 struct GNUNET_HashCode key GNUNET_PACKED;
94}; 88};
95 89
96GNUNET_NETWORK_STRUCT_END 90GNUNET_NETWORK_STRUCT_END
97 91
98GNUNET_NETWORK_STRUCT_BEGIN 92 GNUNET_NETWORK_STRUCT_BEGIN
99 93
100/** 94/**
101 * A room details record specifies a custom name for a given room and 95 * A room details record specifies a custom name for a given room and
@@ -106,7 +100,7 @@ struct GNUNET_MESSENGER_RoomDetailsRecord
106 /** 100 /**
107 * The custom name for the room. 101 * The custom name for the room.
108 */ 102 */
109 char name [256]; 103 char name[256];
110 104
111 /** 105 /**
112 * The flags of the room. 106 * The flags of the room.
@@ -197,6 +191,26 @@ enum GNUNET_MESSENGER_MessageKind
197 GNUNET_MESSENGER_KIND_DELETE = 15, 191 GNUNET_MESSENGER_KIND_DELETE = 15,
198 192
199 /** 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 /**
200 * The unknown kind. The message contains an unknown body. 214 * The unknown kind. The message contains an unknown body.
201 */ 215 */
202 GNUNET_MESSENGER_KIND_UNKNOWN = 0 216 GNUNET_MESSENGER_KIND_UNKNOWN = 0
@@ -224,7 +238,7 @@ struct GNUNET_MESSENGER_MessageHeader
224 /** 238 /**
225 * The signature of the senders private key. 239 * The signature of the senders private key.
226 */ 240 */
227 struct GNUNET_IDENTITY_Signature signature; 241 struct GNUNET_CRYPTO_Signature signature;
228 242
229 /** 243 /**
230 * The timestamp of the message. 244 * The timestamp of the message.
@@ -256,11 +270,6 @@ struct GNUNET_MESSENGER_MessageHeader
256struct GNUNET_MESSENGER_MessageInfo 270struct GNUNET_MESSENGER_MessageInfo
257{ 271{
258 /** 272 /**
259 * The senders key to verify its signatures.
260 */
261 struct GNUNET_IDENTITY_PublicKey host_key;
262
263 /**
264 * The version of GNUnet Messenger API. 273 * The version of GNUnet Messenger API.
265 * 274 *
266 * 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
@@ -281,7 +290,7 @@ struct GNUNET_MESSENGER_MessageJoin
281 /** 290 /**
282 * The senders public key to verify its signatures. 291 * The senders public key to verify its signatures.
283 */ 292 */
284 struct GNUNET_IDENTITY_PublicKey key; 293 struct GNUNET_CRYPTO_PublicKey key;
285}; 294};
286 295
287/** 296/**
@@ -319,7 +328,7 @@ struct GNUNET_MESSENGER_MessageKey
319 /** 328 /**
320 * The new public key which replaces the current senders public key. 329 * The new public key which replaces the current senders public key.
321 */ 330 */
322 struct GNUNET_IDENTITY_PublicKey key; 331 struct GNUNET_CRYPTO_PublicKey key;
323}; 332};
324 333
325/** 334/**
@@ -498,6 +507,87 @@ struct GNUNET_MESSENGER_MessageDelete
498}; 507};
499 508
500/** 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/**
501 * The unified body of a #GNUNET_MESSENGER_Message. 591 * The unified body of a #GNUNET_MESSENGER_Message.
502 */ 592 */
503struct GNUNET_MESSENGER_MessageBody 593struct GNUNET_MESSENGER_MessageBody
@@ -519,6 +609,10 @@ struct GNUNET_MESSENGER_MessageBody
519 struct GNUNET_MESSENGER_MessageFile file; 609 struct GNUNET_MESSENGER_MessageFile file;
520 struct GNUNET_MESSENGER_MessagePrivate privacy; 610 struct GNUNET_MESSENGER_MessagePrivate privacy;
521 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;
522 }; 616 };
523}; 617};
524 618
@@ -539,7 +633,7 @@ struct GNUNET_MESSENGER_Message
539}; 633};
540 634
541/** 635/**
542 * Enum for the different supported flags used by message handling 636 * Enum for the different supported flags used by message handling.
543 * Compatible flags can be OR'ed together. 637 * Compatible flags can be OR'ed together.
544 */ 638 */
545enum GNUNET_MESSENGER_MessageFlags 639enum GNUNET_MESSENGER_MessageFlags
@@ -558,18 +652,44 @@ enum GNUNET_MESSENGER_MessageFlags
558 * 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.
559 */ 653 */
560 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,
561}; 675};
562 676
563/** 677/**
564 * 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.
565 * to load a valid EGO and the anonymous key pair will be used instead. 679 * Compatible flags can be OR'ed together.
566 *
567 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
568 * @param[in/out] handle Messenger handle
569 */ 680 */
570typedef void 681enum GNUNET_MESSENGER_ConnectionFlags
571(*GNUNET_MESSENGER_IdentityCallback) (void *cls, 682{
572 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};
573 693
574/** 694/**
575 * 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>.
@@ -580,6 +700,7 @@ typedef void
580 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect 700 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
581 * @param[in] room Room handle 701 * @param[in] room Room handle
582 * @param[in] sender Sender of message 702 * @param[in] sender Sender of message
703 * @param[in] recipient Recipient of message
583 * @param[in] message Newly received or sent message 704 * @param[in] message Newly received or sent message
584 * @param[in] hash Hash identifying the message 705 * @param[in] hash Hash identifying the message
585 * @param[in] flags Flags of the message 706 * @param[in] flags Flags of the message
@@ -587,8 +708,12 @@ typedef void
587typedef void 708typedef void
588(*GNUNET_MESSENGER_MessageCallback) (void *cls, 709(*GNUNET_MESSENGER_MessageCallback) (void *cls,
589 struct GNUNET_MESSENGER_Room *room, 710 struct GNUNET_MESSENGER_Room *room,
590 const struct GNUNET_MESSENGER_Contact *sender, 711 const struct
591 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,
592 const struct GNUNET_HashCode *hash, 717 const struct GNUNET_HashCode *hash,
593 enum GNUNET_MESSENGER_MessageFlags flags); 718 enum GNUNET_MESSENGER_MessageFlags flags);
594 719
@@ -600,19 +725,19 @@ typedef void
600 * @param[in] room Room handle 725 * @param[in] room Room handle
601 * @param[in] contact Contact handle 726 * @param[in] contact Contact handle
602 */ 727 */
603typedef int 728typedef enum GNUNET_GenericReturnValue
604(*GNUNET_MESSENGER_MemberCallback) (void* cls, 729(*GNUNET_MESSENGER_MemberCallback) (void *cls,
605 struct GNUNET_MESSENGER_Room *room, 730 struct GNUNET_MESSENGER_Room *room,
606 const struct GNUNET_MESSENGER_Contact *contact); 731 const struct
732 GNUNET_MESSENGER_Contact *contact);
607 733
608/** 734/**
609 * 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
610 * 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.
611 * 737 *
612 * @param[in] cfg Configuration to use 738 * @param[in] cfg Configuration to use
613 * @param[in] name Name to look up an ego or NULL to stay anonymous 739 * @param[in] name Name or NULL
614 * @param[in] identity_callback Function called when the EGO of the handle changes 740 * @param[in] key Private key or NULL to stay anonymous
615 * @param[in,out] identity_cls Closure for the <i>identity_callback</i> handler
616 * @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
617 * @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
618 * @return Messenger handle to use, NULL on error 743 * @return Messenger handle to use, NULL on error
@@ -620,26 +745,11 @@ typedef int
620struct GNUNET_MESSENGER_Handle* 745struct GNUNET_MESSENGER_Handle*
621GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 746GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
622 const char *name, 747 const char *name,
623 GNUNET_MESSENGER_IdentityCallback identity_callback, 748 const struct GNUNET_CRYPTO_PrivateKey *key,
624 void *identity_cls,
625 GNUNET_MESSENGER_MessageCallback msg_callback, 749 GNUNET_MESSENGER_MessageCallback msg_callback,
626 void *msg_cls); 750 void *msg_cls);
627 751
628/** 752/**
629 * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All
630 * participated rooms get informed about the key renewal. The handle requires a set name for this function to work and
631 * it needs to be unused by other egos.
632 *
633 * 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
634 * as default.
635 *
636 * @param[in,out] handle Messenger handle to use
637 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
638 */
639int
640GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle);
641
642/**
643 * 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.
644 * 754 *
645 * @param[in,out] handle Messenger handle to use 755 * @param[in,out] handle Messenger handle to use
@@ -657,15 +767,14 @@ const char*
657GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle); 767GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle);
658 768
659/** 769/**
660 * 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
661 * name to its new directory. If anything fails during this process the function returns #GNUNET_NO and the name for 771 * open rooms.
662 * the messenger won't change as specified.
663 * 772 *
664 * @param[in,out] handle Messenger handle to use 773 * @param[in,out] handle Messenger handle to use
665 * @param[in] name Name for the messenger to change to 774 * @param[in] name Name for the messenger to change to
666 * @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
667 */ 776 */
668int 777enum GNUNET_GenericReturnValue
669GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, 778GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
670 const char *name); 779 const char *name);
671 780
@@ -673,12 +782,25 @@ GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
673 * 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.
674 * 783 *
675 * @param[in] handle Messenger handle to use 784 * @param[in] handle Messenger handle to use
676 * @return Used ego's public key or NULL 785 * @return Used public key or NULL
677 */ 786 */
678const struct GNUNET_IDENTITY_PublicKey* 787const struct GNUNET_CRYPTO_PublicKey*
679GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle); 788GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
680 789
681/** 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/**
682 * 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
683 * 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>.
684 * 806 *
@@ -773,22 +895,48 @@ GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room,
773 const struct GNUNET_HashCode *hash); 895 const struct GNUNET_HashCode *hash);
774 896
775/** 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/**
776 * Get the name used by the <i>contact</i>. 912 * Get the name used by the <i>contact</i>.
777 * 913 *
778 * @param[in] contact Contact handle 914 * @param[in] contact Contact handle
779 * @return Name of <i>contact</i> or NULL 915 * @return Name of <i>contact</i> or NULL
780 */ 916 */
781const char* 917const char*
782GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact); 918GNUNET_MESSENGER_contact_get_name (const struct
919 GNUNET_MESSENGER_Contact *contact);
783 920
784/** 921/**
785 * 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.
786 * 923 *
787 * @param[in] contact Contact handle 924 * @param[in] contact Contact handle
788 * @return Public key of the ego used by <i>contact</i> or NULL 925 * @return Public key used by <i>contact</i> or NULL
926 */
927const struct GNUNET_CRYPTO_PublicKey*
928GNUNET_MESSENGER_contact_get_key (const struct
929 GNUNET_MESSENGER_Contact *contact);
930
931/**
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
789 */ 936 */
790const struct GNUNET_IDENTITY_PublicKey* 937size_t
791GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); 938GNUNET_MESSENGER_contact_get_id (const struct
939 GNUNET_MESSENGER_Contact *contact);
792 940
793/** 941/**
794 * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the 942 * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the
@@ -805,13 +953,29 @@ GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact
805 * 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.
806 * 954 *
807 * @param[in,out] room Room handle 955 * @param[in,out] room Room handle
808 * @param[in] message New message to send 956 * @param[in,out] message New message to send
809 * @param[in] contact Contact or NULL 957 * @param[in] contact Contact or NULL
810 */ 958 */
811void 959void
812GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, 960GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
813 const struct GNUNET_MESSENGER_Message *message, 961 const struct GNUNET_MESSENGER_Message *message,
814 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);
815 979
816/** 980/**
817 * 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>.
@@ -837,7 +1001,7 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room,
837int 1001int
838GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, 1002GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room,
839 GNUNET_MESSENGER_MemberCallback callback, 1003 GNUNET_MESSENGER_MemberCallback callback,
840 void* cls); 1004 void *cls);
841 1005
842#if 0 /* keep Emacsens' auto-indent happy */ 1006#if 0 /* keep Emacsens' auto-indent happy */
843{ 1007{
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 95e8c619b..b40693cdb 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -18,7 +18,8 @@
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__) 21#include "gnunet_common.h"
22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly." 23#error "Only <gnunet_util_lib.h> can be included directly."
23#endif 24#endif
24 25
@@ -60,9 +61,9 @@
60 * @return the MQ message 61 * @return the MQ message
61 */ 62 */
62#define GNUNET_MQ_msg_extra(mvar, esize, type) \ 63#define GNUNET_MQ_msg_extra(mvar, esize, type) \
63 GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \ 64 GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \
64 (esize) + sizeof *(mvar), \ 65 (esize) + sizeof *(mvar), \
65 (type)) 66 (type))
66 67
67/** 68/**
68 * Allocate a GNUNET_MQ_Envelope. 69 * Allocate a GNUNET_MQ_Envelope.
@@ -84,7 +85,7 @@
84 * @param type type of the message 85 * @param type type of the message
85 */ 86 */
86#define GNUNET_MQ_msg_header(type) \ 87#define GNUNET_MQ_msg_header(type) \
87 GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type) 88 GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type)
88 89
89 90
90/** 91/**
@@ -96,7 +97,8 @@
96 * @param type type of the message 97 * @param type type of the message
97 */ 98 */
98#define GNUNET_MQ_msg_header_extra(mh, esize, type) \ 99#define GNUNET_MQ_msg_header_extra(mh, esize, type) \
99 GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type) 100 GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type \
101 )
100 102
101 103
102/** 104/**
@@ -110,7 +112,7 @@
110 * @return a newly allocated 'struct GNUNET_MQ_Envelope *' 112 * @return a newly allocated 'struct GNUNET_MQ_Envelope *'
111 */ 113 */
112#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \ 114#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
113 ({ \ 115 ({ \
114 struct GNUNET_MQ_Envelope *_ev; \ 116 struct GNUNET_MQ_Envelope *_ev; \
115 _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \ 117 _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \
116 sizeof(*(mvar)), \ 118 sizeof(*(mvar)), \
@@ -130,8 +132,8 @@
130 * 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
131 */ 133 */
132#define GNUNET_MQ_extract_nested_mh(var) \ 134#define GNUNET_MQ_extract_nested_mh(var) \
133 GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \ 135 GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \
134 sizeof(*(var))) 136 sizeof(*(var)))
135 137
136 138
137/** 139/**
@@ -329,7 +331,7 @@ typedef void
329 * @return #GNUNET_OK if the message is well-formed, 331 * @return #GNUNET_OK if the message is well-formed,
330 * #GNUNET_SYSERR if not 332 * #GNUNET_SYSERR if not
331 */ 333 */
332typedef int 334typedef enum GNUNET_GenericReturnValue
333(*GNUNET_MQ_MessageValidationCallback) ( 335(*GNUNET_MQ_MessageValidationCallback) (
334 void *cls, 336 void *cls,
335 const struct GNUNET_MessageHeader *msg); 337 const struct GNUNET_MessageHeader *msg);
@@ -529,9 +531,9 @@ struct GNUNET_MQ_MessageHandler
529 * End-marker for the handlers array 531 * End-marker for the handlers array
530 */ 532 */
531#define GNUNET_MQ_handler_end() \ 533#define GNUNET_MQ_handler_end() \
532 { \ 534 { \
533 NULL, NULL, NULL, 0, 0 \ 535 NULL, NULL, NULL, 0, 0 \
534 } 536 }
535 537
536 538
537/** 539/**
@@ -563,7 +565,7 @@ struct GNUNET_MQ_MessageHandler
563 * @param ctx context for the callbacks 565 * @param ctx context for the callbacks
564 */ 566 */
565#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \ 567#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \
566 ({ \ 568 ({ \
567 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ 569 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
568 ((struct GNUNET_MQ_MessageHandler){ NULL, \ 570 ((struct GNUNET_MQ_MessageHandler){ NULL, \
569 (GNUNET_MQ_MessageCallback) _cb, \ 571 (GNUNET_MQ_MessageCallback) _cb, \
@@ -615,7 +617,7 @@ struct GNUNET_MQ_MessageHandler
615 * @param ctx context for the callbacks 617 * @param ctx context for the callbacks
616 */ 618 */
617#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \ 619#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \
618 __extension__ ({ \ 620 __extension__ ({ \
619 int (*_mv)(void *cls, const str *msg) = &check_ ## name; \ 621 int (*_mv)(void *cls, const str *msg) = &check_ ## name; \
620 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ 622 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
621 ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \ 623 ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \
@@ -638,17 +640,17 @@ struct GNUNET_MQ_MessageHandler
638 * the size, starting with a `struct GNUNET_MessageHeader` 640 * the size, starting with a `struct GNUNET_MessageHeader`
639 */ 641 */
640#define GNUNET_MQ_check_zero_termination(m) \ 642#define GNUNET_MQ_check_zero_termination(m) \
641 { \ 643 { \
642 const char *str = (const char *) &m[1]; \ 644 const char *str = (const char *) &m[1]; \
643 const struct GNUNET_MessageHeader *hdr = \ 645 const struct GNUNET_MessageHeader *hdr = \
644 (const struct GNUNET_MessageHeader *) m; \ 646 (const struct GNUNET_MessageHeader *) m; \
645 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ 647 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \
646 if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \ 648 if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \
647 { \ 649 { \
648 GNUNET_break (0); \ 650 GNUNET_break (0); \
649 return GNUNET_NO; \ 651 return GNUNET_NO; \
650 } \ 652 } \
651 } 653 }
652 654
653 655
654/** 656/**
@@ -664,19 +666,19 @@ struct GNUNET_MQ_MessageHandler
664 * the size, starting with a `struct GNUNET_MessageHeader` 666 * the size, starting with a `struct GNUNET_MessageHeader`
665 */ 667 */
666#define GNUNET_MQ_check_boxed_message(m) \ 668#define GNUNET_MQ_check_boxed_message(m) \
667 { \ 669 { \
668 const struct GNUNET_MessageHeader *inbox = \ 670 const struct GNUNET_MessageHeader *inbox = \
669 (const struct GNUNET_MessageHeader *) &m[1]; \ 671 (const struct GNUNET_MessageHeader *) &m[1]; \
670 const struct GNUNET_MessageHeader *hdr = \ 672 const struct GNUNET_MessageHeader *hdr = \
671 (const struct GNUNET_MessageHeader *) m; \ 673 (const struct GNUNET_MessageHeader *) m; \
672 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ 674 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \
673 if ((slen < sizeof(struct GNUNET_MessageHeader)) || \ 675 if ((slen < sizeof(struct GNUNET_MessageHeader)) || \
674 (slen != ntohs (inbox->size))) \ 676 (slen != ntohs (inbox->size))) \
675 { \ 677 { \
676 GNUNET_break (0); \ 678 GNUNET_break (0); \
677 return GNUNET_NO; \ 679 return GNUNET_NO; \
678 } \ 680 } \
679 } 681 }
680 682
681 683
682/** 684/**
@@ -691,7 +693,7 @@ struct GNUNET_MQ_MessageHandler
691 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched, 693 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched,
692 * #GNUNET_SYSERR if message was rejected by check function 694 * #GNUNET_SYSERR if message was rejected by check function
693 */ 695 */
694int 696enum GNUNET_GenericReturnValue
695GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, 697GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
696 const struct GNUNET_MessageHeader *mh); 698 const struct GNUNET_MessageHeader *mh);
697 699
@@ -994,7 +996,7 @@ GNUNET_MQ_destroy_notify_cancel (
994 * Call the message message handler that was registered 996 * Call the message message handler that was registered
995 * 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.
996 * 998 *
997 * This function is indented to be used for the implementation 999 * This function is intended to be used for the implementation
998 * of message queues. 1000 * of message queues.
999 * 1001 *
1000 * @param mq message queue with the handlers 1002 * @param mq message queue with the handlers
diff --git a/src/include/gnunet_mst_lib.h b/src/include/gnunet_mst_lib.h
index af2dd3353..5b848bbd6 100644
--- a/src/include/gnunet_mst_lib.h
+++ b/src/include/gnunet_mst_lib.h
@@ -127,7 +127,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
127 * #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
128 * #GNUNET_SYSERR if the data stream is corrupt 128 * #GNUNET_SYSERR if the data stream is corrupt
129 */ 129 */
130int 130enum GNUNET_GenericReturnValue
131GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, 131GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
132 struct GNUNET_NETWORK_Handle *sock, 132 struct GNUNET_NETWORK_Handle *sock,
133 int purge, 133 int purge,
@@ -145,7 +145,7 @@ GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
145 * #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
146 * #GNUNET_SYSERR if the data stream is corrupt 146 * #GNUNET_SYSERR if the data stream is corrupt
147 */ 147 */
148int 148enum GNUNET_GenericReturnValue
149GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst, 149GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst,
150 int one_shot); 150 int one_shot);
151 151
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h
deleted file mode 100644
index 283b2f7e6..000000000
--- a/src/include/gnunet_my_lib.h
+++ /dev/null
@@ -1,511 +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 * @addtogroup lib_extra
22 * @{
23 *
24 * @author Christian Grothoff
25 * @author Christophe Genevey
26 * @author Martin Schanzenbach
27 *
28 * @file
29 * Helper library to access a MySQL database
30 *
31 * @defgroup mysql MySQL library
32 * Helper library to access a MySQL database.
33 * @{
34 */
35#ifndef GNUNET_MY_LIB_H
36#define GNUNET_MY_LIB_H
37
38
39#include "gnunet_util_lib.h"
40#include "gnunet_mysql_lib.h"
41#include <mysql/mysql.h>
42
43#ifndef MYSQL_BOOL
44#error "You need to define MYSQL_BOOL. See (or include) gnunet_mysql_compat.h"
45#endif
46
47#ifdef __cplusplus
48extern "C"
49{
50#if 0 /* keep Emacsens' auto-indent happy */
51}
52#endif
53#endif
54
55
56/**
57 * Information we pass to #GNUNET_MY_exec_prepared() to
58 * initialize the arguments of the prepared statement.
59 */
60struct GNUNET_MY_QueryParam;
61
62
63/**
64 * Function called to convert input argument into SQL parameters.
65 *
66 * @param cls closure
67 * @param pq data about the query
68 * @param qbind array of parameters to initialize
69 * @return -1 on error
70 */
71typedef int
72(*GNUNET_MY_QueryConverter)(void *cls,
73 const struct GNUNET_MY_QueryParam *qp,
74 MYSQL_BIND *qbind);
75
76
77/**
78 * Function called to cleanup result data.
79 *
80 * @param cls closure
81 * @param rs spec to clean up
82 */
83typedef void
84(*GNUNET_MY_QueryCleanup)(void *cls,
85 MYSQL_BIND *qbind);
86/**
87 * Information we pass to #GNUNET_MY_exec_prepared() to
88 * initialize the arguments of the prepared statement.
89 */
90
91
92struct GNUNET_MY_QueryParam
93{
94 /**
95 * Function to call for the type conversion.
96 */
97 GNUNET_MY_QueryConverter conv;
98
99 /**
100 * Function to call for cleaning up the query. Can be NULL.
101 */
102 GNUNET_MY_QueryCleanup cleaner;
103
104 /**
105 * Closure for @e conv.
106 */
107 void *conv_cls;
108
109 /**
110 * Number of arguments the @a conv converter expects to initialize.
111 */
112 unsigned int num_params;
113
114 /**
115 * Information to pass to @e conv.
116 */
117 const void *data;
118
119 /**
120 * Information to pass to @e conv. Size of @a data.
121 */
122 unsigned long data_len;
123};
124
125/**
126 * End of query parameter specification.
127 *
128 * @return array last entry for the result specification to use
129 */
130#define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
131
132
133/**
134 * Generate query parameter for a buffer @a ptr of
135 * @a ptr_size bytes.FG
136 *
137 * @param ptr pointer to the query parameter to pass
138 * @param ptr_size number of bytes in @a ptr
139 */
140struct GNUNET_MY_QueryParam
141GNUNET_MY_query_param_fixed_size (const void *ptr,
142 size_t ptr_size);
143
144
145/**
146 * Run a prepared SELECT statement.
147 *
148 * @param mc mysql context
149 * @param sh handle to SELECT statement
150 * @param params parameters to the statement
151 * @return TBD
152 */
153int
154GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
155 struct GNUNET_MYSQL_StatementHandle *sh,
156 struct GNUNET_MY_QueryParam *params);
157
158
159/**
160 * Information we pass to #GNUNET_MY_extract_result() to
161 * initialize the arguments of the prepared statement.
162 */
163struct GNUNET_MY_ResultParam;
164
165/**
166 * Information we pass to #GNUNET_MY_extract_result() to
167 * initialize the arguments of the prepared statement.
168 */
169struct GNUNET_MY_ResultSpec;
170
171/**
172 * Function called to convert input argument into SQL parameters.
173 *
174 * @param cls closure
175 * @param[in,out] rs
176 * @param stmt the mysql statement that is being run
177 * @param column the column that is being processed
178 * @param[out] results
179 * @return -1 on error
180 */
181typedef int
182(*GNUNET_MY_ResultConverter)(void *cls,
183 struct GNUNET_MY_ResultSpec *rs,
184 MYSQL_STMT *stmt,
185 unsigned int column,
186 MYSQL_BIND *results);
187
188/**
189 * Function called to cleanup result data.
190 *
191 * @param cls closure
192 * @param rs spec to clean up
193 */
194typedef void
195(*GNUNET_MY_ResultCleanup)(void *cls,
196 struct GNUNET_MY_ResultSpec *rs);
197
198
199/**
200 * Information we pass to #GNUNET_MY_extract_result() to
201 * initialize the arguments of the prepared statement.
202 */
203struct GNUNET_MY_ResultSpec
204{
205 /**
206 * Function to call to initialize the MYSQL_BIND array.
207 */
208 GNUNET_MY_ResultConverter pre_conv;
209
210 /**
211 * Function to call for converting the result. Can be NULL.
212 */
213 GNUNET_MY_ResultConverter post_conv;
214
215 /**
216 * Function to call for cleaning up the result. Can be NULL.
217 */
218 GNUNET_MY_ResultCleanup cleaner;
219
220 /**
221 * Closure for @e conv.
222 */
223 void *conv_cls;
224
225 /**
226 * Destination for the data.
227 */
228 void *dst;
229
230 /**
231 * Allowed size for the data, 0 for variable-size
232 * (in this case, the type of @e dst is a `void **`
233 * and we need to allocate a buffer of the right size).
234 */
235 size_t dst_size;
236
237 /**
238 * Where to store actual size of the result.
239 */
240 size_t *result_size;
241
242 /**
243 * How many fields does this result specification occupy
244 * in the result returned by MySQL.
245 */
246 unsigned int num_fields;
247
248 /**
249 * Location where we temporarily store the output buffer
250 * length from MySQL. Internal to libgnunetmy.
251 */
252 unsigned long mysql_bind_output_length;
253
254 /**
255 * Memory for MySQL to notify us about NULL values.
256 */
257 MYSQL_BOOL is_null;
258};
259
260
261/**
262 * End of result speceter specification.
263 *
264 * @return array last entry for the result specification to use
265 */
266#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
267
268
269/**
270 * Obtain fixed size result of @a ptr_size bytes from
271 * MySQL, store in already allocated buffer at @a ptr.
272 *
273 * @spec ptr where to write the result
274 * @param ptr_size number of bytes available at @a ptr
275 */
276struct GNUNET_MY_ResultSpec
277GNUNET_MY_result_spec_fixed_size (void *ptr,
278 size_t ptr_size);
279
280/**
281 * Generate query parameter for a string
282 *
283 * @param ptr pointer to the string query parameter to pass
284 */
285struct GNUNET_MY_QueryParam
286GNUNET_MY_query_param_string (const char *ptr);
287
288/**
289 * Generate fixed-size query parameter with size determined
290 * by variable type.
291 *
292 * @param x pointer to the query parameter to pass
293 */
294#define GNUNET_MY_query_param_auto_from_type( \
295 x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
296
297/**
298 * Generate query parameter for an RSA public key. The
299 * database must contain a BLOB type in the respective position.
300 *
301 * @param x the query parameter to pass
302 * @return array entry for the query parameters to use
303 */
304struct GNUNET_MY_QueryParam
305GNUNET_MY_query_param_rsa_public_key (const struct
306 GNUNET_CRYPTO_RsaPublicKey *x);
307
308/**
309 * Generate query parameter for an RSA signature. The
310 * database must contain a BLOB type in the respective position
311 *
312 *@param x the query parameter to pass
313 *@return array entry for the query parameters to use
314 */
315struct GNUNET_MY_QueryParam
316GNUNET_MY_query_param_rsa_signature (const struct
317 GNUNET_CRYPTO_RsaSignature *x);
318
319/**
320 * Generate query parameter for an absolute time value.
321 * The database must store a 64-bit integer.
322 *
323 *@param x pointer to the query parameter to pass
324 *@return array entry for the query parameters to use
325 */
326struct GNUNET_MY_QueryParam
327GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
328
329
330/**
331 * Generate query parameter for an absolute time value.
332 * The database must store a 64-bit integer.
333 *
334 *@param x pointer to the query parameter to pass
335 */
336struct GNUNET_MY_QueryParam
337GNUNET_MY_query_param_absolute_time_nbo (const struct
338 GNUNET_TIME_AbsoluteNBO *x);
339
340/**
341 * Generate query parameter for an uint16_t in host byte order.
342 *
343 * @param x pointer to the query parameter to pass
344 */
345struct GNUNET_MY_QueryParam
346GNUNET_MY_query_param_uint16 (const uint16_t *x);
347
348/**
349 * Generate query parameter for an uint32_t in host byte order
350 *
351 * @param x pointer to the query parameter to pass
352 */
353struct GNUNET_MY_QueryParam
354GNUNET_MY_query_param_uint32 (const uint32_t *x);
355
356/**
357 * Generate query parameter for an uint64_t in host byte order
358 *
359 * @param x pointer to the query parameter to pass
360 */
361struct GNUNET_MY_QueryParam
362GNUNET_MY_query_param_uint64 (const uint64_t *x);
363
364/**
365 * We expect a fixed-size result, with size determined by the type of `* dst`
366 *
367 * @spec name name of the field in the table
368 * @spec dst point to where to store the result, type fits expected result size
369 * @return array entry for the result specification to use
370 */
371#define GNUNET_MY_result_spec_auto_from_type( \
372 dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
373
374
375/**
376 * Variable-size result expected
377 *
378 * @param[out] dst where to store the result, allocated
379 * @param[out] ptr_size where to store the size of @a dst
380 * @return array entry for the result specification to use
381 */
382struct GNUNET_MY_ResultSpec
383GNUNET_MY_result_spec_variable_size (void **dst,
384 size_t *ptr_size);
385
386/**
387 * RSA public key expected
388 *
389 * @param name name of the field in the table
390 * @param[out] rsa where to store the result
391 * @return array entry for the result specification to use
392 */
393struct GNUNET_MY_ResultSpec
394GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
395
396
397/**
398 * RSA signature expected.
399 *
400 * @param[out] sig where to store the result;
401 * @return array entry for the result specification to use
402 */
403struct GNUNET_MY_ResultSpec
404GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
405
406/**
407 * 0- terminated string exprected.
408 *
409 * @param[out] dst where to store the result, allocated
410 * @return array entry for the result specification to use
411 */
412struct GNUNET_MY_ResultSpec
413GNUNET_MY_result_spec_string (char **dst);
414
415/**
416 * Absolute time expected
417 *
418 * @param name name of the field in the table
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 (struct GNUNET_TIME_Absolute *at);
424
425/**
426 * Absolute time in network byte order expected
427 *
428 * @param[out] at where to store the result
429 * @return array entry for the result specification to use
430 */
431struct GNUNET_MY_ResultSpec
432GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
433
434/**
435 * uint16_t expected
436 *
437 * @param[out] u16 where to store the result
438 * @return array entry for the result specification to use
439 */
440struct GNUNET_MY_ResultSpec
441GNUNET_MY_result_spec_uint16 (uint16_t *u16);
442
443/**
444 * uint32_t expected
445 *
446 * @param[out] u32 where to store the result
447 * @return array entry for the result specification to use
448 */
449struct GNUNET_MY_ResultSpec
450GNUNET_MY_result_spec_uint32 (uint32_t *u32);
451
452/**
453 * uint64_t expected.
454 *
455 * @param[out] u64 where to store the result
456 * @return array entry for the result specification to use
457 */
458struct GNUNET_MY_ResultSpec
459GNUNET_MY_result_spec_uint64 (uint64_t *u64);
460
461
462/**
463 * Extract results from a query result according to the given
464 * specification. Always fetches the next row.
465 *
466 * @param sh statement that returned results
467 * @param rs specification to extract for
468 * @return
469 * #GNUNET_YES if all results could be extracted
470 * #GNUNET_NO if there is no more data in the result set
471 * #GNUNET_SYSERR if a result was invalid
472 */
473int
474GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
475 struct GNUNET_MY_ResultSpec *specs);
476
477
478/**
479 * Free all memory that was allocated in @a qp during
480 * #GNUNET_MY_exect_prepared().
481 *
482 * @param qp query specification to clean up
483 * @param qbind mysql query
484 */
485void
486GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
487 MYSQL_BIND *qbind);
488
489
490/**
491 * Free all memory that was allocated in @a rs during
492 * #GNUNET_MY_extract_result().
493 *
494 * @param rs reult specification to clean up
495 */
496void
497GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs);
498
499
500#if 0 /* keep Emacsens' auto-indent happy */
501{
502#endif
503#ifdef __cplusplus
504}
505#endif
506
507#endif
508
509/** @} */ /* end of group */
510
511/** @} */ /* end of group addition to lib_extra */
diff --git a/src/include/gnunet_mysql_compat.h b/src/include/gnunet_mysql_compat.h
deleted file mode 100644
index 9fb9db30f..000000000
--- a/src/include/gnunet_mysql_compat.h
+++ /dev/null
@@ -1,63 +0,0 @@
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 * @author Martin Schanzenbach
22 *
23 * @file
24 * MySQL/MariaDB compatibility insanity helper header
25 *
26 * @defgroup mysql MySQL library
27 * Helper library to access a MySQL database.
28 * @{
29 */
30#ifndef GNUNET_MYSQL_COMPAT_H
31#define GNUNET_MYSQL_COMPAT_H
32
33
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#ifndef LIBMARIADB
45#if MYSQL_VERSION_ID >= 80000
46#define MYSQL_BOOL bool
47#else
48#define MYSQL_BOOL my_bool /* MySQL < 8 wants this */
49#endif
50#else
51#define MYSQL_BOOL my_bool /* MariaDB still uses my_bool */
52#endif
53
54#if 0 /* keep Emacsens' auto-indent happy */
55{
56#endif
57#ifdef __cplusplus
58}
59#endif
60
61#endif
62
63/** @} */ /* end of group */
diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h
deleted file mode 100644
index 52be3ff11..000000000
--- a/src/include/gnunet_mysql_lib.h
+++ /dev/null
@@ -1,151 +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
34#include "gnunet_util_lib.h"
35#include <mysql/mysql.h>
36
37#ifdef __cplusplus
38extern "C"
39{
40#if 0 /* keep Emacsens' auto-indent happy */
41}
42#endif
43#endif
44
45/**
46 * Mysql context.
47 */
48struct GNUNET_MYSQL_Context;
49
50
51/**
52 * Handle for a prepared statement.
53 */
54struct GNUNET_MYSQL_StatementHandle;
55
56
57/**
58 * Type of a callback that will be called for each
59 * data set returned from MySQL.
60 *
61 * @param cls user-defined argument
62 * @param num_values number of elements in values
63 * @param values values returned by MySQL
64 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
65 */
66typedef int
67(*GNUNET_MYSQL_DataProcessor) (void *cls,
68 unsigned int num_values,
69 MYSQL_BIND *values);
70
71
72/**
73 * Create a mysql context.
74 *
75 * @param cfg configuration
76 * @param section configuration section to use to get MySQL configuration options
77 * @return the mysql context
78 */
79struct GNUNET_MYSQL_Context *
80GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
81 const char *section);
82
83
84/**
85 * Destroy a mysql context. Also frees all associated prepared statements.
86 *
87 * @param mc context to destroy
88 */
89void
90GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc);
91
92
93/**
94 * Close database connection and all prepared statements (we got a DB
95 * error). The connection will automatically be re-opened and
96 * statements will be re-prepared if they are needed again later.
97 *
98 * @param mc mysql context
99 */
100void
101GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc);
102
103
104/**
105 * Get internal handle for a prepared statement. This function should rarely
106 * be used, and if, with caution! On failures during the interaction with
107 * the handle, you must call #GNUNET_MYSQL_statements_invalidate()!
108 *
109 * @param sh prepared statement to introspect
110 * @return MySQL statement handle, NULL on error
111 */
112MYSQL_STMT *
113GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh);
114
115
116/**
117 * Prepare a statement. Prepared statements are automatically discarded
118 * when the MySQL context is destroyed.
119 *
120 * @param mc mysql context
121 * @param query query text
122 * @return prepared statement, NULL on error
123 */
124struct GNUNET_MYSQL_StatementHandle *
125GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
126 const char *query);
127
128
129/**
130 * Run a SQL statement.
131 *
132 * @param mc mysql context
133 * @param sql SQL statement to run
134 * @return #GNUNET_OK on success
135 * #GNUNET_SYSERR if there was a problem
136 */
137int
138GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
139 const char *sql);
140
141
142#if 0 /* keep Emacsens' auto-indent happy */
143{
144#endif
145#ifdef __cplusplus
146}
147#endif
148
149#endif
150
151/** @} */ /* end of group */
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h
index f2bdf7cc6..b7bcc4eb6 100644
--- a/src/include/gnunet_namestore_plugin.h
+++ b/src/include/gnunet_namestore_plugin.h
@@ -53,6 +53,7 @@ extern "C"
53 * @param cls closure 53 * @param cls closure
54 * @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,
55 * 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)
56 * @param zone_key private key of the zone 57 * @param zone_key private key of the zone
57 * @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)
58 * @param rd_count number of entries in @a rd array 59 * @param rd_count number of entries in @a rd array
@@ -61,8 +62,9 @@ extern "C"
61typedef void 62typedef void
62(*GNUNET_NAMESTORE_RecordIterator) (void *cls, 63(*GNUNET_NAMESTORE_RecordIterator) (void *cls,
63 uint64_t serial, 64 uint64_t serial,
65 const char *editor_hint,
64 const struct 66 const struct
65 GNUNET_IDENTITY_PrivateKey *private_key, 67 GNUNET_CRYPTO_PrivateKey *private_key,
66 const char *label, 68 const char *label,
67 unsigned int rd_count, 69 unsigned int rd_count,
68 const struct GNUNET_GNSRECORD_Data *rd); 70 const struct GNUNET_GNSRECORD_Data *rd);
@@ -91,7 +93,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
91 */ 93 */
92 enum GNUNET_GenericReturnValue 94 enum GNUNET_GenericReturnValue
93 (*store_records)(void *cls, 95 (*store_records)(void *cls,
94 const struct GNUNET_IDENTITY_PrivateKey *zone, 96 const struct GNUNET_CRYPTO_PrivateKey *zone,
95 const char *label, 97 const char *label,
96 unsigned int rd_count, 98 unsigned int rd_count,
97 const struct GNUNET_GNSRECORD_Data *rd); 99 const struct GNUNET_GNSRECORD_Data *rd);
@@ -108,7 +110,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
108 */ 110 */
109 enum GNUNET_GenericReturnValue 111 enum GNUNET_GenericReturnValue
110 (*lookup_records)(void *cls, 112 (*lookup_records)(void *cls,
111 const struct GNUNET_IDENTITY_PrivateKey *zone, 113 const struct GNUNET_CRYPTO_PrivateKey *zone,
112 const char *label, 114 const char *label,
113 GNUNET_NAMESTORE_RecordIterator iter, 115 GNUNET_NAMESTORE_RecordIterator iter,
114 void *iter_cls); 116 void *iter_cls);
@@ -130,7 +132,7 @@ struct GNUNET_NAMESTORE_PluginFunctions
130 */ 132 */
131 enum GNUNET_GenericReturnValue 133 enum GNUNET_GenericReturnValue
132 (*iterate_records)(void *cls, 134 (*iterate_records)(void *cls,
133 const struct GNUNET_IDENTITY_PrivateKey *zone, 135 const struct GNUNET_CRYPTO_PrivateKey *zone,
134 uint64_t serial, 136 uint64_t serial,
135 uint64_t limit, 137 uint64_t limit,
136 GNUNET_NAMESTORE_RecordIterator iter, 138 GNUNET_NAMESTORE_RecordIterator iter,
@@ -150,61 +152,55 @@ struct GNUNET_NAMESTORE_PluginFunctions
150 */ 152 */
151 enum GNUNET_GenericReturnValue 153 enum GNUNET_GenericReturnValue
152 (*zone_to_name)(void *cls, 154 (*zone_to_name)(void *cls,
153 const struct GNUNET_IDENTITY_PrivateKey *zone, 155 const struct GNUNET_CRYPTO_PrivateKey *zone,
154 const struct GNUNET_IDENTITY_PublicKey *value_zone, 156 const struct GNUNET_CRYPTO_PublicKey *value_zone,
155 GNUNET_NAMESTORE_RecordIterator iter, 157 GNUNET_NAMESTORE_RecordIterator iter,
156 void *iter_cls); 158 void *iter_cls);
157 159
158 /** Transaction-based API draft **/ 160 /** Transaction-based API draft **/
159 161
160 /** 162 /**
161 * Start a transaction in the database 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).
162 * 166 *
163 * @param cls closure (internal context for the plugin) 167 * @param cls closure (internal context for the plugin)
164 * @param emsg message. On error, string will be allocated and must be freed. 168 * @param zone private key of the zone
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 169 * @param editor_hint the new value for the advisory lock field
166 */ 170 * @param label name of the record in the zone
167 enum GNUNET_GenericReturnValue 171 * @param iter function to call with the result
168 (*transaction_begin)(void *cls, char **emsg); 172 * @param iter_cls closure for @a iter
169 173 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
170 /**
171 * Abort and roll back a transaction in the database
172 *
173 * @param cls closure (internal context for the plugin)
174 * @param emsg message. On error, string will be allocated and must be freed.
175 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
176 */
177 enum GNUNET_GenericReturnValue
178 (*transaction_rollback)(void *cls, char **emsg);
179
180 /**
181 * Commit a transaction in the database
182 *
183 * @param cls closure (internal context for the plugin)
184 * @param emsg message. On error, string will be allocated and must be freed.
185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
186 */ 174 */
187 enum GNUNET_GenericReturnValue 175 enum GNUNET_GenericReturnValue
188 (*transaction_commit)(void *cls, char **emsg); 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);
189 182
190 /** 183 /**
191 * Edit records in the datastore for which we are the authority. 184 * This clears the editor hint, unless it does not match the
192 * Should be called within a transaction (after begin) and maps 185 * given editor hint, in which case this is a NOP.
193 * to a SELECT ... FOR UPDATE in PQ. 186 * If a replacement hint is given, it hint is not cleared, but
187 * set to the replacement.
194 * 188 *
195 * @param cls closure (internal context for the plugin) 189 * @param cls closure (internal context for the plugin)
196 * @param zone private key of the zone 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
197 * @param label name of the record in the zone 193 * @param label name of the record in the zone
198 * @param iter function to call with the result 194 * @param iter function to call with the result
199 * @param iter_cls closure for @a iter 195 * @param iter_cls closure for @a iter
200 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 196 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
201 */ 197 */
202 enum GNUNET_GenericReturnValue 198 enum GNUNET_GenericReturnValue
203 (*edit_records)(void *cls, 199 (*clear_editor_hint)(void *cls,
204 const struct GNUNET_IDENTITY_PrivateKey *zone, 200 const char *editor_hint,
205 const char *label, 201 const char *editor_hint_replacement,
206 GNUNET_NAMESTORE_RecordIterator iter, 202 const struct GNUNET_CRYPTO_PrivateKey *zone,
207 void *iter_cls); 203 const char *label);
208 204
209 /** 205 /**
210 * Setup the database. 206 * Setup the database.
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index b93a345c7..0f9be8b10 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -44,9 +44,7 @@
44 44
45#include "gnunet_error_codes.h" 45#include "gnunet_error_codes.h"
46#include "gnunet_util_lib.h" 46#include "gnunet_util_lib.h"
47#include "gnunet_block_lib.h"
48#include "gnunet_gnsrecord_lib.h" 47#include "gnunet_gnsrecord_lib.h"
49#include "gnunet_identity_service.h"
50 48
51#ifdef __cplusplus 49#ifdef __cplusplus
52extern "C" 50extern "C"
@@ -142,6 +140,9 @@ typedef void
142 * 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
143 * monitors do keep up. 141 * monitors do keep up.
144 * 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 *
145 * @param h handle to the namestore 146 * @param h handle to the namestore
146 * @param pkey private key of the zone 147 * @param pkey private key of the zone
147 * @param label name that is being mapped 148 * @param label name that is being mapped
@@ -152,13 +153,13 @@ typedef void
152 * @return handle to abort the request 153 * @return handle to abort the request
153 */ 154 */
154struct GNUNET_NAMESTORE_QueueEntry * 155struct GNUNET_NAMESTORE_QueueEntry *
155GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, 156GNUNET_NAMESTORE_record_set_store (struct GNUNET_NAMESTORE_Handle *h,
156 const struct GNUNET_IDENTITY_PrivateKey *pkey, 157 const struct GNUNET_CRYPTO_PrivateKey *pkey,
157 const char *label, 158 const char *label,
158 unsigned int rd_count, 159 unsigned int rd_count,
159 const struct GNUNET_GNSRECORD_Data *rd, 160 const struct GNUNET_GNSRECORD_Data *rd,
160 GNUNET_NAMESTORE_ContinuationWithStatus cont, 161 GNUNET_NAMESTORE_ContinuationWithStatus cont,
161 void *cont_cls); 162 void *cont_cls);
162 163
163/** 164/**
164 * Store one or more record sets in the namestore. If any item is already present, 165 * Store one or more record sets in the namestore. If any item is already present,
@@ -175,6 +176,9 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
175 * cause @a cont to be called immediately before the commit and before 176 * cause @a cont to be called immediately before the commit and before
176 * notification of monitors. 177 * notification of monitors.
177 * 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 *
178 * @param h handle to the namestore 182 * @param h handle to the namestore
179 * @param pkey private key of the zone 183 * @param pkey private key of the zone
180 * @param rd_set_count the number of record sets 184 * @param rd_set_count the number of record sets
@@ -185,9 +189,9 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
185 * @return handle to abort the request 189 * @return handle to abort the request
186 */ 190 */
187struct GNUNET_NAMESTORE_QueueEntry * 191struct GNUNET_NAMESTORE_QueueEntry *
188GNUNET_NAMESTORE_records_store2 ( 192GNUNET_NAMESTORE_records_store (
189 struct GNUNET_NAMESTORE_Handle *h, 193 struct GNUNET_NAMESTORE_Handle *h,
190 const struct GNUNET_IDENTITY_PrivateKey *pkey, 194 const struct GNUNET_CRYPTO_PrivateKey *pkey,
191 unsigned int rd_set_count, 195 unsigned int rd_set_count,
192 const struct GNUNET_NAMESTORE_RecordInfo *record_info, 196 const struct GNUNET_NAMESTORE_RecordInfo *record_info,
193 unsigned int *rds_sent, 197 unsigned int *rds_sent,
@@ -216,16 +220,14 @@ GNUNET_NAMESTORE_records_store2 (
216 * @return handle to abort the request 220 * @return handle to abort the request
217 */ 221 */
218struct GNUNET_NAMESTORE_QueueEntry * 222struct GNUNET_NAMESTORE_QueueEntry *
219GNUNET_NAMESTORE_records_store_ (struct GNUNET_NAMESTORE_Handle *h, 223GNUNET_NAMESTORE_record_set_store_ (struct GNUNET_NAMESTORE_Handle *h,
220 const struct GNUNET_IDENTITY_PrivateKey *pkey, 224 const struct GNUNET_CRYPTO_PrivateKey *pkey,
221 const char *label, 225 const char *label,
222 unsigned int rd_count, 226 unsigned int rd_count,
223 const struct GNUNET_GNSRECORD_Data *rd, 227 const struct GNUNET_GNSRECORD_Data *rd,
224 int is_zonemaster, 228 int is_zonemaster,
225 GNUNET_NAMESTORE_ContinuationWithStatus cont, 229 GNUNET_NAMESTORE_ContinuationWithStatus cont,
226 void *cont_cls); 230 void *cont_cls);
227
228
229 231
230 232
231/** 233/**
@@ -240,10 +242,27 @@ GNUNET_NAMESTORE_records_store_ (struct GNUNET_NAMESTORE_Handle *h,
240typedef void 242typedef void
241(*GNUNET_NAMESTORE_RecordMonitor) (void *cls, 243(*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
242 const struct 244 const struct
243 GNUNET_IDENTITY_PrivateKey *zone, 245 GNUNET_CRYPTO_PrivateKey *zone,
244 const char *label, 246 const char *label,
245 unsigned int rd_count, 247 unsigned int rd_count,
246 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);
247 266
248/** 267/**
249 * Process a record set that was stored in the namestore. 268 * Process a record set that was stored in the namestore.
@@ -260,7 +279,7 @@ typedef void
260typedef void 279typedef void
261(*GNUNET_NAMESTORE_RecordSetMonitor) (void *cls, 280(*GNUNET_NAMESTORE_RecordSetMonitor) (void *cls,
262 const struct 281 const struct
263 GNUNET_IDENTITY_PrivateKey *zone, 282 GNUNET_CRYPTO_PrivateKey *zone,
264 const char *label, 283 const char *label,
265 unsigned int rd_count, 284 unsigned int rd_count,
266 const struct GNUNET_GNSRECORD_Data *rd, 285 const struct GNUNET_GNSRECORD_Data *rd,
@@ -284,7 +303,7 @@ typedef void
284struct GNUNET_NAMESTORE_QueueEntry * 303struct GNUNET_NAMESTORE_QueueEntry *
285GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, 304GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
286 const struct 305 const struct
287 GNUNET_IDENTITY_PrivateKey *pkey, 306 GNUNET_CRYPTO_PrivateKey *pkey,
288 const char *label, 307 const char *label,
289 GNUNET_SCHEDULER_TaskCallback error_cb, 308 GNUNET_SCHEDULER_TaskCallback error_cb,
290 void *error_cb_cls, 309 void *error_cb_cls,
@@ -309,7 +328,7 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
309struct GNUNET_NAMESTORE_QueueEntry * 328struct GNUNET_NAMESTORE_QueueEntry *
310GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h, 329GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
311 const struct 330 const struct
312 GNUNET_IDENTITY_PrivateKey *pkey, 331 GNUNET_CRYPTO_PrivateKey *pkey,
313 const char *label, 332 const char *label,
314 GNUNET_SCHEDULER_TaskCallback error_cb, 333 GNUNET_SCHEDULER_TaskCallback error_cb,
315 void *error_cb_cls, 334 void *error_cb_cls,
@@ -318,7 +337,6 @@ GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
318 enum GNUNET_GNSRECORD_Filter filter); 337 enum GNUNET_GNSRECORD_Filter filter);
319 338
320 339
321
322/** 340/**
323 * 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.
324 * Returns at most one result to the processor. 342 * Returns at most one result to the processor.
@@ -338,9 +356,9 @@ GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
338 */ 356 */
339struct GNUNET_NAMESTORE_QueueEntry * 357struct GNUNET_NAMESTORE_QueueEntry *
340GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 358GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
341 const struct GNUNET_IDENTITY_PrivateKey *zone, 359 const struct GNUNET_CRYPTO_PrivateKey *zone,
342 const struct 360 const struct
343 GNUNET_IDENTITY_PublicKey *value_zone, 361 GNUNET_CRYPTO_PublicKey *value_zone,
344 GNUNET_SCHEDULER_TaskCallback error_cb, 362 GNUNET_SCHEDULER_TaskCallback error_cb,
345 void *error_cb_cls, 363 void *error_cb_cls,
346 GNUNET_NAMESTORE_RecordMonitor proc, 364 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -390,7 +408,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
390struct GNUNET_NAMESTORE_ZoneIterator * 408struct GNUNET_NAMESTORE_ZoneIterator *
391GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 409GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
392 const struct 410 const struct
393 GNUNET_IDENTITY_PrivateKey *zone, 411 GNUNET_CRYPTO_PrivateKey *zone,
394 GNUNET_SCHEDULER_TaskCallback error_cb, 412 GNUNET_SCHEDULER_TaskCallback error_cb,
395 void *error_cb_cls, 413 void *error_cb_cls,
396 GNUNET_NAMESTORE_RecordMonitor proc, 414 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -427,7 +445,7 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
427struct GNUNET_NAMESTORE_ZoneIterator * 445struct GNUNET_NAMESTORE_ZoneIterator *
428GNUNET_NAMESTORE_zone_iteration_start2 (struct GNUNET_NAMESTORE_Handle *h, 446GNUNET_NAMESTORE_zone_iteration_start2 (struct GNUNET_NAMESTORE_Handle *h,
429 const struct 447 const struct
430 GNUNET_IDENTITY_PrivateKey *zone, 448 GNUNET_CRYPTO_PrivateKey *zone,
431 GNUNET_SCHEDULER_TaskCallback error_cb, 449 GNUNET_SCHEDULER_TaskCallback error_cb,
432 void *error_cb_cls, 450 void *error_cb_cls,
433 GNUNET_NAMESTORE_RecordSetMonitor proc, 451 GNUNET_NAMESTORE_RecordSetMonitor proc,
@@ -437,7 +455,6 @@ GNUNET_NAMESTORE_zone_iteration_start2 (struct GNUNET_NAMESTORE_Handle *h,
437 enum GNUNET_GNSRECORD_Filter filter); 455 enum GNUNET_GNSRECORD_Filter filter);
438 456
439 457
440
441/** 458/**
442 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start 459 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
443 * for the next record. 460 * for the next record.
@@ -501,7 +518,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
501struct GNUNET_NAMESTORE_ZoneMonitor * 518struct GNUNET_NAMESTORE_ZoneMonitor *
502GNUNET_NAMESTORE_zone_monitor_start ( 519GNUNET_NAMESTORE_zone_monitor_start (
503 const struct GNUNET_CONFIGURATION_Handle *cfg, 520 const struct GNUNET_CONFIGURATION_Handle *cfg,
504 const struct GNUNET_IDENTITY_PrivateKey *zone, 521 const struct GNUNET_CRYPTO_PrivateKey *zone,
505 int iterate_first, 522 int iterate_first,
506 GNUNET_SCHEDULER_TaskCallback error_cb, 523 GNUNET_SCHEDULER_TaskCallback error_cb,
507 void *error_cb_cls, 524 void *error_cb_cls,
@@ -541,7 +558,7 @@ GNUNET_NAMESTORE_zone_monitor_start (
541struct GNUNET_NAMESTORE_ZoneMonitor * 558struct GNUNET_NAMESTORE_ZoneMonitor *
542GNUNET_NAMESTORE_zone_monitor_start2 ( 559GNUNET_NAMESTORE_zone_monitor_start2 (
543 const struct GNUNET_CONFIGURATION_Handle *cfg, 560 const struct GNUNET_CONFIGURATION_Handle *cfg,
544 const struct GNUNET_IDENTITY_PrivateKey *zone, 561 const struct GNUNET_CRYPTO_PrivateKey *zone,
545 int iterate_first, 562 int iterate_first,
546 GNUNET_SCHEDULER_TaskCallback error_cb, 563 GNUNET_SCHEDULER_TaskCallback error_cb,
547 void *error_cb_cls, 564 void *error_cb_cls,
@@ -592,57 +609,62 @@ GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
592 */ 609 */
593 610
594/** 611/**
595 * Begin a namestore transaction. 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.
596 * 618 *
597 * @param h handle to the namestore 619 * @param h handle to the namestore
598 * @param cont function to call on result 620 * @param pkey the private key of the zone to edit
599 * @param cont_cls closure for @a cont 621 * @param label the label of the record set to edit
600 * @return handle to abort the request 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
601 */ 628 */
602struct GNUNET_NAMESTORE_QueueEntry * 629struct GNUNET_NAMESTORE_QueueEntry *
603GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h, 630GNUNET_NAMESTORE_record_set_edit_begin (struct GNUNET_NAMESTORE_Handle *h,
604 GNUNET_NAMESTORE_ContinuationWithStatus 631 const struct
605 cont, 632 GNUNET_CRYPTO_PrivateKey *pkey,
606 void *cont_cls); 633 const char *label,
634 const char *editor_hint,
635 GNUNET_NAMESTORE_EditRecordSetBeginCallback
636 edit_cb,
637 void *edit_cb_cls);
607 638
608/** 639/**
609 * Begin rollback all actions in a transaction. 640 * If the current advisory lock is set to the provided editor hint,
610 * Reverts all actions performed since #GNUNET_NAMESTORE_transaction_begin 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.
611 * 645 *
612 * @param h handle to the namestore 646 * If provided editor hint does not match the current advisory lock,
613 * @param cont function to call on result 647 * this function is not doing anything (NOP).
614 * @param cont_cls closure for @a cont
615 * @return handle to abort the request
616 */
617struct GNUNET_NAMESTORE_QueueEntry *
618GNUNET_NAMESTORE_transaction_rollback (struct GNUNET_NAMESTORE_Handle *h,
619 GNUNET_NAMESTORE_ContinuationWithStatus
620 cont,
621 void *cont_cls);
622/**
623 * Commit a namestore transaction.
624 * Saves all actions performed since #GNUNET_NAMESTORE_transaction_begin
625 * 648 *
626 * @param h handle to the namestore 649 * @param h handle to the namestore
627 * @param cont function to call on result 650 * @param pkey the private key of the zone to edit
628 * @param cont_cls closure for @a cont 651 * @param label the label of the record set to edit
629 * @return handle to abort the request 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
630 */ 657 */
631struct GNUNET_NAMESTORE_QueueEntry * 658struct GNUNET_NAMESTORE_QueueEntry *
632GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, 659GNUNET_NAMESTORE_record_set_edit_cancel (struct GNUNET_NAMESTORE_Handle *h,
633 GNUNET_NAMESTORE_ContinuationWithStatus 660 const struct
634 cont, 661 GNUNET_CRYPTO_PrivateKey *pkey,
635 void *cont_cls); 662 const char *label,
636 663 const char *editor_hint,
637struct GNUNET_NAMESTORE_QueueEntry * 664 const char *editor_hint_replacement,
638GNUNET_NAMESTORE_records_edit ( 665 GNUNET_NAMESTORE_ContinuationWithStatus
639 struct GNUNET_NAMESTORE_Handle *h, 666 finished_cb,
640 const struct GNUNET_IDENTITY_PrivateKey *pkey, 667 void *finished_cls);
641 const char *label,
642 GNUNET_SCHEDULER_TaskCallback error_cb,
643 void *error_cb_cls,
644 GNUNET_NAMESTORE_RecordMonitor rm,
645 void *rm_cls);
646 668
647#if 0 /* keep Emacsens' auto-indent happy */ 669#if 0 /* keep Emacsens' auto-indent happy */
648{ 670{
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index f2854a0be..ba9f252a0 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -345,6 +345,19 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
345 345
346 346
347/** 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/**
348 * 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
349 * this peer. Mostly a convenience function so that clients do not 362 * this peer. Mostly a convenience function so that clients do not
350 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback 363 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 8d71d7764..764b7b29d 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -39,6 +39,7 @@
39#ifndef GNUNET_NETWORK_LIB_H 39#ifndef GNUNET_NETWORK_LIB_H
40#define GNUNET_NETWORK_LIB_H 40#define GNUNET_NETWORK_LIB_H
41 41
42#include "gnunet_common.h"
42#ifdef __cplusplus 43#ifdef __cplusplus
43extern "C" 44extern "C"
44{ 45{
@@ -157,7 +158,7 @@ GNUNET_NETWORK_socket_box_native (int fd);
157 * @param doBlock blocking mode 158 * @param doBlock blocking mode
158 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 159 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
159 */ 160 */
160int 161enum GNUNET_GenericReturnValue
161GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, 162GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
162 int doBlock); 163 int doBlock);
163 164
diff --git a/src/include/gnunet_nt_lib.h b/src/include/gnunet_nt_lib.h
index 144a3daa3..014b4fbe0 100644
--- a/src/include/gnunet_nt_lib.h
+++ b/src/include/gnunet_nt_lib.h
@@ -17,6 +17,11 @@
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/**
21 * @addtogroup Backbone 26 * @addtogroup Backbone
22 * @{ 27 * @{
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index 015282054..c1e193720 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -18,7 +18,7 @@
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__) 21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly." 22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif 23#endif
24 24
@@ -383,14 +383,14 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
383 * @param addrlen length of the address 383 * @param addrlen length of the address
384 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 384 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
385 */ 385 */
386typedef int 386typedef enum GNUNET_GenericReturnValue
387(*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, 387(*GNUNET_OS_NetworkInterfaceProcessor)(void *cls,
388 const char *name, 388 const char *name,
389 int isDefault, 389 int isDefault,
390 const struct sockaddr *addr, 390 const struct sockaddr *addr,
391 const struct sockaddr *broadcast_addr, 391 const struct sockaddr *broadcast_addr,
392 const struct sockaddr *netmask, 392 const struct sockaddr *netmask,
393 socklen_t addrlen); 393 socklen_t addrlen);
394 394
395 395
396/** 396/**
@@ -612,7 +612,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
612 * @param code return code/signal number 612 * @param code return code/signal number
613 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise 613 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
614 */ 614 */
615int 615enum GNUNET_GenericReturnValue
616GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, 616GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
617 enum GNUNET_OS_ProcessStatusType *type, 617 enum GNUNET_OS_ProcessStatusType *type,
618 unsigned long *code); 618 unsigned long *code);
@@ -628,7 +628,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
628 * @param proc pointer to process structure of the process to wait for 628 * @param proc pointer to process structure of the process to wait for
629 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 629 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
630 */ 630 */
631int 631enum GNUNET_GenericReturnValue
632GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); 632GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
633 633
634 634
@@ -641,7 +641,7 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
641 * @param code return code/signal number 641 * @param code return code/signal number
642 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise 642 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
643 */ 643 */
644int 644enum GNUNET_GenericReturnValue
645GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, 645GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
646 enum GNUNET_OS_ProcessStatusType *type, 646 enum GNUNET_OS_ProcessStatusType *type,
647 unsigned long *code); 647 unsigned long *code);
diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h
deleted file mode 100644
index 806de963c..000000000
--- a/src/include/gnunet_peerinfo_service.h
+++ /dev/null
@@ -1,214 +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 * @addtogroup Backbone
22 * @{
23 *
24 * @author Christian Grothoff
25 *
26 * @file
27 * Maintain the list of currently known hosts
28 *
29 * @defgroup peerinfo Peer Info service
30 * Maintain the list of currently known hosts.
31 *
32 * Holds an in-memory structure of data/hosts.
33 *
34 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
35 *
36 * @{
37 */
38
39#ifndef GNUNET_PEERINFO_SERVICE_H
40#define GNUNET_PEERINFO_SERVICE_H
41
42
43#include "gnunet_common.h"
44#include "gnunet_util_lib.h"
45#include "gnunet_hello_lib.h"
46
47#ifdef __cplusplus
48extern "C"
49{
50#if 0 /* keep Emacsens' auto-indent happy */
51}
52#endif
53#endif
54
55
56/**
57 * Handle to the peerinfo service.
58 */
59struct GNUNET_PEERINFO_Handle;
60
61
62/**
63 * Connect to the peerinfo service.
64 *
65 * @param cfg configuration to use
66 * @return NULL on error (configuration related, actual connection
67 * etablishment may happen asynchronously).
68 */
69struct GNUNET_PEERINFO_Handle *
70GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
71
72
73/**
74 * Disconnect from the peerinfo service. Note that all iterators must
75 * have completed or have been cancelled by the time this function is
76 * called (otherwise, calling this function is a serious error).
77 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
78 * pending, they will be cancelled silently on disconnect.
79 *
80 * @param h handle to disconnect
81 */
82void
83GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
84
85
86/**
87 * Add a host to the persistent list. This method operates in
88 * semi-reliable mode: if the transmission is not completed by
89 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
90 * aborted. Furthermore, if a second HELLO is added for the
91 * same peer before the first one was transmitted, PEERINFO may
92 * merge the two HELLOs prior to transmission to the service.
93 *
94 * @param h handle to the peerinfo service
95 * @param hello the verified (!) HELLO message
96 * @param cont continuation to call when done, NULL is allowed
97 * @param cont_cls closure for @a cont
98 * @return handle to cancel add operation; all pending
99 * 'add' operations will be cancelled automatically
100 * on disconnect, so it is not necessary to keep this
101 * handle (unless @a cont is non-NULL and at some point
102 * calling @a cont must be prevented)
103 */
104struct GNUNET_MQ_Envelope *
105GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
106 const struct GNUNET_HELLO_Message *hello,
107 GNUNET_SCHEDULER_TaskCallback cont,
108 void *cont_cls);
109
110
111/**
112 * Type of an iterator over the hosts. Note that each
113 * host will be called with each available protocol.
114 *
115 * @param cls closure
116 * @param peer id of the peer, NULL for last call
117 * @param hello hello message for the peer (can be NULL)
118 * @param error message
119 */
120typedef void
121(*GNUNET_PEERINFO_Processor) (void *cls,
122 const struct GNUNET_PeerIdentity *peer,
123 const struct GNUNET_HELLO_Message *hello,
124 const char *err_msg);
125
126
127/**
128 * Handle for cancellation of iteration over peers.
129 */
130struct GNUNET_PEERINFO_IteratorContext;
131
132
133/**
134 * Call a method for each known matching host. The callback method
135 * will be invoked once for each matching host and then finally once
136 * with a NULL pointer. After that final invocation, the iterator
137 * context must no longer be used.
138 *
139 * Instead of calling this function with `peer == NULL` it is often
140 * better to use #GNUNET_PEERINFO_notify().
141 *
142 * @param h handle to the peerinfo service
143 * @param include_friend_only include HELLO messages for friends only
144 * @param peer restrict iteration to this peer only (can be NULL)
145 * @param callback the method to call for each peer
146 * @param callback_cls closure for @a callback
147 * @return iterator context
148 */
149struct GNUNET_PEERINFO_IteratorContext *
150GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
151 int include_friend_only,
152 const struct GNUNET_PeerIdentity *peer,
153 GNUNET_PEERINFO_Processor callback,
154 void *callback_cls);
155
156
157/**
158 * Cancel an iteration over peer information.
159 *
160 * @param ic context of the iterator to cancel
161 */
162void
163GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
164
165
166/**
167 * Handle for notifications about changes to the set of known peers.
168 */
169struct GNUNET_PEERINFO_NotifyContext;
170
171
172/**
173 * Call a method whenever our known information about peers
174 * changes. Initially calls the given function for all known
175 * peers and then only signals changes.
176 *
177 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
178 * messages which are intended for friend to friend mode and which do not
179 * have to be gossiped. Otherwise these messages are skipped.
180 *
181 * @param cfg configuration to use
182 * @param include_friend_only include HELLO messages for friends only
183 * @param callback the method to call for each peer
184 * @param callback_cls closure for @a callback
185 * @return NULL on error
186 */
187struct GNUNET_PEERINFO_NotifyContext *
188GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
189 int include_friend_only,
190 GNUNET_PEERINFO_Processor callback,
191 void *callback_cls);
192
193
194/**
195 * Stop notifying about changes.
196 *
197 * @param nc context to stop notifying
198 */
199void
200GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
201
202
203#if 0 /* keep Emacsens' auto-indent happy */
204{
205#endif
206#ifdef __cplusplus
207}
208#endif
209
210#endif
211
212/** @} */ /* end of group */
213
214/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_peerstore_plugin.h b/src/include/gnunet_peerstore_plugin.h
index 2636c3009..6ecb9135a 100644
--- a/src/include/gnunet_peerstore_plugin.h
+++ b/src/include/gnunet_peerstore_plugin.h
@@ -46,6 +46,19 @@ extern "C"
46#endif 46#endif
47#endif 47#endif
48 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);
49 62
50/** 63/**
51 * @brief struct returned by the initialization function of the plugin 64 * @brief struct returned by the initialization function of the plugin
@@ -93,6 +106,7 @@ struct GNUNET_PEERSTORE_PluginFunctions
93 * @param sub_system name of sub system 106 * @param sub_system name of sub system
94 * @param peer Peer identity (can be NULL) 107 * @param peer Peer identity (can be NULL)
95 * @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
96 * @param iter function to call asynchronously with the results, terminated 110 * @param iter function to call asynchronously with the results, terminated
97 * by a NULL result 111 * by a NULL result
98 * @param iter_cls closure for @a iter 112 * @param iter_cls closure for @a iter
@@ -104,7 +118,9 @@ struct GNUNET_PEERSTORE_PluginFunctions
104 const char *sub_system, 118 const char *sub_system,
105 const struct GNUNET_PeerIdentity *peer, 119 const struct GNUNET_PeerIdentity *peer,
106 const char *key, 120 const char *key,
107 GNUNET_PEERSTORE_Processor iter, 121 uint64_t serial,
122 uint64_t limit,
123 GNUNET_PEERSTORE_PluginProcessor iter,
108 void *iter_cls); 124 void *iter_cls);
109 125
110 /** 126 /**
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index c4000c680..3fb9df82a 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -46,6 +46,10 @@ extern "C" {
46#endif 46#endif
47#endif 47#endif
48 48
49/**
50 * Key used for storing HELLO in the peerstore
51 */
52#define GNUNET_PEERSTORE_HELLO_KEY "peerstore-peer-hello-uri"
49 53
50/** 54/**
51 * Key used for storing addresses in URL format in the peerstore 55 * Key used for storing addresses in URL format in the peerstore
@@ -62,32 +66,32 @@ extern "C" {
62 * messages. 66 * messages.
63 */ 67 */
64#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \ 68#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \
65 "transport-backchannel-monotonic-time" 69 "transport-backchannel-monotonic-time"
66 70
67/** 71/**
68 * Key used to store sender's monotonic time from DV learn 72 * Key used to store sender's monotonic time from DV learn
69 * messages. 73 * messages.
70 */ 74 */
71#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \ 75#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \
72 "transport-dv-learn-monotonic-time" 76 "transport-dv-learn-monotonic-time"
73 77
74/** 78/**
75 * Key used to store sender's monotonic time from handshake message. 79 * Key used to store sender's monotonic time from handshake message.
76 */ 80 */
77#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \ 81#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \
78 "transport-tcp-communicator-handshake" 82 "transport-tcp-communicator-handshake"
79 83
80/** 84/**
81 * 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.
82 */ 86 */
83#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \ 87#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \
84 "transport-tcp-communicator-handshake-ack" 88 "transport-tcp-communicator-handshake-ack"
85 89
86/** 90/**
87 * Key used to store sender's monotonic time from rekey message. 91 * Key used to store sender's monotonic time from rekey message.
88 */ 92 */
89#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \ 93#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \
90 "transport-tcp-communicator-rekey" 94 "transport-tcp-communicator-rekey"
91 95
92 96
93/** 97/**
@@ -104,7 +108,8 @@ enum GNUNET_PEERSTORE_StoreOption
104 * Delete any previous values for the given key before 108 * Delete any previous values for the given key before
105 * storing the given value. 109 * storing the given value.
106 */ 110 */
107 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1 111 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1,
112
108}; 113};
109 114
110/** 115/**
@@ -118,6 +123,11 @@ struct GNUNET_PEERSTORE_Handle;
118struct GNUNET_PEERSTORE_StoreContext; 123struct GNUNET_PEERSTORE_StoreContext;
119 124
120/** 125/**
126 * Context for the info handler.
127 */
128struct GNUNET_PEERSTORE_NotifyContext;
129
130/**
121 * Single PEERSTORE record 131 * Single PEERSTORE record
122 */ 132 */
123struct GNUNET_PEERSTORE_Record 133struct GNUNET_PEERSTORE_Record
@@ -152,11 +162,6 @@ struct GNUNET_PEERSTORE_Record
152 */ 162 */
153 struct GNUNET_TIME_Absolute expiry; 163 struct GNUNET_TIME_Absolute expiry;
154 164
155 /**
156 * Client from which this record originated.
157 * NOTE: This is internal to the service.
158 */
159 struct GNUNET_SERVICE_Client *client;
160}; 165};
161 166
162 167
@@ -170,9 +175,16 @@ typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success);
170 175
171 176
172/** 177/**
178 * Context for a add hello uri request.
179 */
180struct GNUNET_PEERSTORE_StoreHelloContext;
181
182
183/**
173 * Function called by PEERSTORE for each matching record. 184 * Function called by PEERSTORE for each matching record.
174 * 185 *
175 * @param cls closure 186 * @param cls closure
187 * @param seq sequence in interation
176 * @param record peerstore record information 188 * @param record peerstore record information
177 * @param emsg error message, or NULL if no errors 189 * @param emsg error message, or NULL if no errors
178 */ 190 */
@@ -181,6 +193,43 @@ typedef void (*GNUNET_PEERSTORE_Processor) (
181 const struct GNUNET_PEERSTORE_Record *record, 193 const struct GNUNET_PEERSTORE_Record *record,
182 const char *emsg); 194 const char *emsg);
183 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
184 233
185/** 234/**
186 * Connect to the PEERSTORE service. 235 * Connect to the PEERSTORE service.
@@ -192,15 +241,13 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
192 241
193 242
194/** 243/**
195 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests 244 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH and
196 * will be canceled. 245 * STORE requests will be canceled.
197 * Any pending STORE requests will depend on @e snyc_first flag.
198 * 246 *
199 * @param h handle to disconnect 247 * @param h handle to disconnect
200 * @param sync_first send any pending STORE requests before disconnecting
201 */ 248 */
202void 249void
203GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first); 250GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h);
204 251
205 252
206/** 253/**
@@ -242,64 +289,130 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
242 289
243 290
244/** 291/**
245 * 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.
246 * 300 *
247 * @param h handle to the PEERSTORE service 301 * @param h handle to the PEERSTORE service
248 * @param sub_system name of sub system 302 * @param sub_system name of sub system
249 * @param peer Peer identity (can be NULL) 303 * @param peer Peer identity (can be NULL)
250 * @param key entry key string (can be NULL) 304 * @param key entry key string (can be NULL)
251 * @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.
252 * @param callback_cls closure for @a callback 306 * @param callback_cls closure for @a callback
253 * @return Handle to iteration request 307 * @return Handle to iteration request
254 */ 308 */
255struct GNUNET_PEERSTORE_IterateContext * 309struct GNUNET_PEERSTORE_IterateContext *
256GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, 310GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h,
257 const char *sub_system, 311 const char *sub_system,
258 const struct GNUNET_PeerIdentity *peer, 312 const struct GNUNET_PeerIdentity *peer,
259 const char *key, 313 const char *key,
260 GNUNET_PEERSTORE_Processor callback, 314 GNUNET_PEERSTORE_Processor callback,
261 void *callback_cls); 315 void *callback_cls);
262 316
263 317
264/** 318/**
265 * Cancel an iterate request 319 * Continue an iteration.
266 * Please do not call after the iterate request is done 320 * Do NOT call after the iterate request is done.
267 * 321 *
268 * @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.
269 */ 324 */
270void 325void
271GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic); 326GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic,
327 uint64_t limit);
272 328
273 329
274/** 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/**
275 * Request watching a given key 340 * Request watching a given key
276 * 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.
277 * 353 *
278 * @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
279 * @param sub_system name of sub system 356 * @param sub_system name of sub system
280 * @param peer Peer identity 357 * @param peer Peer identity
281 * @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
282 * @param callback function called with each new value 367 * @param callback function called with each new value
283 * @param callback_cls closure for @a callback 368 * @param callback_cls closure for @a callback
284 * @return Handle to watch request 369 * @return Handle to watch request
285 */ 370 */
286struct GNUNET_PEERSTORE_WatchContext * 371struct GNUNET_PEERSTORE_Monitor *
287GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, 372GNUNET_PEERSTORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
288 const char *sub_system, 373 int iterate_first,
289 const struct GNUNET_PeerIdentity *peer, 374 const char *sub_system,
290 const char *key, 375 const struct GNUNET_PeerIdentity *peer,
291 GNUNET_PEERSTORE_Processor callback, 376 const char *key,
292 void *callback_cls); 377 GNUNET_SCHEDULER_TaskCallback error_cb,
293 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);
294 383
295/** 384/**
296 * 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.
297 * 389 *
298 * @param wc handle to the watch request 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.
400 *
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)
299 */ 404 */
300void 405void
301GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc); 406GNUNET_PEERSTORE_monitor_next (struct GNUNET_PEERSTORE_Monitor *zm,
407 uint64_t limit);
302 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);
303 416
304#if 0 /* keep Emacsens' auto-indent happy */ 417#if 0 /* keep Emacsens' auto-indent happy */
305{ 418{
diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h
index a3135e2cf..2a9cde47f 100644
--- a/src/include/gnunet_plugin_lib.h
+++ b/src/include/gnunet_plugin_lib.h
@@ -70,7 +70,7 @@ typedef void *
70 * @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
71 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not 71 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
72 */ 72 */
73int 73enum GNUNET_GenericReturnValue
74GNUNET_PLUGIN_test (const char *library_name); 74GNUNET_PLUGIN_test (const char *library_name);
75 75
76 76
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 4cbc2a139..7501bee12 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -27,8 +27,17 @@
27 27
28 28
29#include <libpq-fe.h> 29#include <libpq-fe.h>
30#include <stdint.h>
31#include "gnunet_common.h"
32#include "gnunet_time_lib.h"
30#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
31#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;
32 41
33/* ************************* pq_query_helper.c functions ************************ */ 42/* ************************* pq_query_helper.c functions ************************ */
34 43
@@ -58,6 +67,14 @@ typedef int
58 void *scratch[], 67 void *scratch[],
59 unsigned int scratch_length); 68 unsigned int scratch_length);
60 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);
61 78
62/** 79/**
63 * @brief Description of a DB query parameter. 80 * @brief Description of a DB query parameter.
@@ -71,10 +88,20 @@ struct GNUNET_PQ_QueryParam
71 88
72 /** 89 /**
73 * 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.
74 */ 94 */
75 void *conv_cls; 95 void *conv_cls;
76 96
77 /** 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 /**
78 * Data or NULL. 105 * Data or NULL.
79 */ 106 */
80 const void *data; 107 const void *data;
@@ -91,6 +118,15 @@ struct GNUNET_PQ_QueryParam
91 118
92}; 119};
93 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);
94 130
95/** 131/**
96 * End of query parameter specification. 132 * End of query parameter specification.
@@ -146,38 +182,209 @@ GNUNET_PQ_query_param_string (const char *ptr);
146struct GNUNET_PQ_QueryParam 182struct GNUNET_PQ_QueryParam
147GNUNET_PQ_query_param_bool (bool b); 183GNUNET_PQ_query_param_bool (bool b);
148 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
149 199
150/** 200/**
151 * Information for an array argument. 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.
152 */ 206 */
153struct GNUNET_PQ_ArraySpec 207struct GNUNET_PQ_ArrayHeader_P
154{ 208{
155 /** 209 uint32_t ndim; /* number of dimensions. we only support ndim = 1 */
156 * Number of dimensions of the array 210 uint32_t has_null;
157 */ 211 uint32_t oid; /* oid of the elements */
158 unsigned int ndims; 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));
159 215
160 /**
161 * Array of @e ndims lengths of the array
162 */
163 unsigned int *lens;
164 216
165 /** 217/**
166 * One-dimensional array of pointers to conversion functions for the 218 * Generate query parameter for an array of bool in host byte order.
167 * elements in the array. 219 *
168 */ 220 * @param num Number of elements in @a elements
169 const struct GNUNET_PQ_QueryParam *ae; 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);
170 230
171}; 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))
172 358
173 359
174/** 360/**
175 * Generate query parameter for an array. 361 * Generate query parameter for an array of strings (continuous)
176 * 362 *
177 * @param as array specification 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
178 */ 367 */
179struct GNUNET_PQ_QueryParam 368struct GNUNET_PQ_QueryParam
180GNUNET_PQ_query_param_array (const struct GNUNET_PQ_ArraySpec *as); 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);
181 388
182 389
183/** 390/**
@@ -190,6 +397,83 @@ GNUNET_PQ_query_param_array (const struct GNUNET_PQ_ArraySpec *as);
190#define GNUNET_PQ_query_param_auto_from_type(x) \ 397#define GNUNET_PQ_query_param_auto_from_type(x) \
191 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) 398 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
192 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);
193 477
194/** 478/**
195 * Generate query parameter for an RSA public key. The 479 * Generate query parameter for an RSA public key. The
@@ -293,7 +577,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x);
293 577
294 578
295/** 579/**
296 * Generate query parameter for an uint16_t in host byte order. 580 * Generate query parameter for an uint64_t in host byte order.
297 * 581 *
298 * @param x pointer to the query parameter to pass 582 * @param x pointer to the query parameter to pass
299 * @return query parameter to use 583 * @return query parameter to use
@@ -302,6 +586,37 @@ struct GNUNET_PQ_QueryParam
302GNUNET_PQ_query_param_uint64 (const uint64_t *x); 586GNUNET_PQ_query_param_uint64 (const uint64_t *x);
303 587
304 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
305/* ************************* pq_result_helper.c functions ************************ */ 620/* ************************* pq_result_helper.c functions ************************ */
306 621
307 622
@@ -351,8 +666,7 @@ struct GNUNET_PQ_ResultSpec
351 GNUNET_PQ_ResultConverter conv; 666 GNUNET_PQ_ResultConverter conv;
352 667
353 /** 668 /**
354 * Function to clean up result data, NULL if cleanup is 669 * Function to clean up result data, NULL if cleanup is not necessary.
355 * not necessary.
356 */ 670 */
357 GNUNET_PQ_ResultCleanup cleaner; 671 GNUNET_PQ_ResultCleanup cleaner;
358 672
@@ -367,9 +681,9 @@ struct GNUNET_PQ_ResultSpec
367 void *dst; 681 void *dst;
368 682
369 /** 683 /**
370 * Allowed size for the data, 0 for variable-size 684 * Allowed size for the data, 0 for variable-size (in this case, the type of
371 * (in this case, the type of @e dst is a `void **` 685 * @e dst is a `void **` and we need to allocate a buffer of the right
372 * and we need to allocate a buffer of the right size). 686 * size).
373 */ 687 */
374 size_t dst_size; 688 size_t dst_size;
375 689
@@ -389,10 +703,8 @@ struct GNUNET_PQ_ResultSpec
389 bool is_nullable; 703 bool is_nullable;
390 704
391 /** 705 /**
392 * Points to a location where we should store 706 * Points to a location where we should store "true" if the result found is
393 * "true" if the result found is NULL, and 707 * NULL, and otherwise "false". Only used if @e is_nullable is true.
394 * otherwise "false". Only used if @e is_nullable
395 * is true.
396 */ 708 */
397 bool *is_null; 709 bool *is_null;
398 710
@@ -419,8 +731,7 @@ struct GNUNET_PQ_ResultSpec
419 731
420 732
421/** 733/**
422 * Allow NULL value to be found in the database 734 * Allow NULL value to be found in the database for the given value.
423 * for the given value.
424 * 735 *
425 * @param rs result spec entry to modify 736 * @param rs result spec entry to modify
426 * @param[out] is_null location set to 'true' if the 737 * @param[out] is_null location set to 'true' if the
@@ -616,15 +927,233 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
616 uint64_t *u64); 927 uint64_t *u64);
617 928
618 929
619/* ************************* pq.c functions ************************ */ 930/**
931 * int64_t expected.
932 *
933 * @param name name of the field in the table
934 * @param[out] i64 where to store the result
935 * @return array entry for the result specification to use
936 */
937struct GNUNET_PQ_ResultSpec
938GNUNET_PQ_result_spec_int64 (const char *name,
939 int64_t *i64);
940
620 941
621/** 942/**
622 * Postgres context. 943 * array of bool expected.
944 *
945 * @param db Database context, needed for OID lookup for the correct type
946 * @param name name of the field in the table
947 * @param[out] num where to store the number of elements in the array @a bools.
948 * @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.
949 * @return array entry for the result specification to use
950 */
951struct GNUNET_PQ_ResultSpec
952GNUNET_PQ_result_spec_array_bool (
953 struct GNUNET_PQ_Context *db,
954 const char *name,
955 size_t *num,
956 bool **bools);
957
958/**
959 * array of uint16_t expected.
960 *
961 * @param db Database context, needed for OID lookup for the correct type
962 * @param name name of the field in the table
963 * @param[out] num where to store the number of elements in the array @a u16s.
964 * @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.
965 * @return array entry for the result specification to use
966 */
967struct GNUNET_PQ_ResultSpec
968GNUNET_PQ_result_spec_array_uint16 (
969 struct GNUNET_PQ_Context *db,
970 const char *name,
971 size_t *num,
972 uint16_t **dst);
973
974/**
975 * array of uint32_t expected.
976 *
977 * @param db Database context, needed for OID lookup for the correct type
978 * @param name name of the field in the table
979 * @param[out] num where to store the number of elements in the array @a u32s.
980 * @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.
981 * @return array entry for the result specification to use
982 */
983struct GNUNET_PQ_ResultSpec
984GNUNET_PQ_result_spec_array_uint32 (
985 struct GNUNET_PQ_Context *db,
986 const char *name,
987 size_t *num,
988 uint32_t **dst);
989
990/**
991 * array of uint64_t expected.
992 *
993 * @param db Database context, needed for OID lookup for the correct type
994 * @param name name of the field in the table
995 * @param[out] num where to store the number of elements in the array @a u64s.
996 * @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.
997 * @return array entry for the result specification to use
998 */
999struct GNUNET_PQ_ResultSpec
1000GNUNET_PQ_result_spec_array_uint64 (
1001 struct GNUNET_PQ_Context *db,
1002 const char *name,
1003 size_t *num,
1004 uint64_t **dst);
1005
1006
1007/**
1008 * array of absolute time expected.
1009 *
1010 * @param db Database context, needed for OID lookup for the correct type
1011 * @param name name of the field in the table
1012 * @param[out] num where to store the number of elements in the array @a u64s.
1013 * @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.
1014 * @return array entry for the result specification to use
1015 */
1016struct GNUNET_PQ_ResultSpec
1017GNUNET_PQ_result_spec_array_abs_time (
1018 struct GNUNET_PQ_Context *db,
1019 const char *name,
1020 size_t *num,
1021 struct GNUNET_TIME_Absolute **dst);
1022
1023/**
1024 * array of relative time expected.
1025 *
1026 * @param db Database context, needed for OID lookup for the correct type
1027 * @param name name of the field in the table
1028 * @param[out] num where to store the number of elements in the array @a u64s.
1029 * @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.
1030 * @return array entry for the result specification to use
1031 */
1032struct GNUNET_PQ_ResultSpec
1033GNUNET_PQ_result_spec_array_rel_time (
1034 struct GNUNET_PQ_Context *db,
1035 const char *name,
1036 size_t *num,
1037 struct GNUNET_TIME_Relative **dst);
1038
1039/**
1040 * array of relative time expected.
1041 *
1042 * @param db Database context, needed for OID lookup for the correct type
1043 * @param name name of the field in the table
1044 * @param[out] num where to store the number of elements in the array @a u64s.
1045 * @param[out] dst pointer to where to store the array of @a num timestamps. Allocated by the function, MUST be freed with GNUNET_free.
1046 * @return array entry for the result specification to use
623 */ 1047 */
624struct GNUNET_PQ_Context; 1048
1049struct GNUNET_PQ_ResultSpec
1050GNUNET_PQ_result_spec_array_timestamp (
1051 struct GNUNET_PQ_Context *db,
1052 const char *name,
1053 size_t *num,
1054 struct GNUNET_TIME_Timestamp **dst);
1055
1056/**
1057 * Array of variable-size result expected.
1058 *
1059 * @param db Database context, needed for OID lookup for the correct type
1060 * @param name name of the field in the table
1061 * @param[out] num where to store the number of elements
1062 * @param[out] sizes where to store the @a num size's of byte-buffers in @a dst
1063 * @param[out] dst where to store the continuous array of @a num byte-buffers , allocated
1064 * @return array entry for the result specification to use
1065 */
1066struct GNUNET_PQ_ResultSpec
1067GNUNET_PQ_result_spec_array_variable_size (
1068 struct GNUNET_PQ_Context *db,
1069 const char *name,
1070 size_t *num,
1071 size_t **sizes,
1072 void **dst);
625 1073
626 1074
627/** 1075/**
1076 * Array of fixed-size result expected.
1077 *
1078 * @param db Database context, needed for OID lookup for the correct type
1079 * @param name name of the field in the table
1080 * @param size number of bytes expected in each element of @a dst
1081 * @param[out] num where to store the number of elements
1082 * @param[out] dst where to store the results, an continuous array of fixed-size elements
1083 * @return array entry for the result specification to use
1084 */
1085struct GNUNET_PQ_ResultSpec
1086GNUNET_PQ_result_spec_array_fixed_size (
1087 struct GNUNET_PQ_Context *db,
1088 const char *name,
1089 size_t size,
1090 size_t *num,
1091 void **dst);
1092
1093
1094/**
1095 * We expect a fixed-size result, with size determined by the type of `* dst`
1096 *
1097 * @param db Database context, needed for OID lookup for the correct type
1098 * @param name name of the field in the table
1099 * @param num pointer to where to store the number of elements
1100 * @param dst pointer to where to store the results, type fits expected result size
1101 * @return array entry for the result specification to use
1102 */
1103#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \
1104 GNUNET_PQ_result_spec_array_fixed_size ( \
1105 (db), \
1106 (name), \
1107 sizeof(*(dst)), \
1108 (num), \
1109 (void *) &(dst))
1110
1111
1112/**
1113 * Array of 0-terminated strings expected.
1114 *
1115 * @param db Database context, needed for OID lookup for the correct type
1116 * @param name name of the field in the table
1117 * @param[out] num where to store the number of elements
1118 * @param[out] dst where to store the allocated continous array of @a num 0-terminated strings
1119 * @return array entry for the result specification to use
1120 */
1121struct GNUNET_PQ_ResultSpec
1122GNUNET_PQ_result_spec_array_string (
1123 struct GNUNET_PQ_Context *db,
1124 const char *name,
1125 size_t *num,
1126 char **dst);
1127
1128
1129/**
1130 * Blind sign public key expected.
1131 *
1132 * @param name name of the field in the table
1133 * @param[out] public_key where to store the denomination signature
1134 * @return array entry for the result specification to use
1135 */
1136struct GNUNET_PQ_ResultSpec
1137GNUNET_PQ_result_spec_blind_sign_pub (
1138 const char *name,
1139 struct GNUNET_CRYPTO_BlindSignPublicKey **public_key);
1140
1141
1142/**
1143 * Blind sign private key expected.
1144 *
1145 * @param name name of the field in the table
1146 * @param[out] private_key where to store the denomination signature
1147 * @return array entry for the result specification to use
1148 */
1149struct GNUNET_PQ_ResultSpec
1150GNUNET_PQ_result_spec_blind_sign_priv (
1151 const char *name,
1152 struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key);
1153
1154/* ************************* pq.c functions ************************ */
1155
1156/**
628 * Execute a prepared statement. 1157 * Execute a prepared statement.
629 * 1158 *
630 * @param db database context 1159 * @param db database context
@@ -827,8 +1356,9 @@ GNUNET_PQ_prepare_statements (struct GNUNET_PQ_Context *db,
827 1356
828 1357
829/** 1358/**
830 * Request creation of prepared statements @a ps from Postgres, but do not automatically re-prepare the statement 1359 * Request creation of prepared statements @a ps from Postgres, but do not
831 * if we are disconnected from the database. 1360 * automatically re-prepare the statement if we are disconnected from the
1361 * database.
832 * 1362 *
833 * @param db database to prepare the statements for 1363 * @param db database to prepare the statements for
834 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared 1364 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
@@ -1010,10 +1540,10 @@ GNUNET_PQ_connect2 (const char *config_str,
1010 1540
1011 1541
1012/** 1542/**
1013 * Connect to a postgres database using the configuration 1543 * Connect to a postgres database using the configuration option "CONFIG" in
1014 * option "CONFIG" in @a section. Also ensures that the 1544 * @a section. Also ensures that the statements in @a es are executed
1015 * statements in @a es are executed whenever we (re)connect to the 1545 * whenever we (re)connect to the database, and that the prepared statements
1016 * database, and that the prepared statements in @a ps are "ready". 1546 * in @a ps are "ready".
1017 * 1547 *
1018 * The caller does not have to ensure that @a es and @a ps remain allocated 1548 * The caller does not have to ensure that @a es and @a ps remain allocated
1019 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. 1549 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
@@ -1041,7 +1571,8 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
1041 * database, and that the prepared statements in @a ps are "ready". 1571 * database, and that the prepared statements in @a ps are "ready".
1042 * 1572 *
1043 * The caller does not have to ensure that @a es and @a ps remain allocated 1573 * The caller does not have to ensure that @a es and @a ps remain allocated
1044 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. 1574 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a
1575 * copy will be made.
1045 * 1576 *
1046 * @param cfg configuration 1577 * @param cfg configuration
1047 * @param section configuration section to use to get Postgres configuration options 1578 * @param section configuration section to use to get Postgres configuration options
@@ -1120,12 +1651,24 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);
1120 1651
1121 1652
1122/** 1653/**
1654 * Poll for events right now. Useful if we may have
1655 * triggered an event for ourselves. Not needed when
1656 * using GNUNET_PQ_event_notify(), but useful when
1657 * stored procedures may have triggered events.
1658 * Does nothing if there are no events.
1659 *
1660 * @param[in,out] db database to check for events
1661 */
1662void
1663GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db);
1664
1665
1666/**
1123 * Notify all that listen on @a es of an event. 1667 * Notify all that listen on @a es of an event.
1124 * 1668 *
1125 * Unlike many other calls, this function is thread-safe 1669 * Unlike many other calls, this function is thread-safe and may be called
1126 * and may be called from threads that are different 1670 * from threads that are different from the one that setup @a db. However, the
1127 * from the one that setup @a db. However, the @a cb 1671 * @a cb will always be called from the thread that runs
1128 * will always be called from the thread that runs
1129 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler. 1672 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
1130 * 1673 *
1131 * @param db database context to use 1674 * @param db database context to use
@@ -1141,14 +1684,14 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
1141 1684
1142 1685
1143/** 1686/**
1144 * Compute the channel that one should notify upon 1687 * Compute the channel that one should notify upon for the given event
1145 * for the given event specification. 1688 * specification.
1146 * 1689 *
1147 * @param es event specification 1690 * @param es event specification
1148 * @return channel to notify upon 1691 * @return channel to notify upon
1149 */ 1692 */
1150char * 1693char *
1151GNUNET_PG_get_event_notify_channel (const struct GNUNET_DB_EventHeaderP *es); 1694GNUNET_PQ_get_event_notify_channel (const struct GNUNET_DB_EventHeaderP *es);
1152 1695
1153 1696
1154/** 1697/**
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h
index 0c51d6cf7..f06d95422 100644
--- a/src/include/gnunet_program_lib.h
+++ b/src/include/gnunet_program_lib.h
@@ -18,7 +18,7 @@
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__) 21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly." 22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif 23#endif
24 24
@@ -122,6 +122,45 @@ GNUNET_PROGRAM_run (int argc,
122 GNUNET_PROGRAM_Main task, 122 GNUNET_PROGRAM_Main task,
123 void *task_cls); 123 void *task_cls);
124 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
125 164
126#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
127{ 166{
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index e78738d7b..6ab008d16 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
@@ -1327,7 +1327,7 @@ extern "C" {
1327/** 1327/**
1328 * Service to client: result of store operation. 1328 * Service to client: result of store operation.
1329 */ 1329 */
1330#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 436 1330#define GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE 436
1331 1331
1332/** 1332/**
1333 * Client to service: lookup label 1333 * Client to service: lookup label
@@ -2352,7 +2352,7 @@ extern "C" {
2352/** 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
2353 * parts. */ 2353 * parts. */
2354#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \ 2354#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \
2355 692 // FIXME: start using this where appropriate 2355 692 // FIXME: start using this where appropriate
2356 2356
2357/** Message part: method */ 2357/** Message part: method */
2358#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693 2358#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693
@@ -2599,14 +2599,14 @@ extern "C" {
2599#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820 2599#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820
2600 2600
2601/** 2601/**
2602 * Iteration request 2602 * Iteration request (see also 828, 829)
2603 */ 2603 */
2604#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 821 2604#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_START 821
2605 2605
2606/** 2606/**
2607 * Iteration record message 2607 * Record result message
2608 */ 2608 */
2609#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD 822 2609#define GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD 822
2610 2610
2611/** 2611/**
2612 * Iteration end message 2612 * Iteration end message
@@ -2614,19 +2614,34 @@ extern "C" {
2614#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823 2614#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823
2615 2615
2616/** 2616/**
2617 * Watch request 2617 * Monitor request
2618 */ 2618 */
2619#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH 824 2619#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_START 824
2620 2620
2621/** 2621/**
2622 * Watch response 2622 * Monitor sync
2623 */ 2623 */
2624#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD 825 2624#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_SYNC 825
2625 2625
2626/** 2626/**
2627 * Watch cancel request 2627 * Monitor next request
2628 */ 2628 */
2629#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL 826 2629#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_NEXT 826
2630
2631/**
2632 * Store result message
2633 */
2634#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT 827
2635
2636/**
2637 * Iteration request (see also 821, 829)
2638 */
2639#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_NEXT 828
2640
2641/**
2642 * Iteration request (see also 821, 828)
2643 */
2644#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_STOP 829
2630 2645
2631/******************************************************************************* 2646/*******************************************************************************
2632 * SOCIAL message types 2647 * SOCIAL message types
@@ -3201,6 +3216,11 @@ extern "C" {
3201#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 3216#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064
3202 3217
3203/** 3218/**
3219 * Message to ask NAT service to notify all clients about a new global address.
3220 */
3221#define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS 1065
3222
3223/**
3204 * Message to ask NAT service to request autoconfiguration. 3224 * Message to ask NAT service to request autoconfiguration.
3205 */ 3225 */
3206#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067 3226#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067
@@ -3530,6 +3550,11 @@ extern "C" {
3530#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461 3550#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461
3531 3551
3532/** 3552/**
3553 * UDP Rekey.
3554 */
3555#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_REKEY 1462
3556
3557/**
3533 * Next available: 1500 3558 * Next available: 1500
3534 */ 3559 */
3535#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500 3560#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500
@@ -3549,17 +3574,9 @@ extern "C" {
3549 3574
3550#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 3575#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600
3551 3576
3552#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601 3577#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1601
3553
3554#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602
3555
3556#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603
3557 3578
3558#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604 3579#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1602
3559
3560#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605
3561
3562#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606
3563 3580
3564/************************************ Room *************************************/ 3581/************************************ Room *************************************/
3565 3582
@@ -3575,6 +3592,10 @@ extern "C" {
3575 3592
3576#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616 3593#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616
3577 3594
3595#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC 1617
3596
3597#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_LINK 1618
3598
3578/*********************************************************************************/ 3599/*********************************************************************************/
3579 3600
3580/*********************************************************************************/ 3601/*********************************************************************************/
@@ -3618,20 +3639,19 @@ extern "C" {
3618 */ 3639 */
3619 3640
3620/** 3641/**
3621 * Message type for Begin, Commit or Rollback 3642 * Message type for start of record edit with advisory lock
3622 */ 3643 */
3623#define GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL 1750 3644#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT 1750
3624 3645
3625/** 3646/**
3626 * Return status message for control message 3647 * Return record set to edit with previous editor hint/advisory lock
3627 */ 3648 */
3628#define GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT 1751 3649#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE 1751
3629 3650
3630/** 3651/**
3631 * Open and lock records for editing message 3652 * Message type for cancellation/reset of editor hint/advisory lock
3632 */ 3653 */
3633#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_EDIT 1752 3654#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_CANCEL 1752
3634
3635 3655
3636/** 3656/**
3637 * Type used to match 'all' message types. 3657 * Type used to match 'all' message types.
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index 49a006e91..086c3f021 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -49,7 +49,7 @@ extern "C" {
49/** 49/**
50 * Version number of the re:claimID API. 50 * Version number of the re:claimID API.
51 */ 51 */
52#define GNUNET_RECLAIM_VERSION 0x00000001 52#define GNUNET_RECLAIM_VERSION 0x00000002
53 53
54/** 54/**
55 * Opaque handle to access the service. 55 * Opaque handle to access the service.
@@ -62,6 +62,9 @@ struct GNUNET_RECLAIM_Handle;
62 */ 62 */
63struct GNUNET_RECLAIM_Operation; 63struct GNUNET_RECLAIM_Operation;
64 64
65#define GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN 256
66
67#define GNUNET_RECLAIM_TICKET_RP_URI_URN_PREFIX "urn:gns:"
65 68
66/** 69/**
67 * The authorization ticket. This ticket is meant to be transferred 70 * The authorization ticket. This ticket is meant to be transferred
@@ -72,19 +75,30 @@ struct GNUNET_RECLAIM_Operation;
72struct GNUNET_RECLAIM_Ticket 75struct GNUNET_RECLAIM_Ticket
73{ 76{
74 /** 77 /**
75 * 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.
76 */ 82 */
77 struct GNUNET_IDENTITY_PublicKey identity; 83 char gns_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH * 2 + 2];
78 84
79 /** 85 /**
80 * The ticket audience (= relying party) 86 * The ticket issuer (= the user)
81 */ 87 */
82 struct GNUNET_IDENTITY_PublicKey audience; 88 //struct GNUNET_CRYPTO_PublicKey identity;
83 89
84 /** 90 /**
85 * The ticket random identifier 91 * The ticket random identifier
86 */ 92 */
87 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];
88}; 102};
89 103
90 104
@@ -95,10 +109,12 @@ struct GNUNET_RECLAIM_Ticket
95 * 109 *
96 * @param cls closure 110 * @param cls closure
97 * @param ticket the ticket 111 * @param ticket the ticket
112 * @param rp_uri the RP URI of the ticket
98 */ 113 */
99typedef void (*GNUNET_RECLAIM_TicketCallback) ( 114typedef void (*GNUNET_RECLAIM_TicketCallback) (
100 void *cls, 115 void *cls,
101 const struct GNUNET_RECLAIM_Ticket *ticket); 116 const struct GNUNET_RECLAIM_Ticket *ticket,
117 const char* rp_uri);
102 118
103/** 119/**
104 * Method called when a token has been issued. 120 * Method called when a token has been issued.
@@ -134,7 +150,7 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
134 * @param attr The attribute 150 * @param attr The attribute
135 */ 151 */
136typedef void (*GNUNET_RECLAIM_AttributeResult) ( 152typedef void (*GNUNET_RECLAIM_AttributeResult) (
137 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 153 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
138 const struct GNUNET_RECLAIM_Attribute *attr); 154 const struct GNUNET_RECLAIM_Attribute *attr);
139 155
140/** 156/**
@@ -146,7 +162,7 @@ typedef void (*GNUNET_RECLAIM_AttributeResult) (
146 * @param presentation The presentation for the credential (may be NULL) 162 * @param presentation The presentation for the credential (may be NULL)
147 */ 163 */
148typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( 164typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
149 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 165 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
150 const struct GNUNET_RECLAIM_Attribute *attr, 166 const struct GNUNET_RECLAIM_Attribute *attr,
151 const struct GNUNET_RECLAIM_Presentation *presentation); 167 const struct GNUNET_RECLAIM_Presentation *presentation);
152 168
@@ -160,7 +176,7 @@ typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
160 * @param attributes the parsed attributes 176 * @param attributes the parsed attributes
161 */ 177 */
162typedef void (*GNUNET_RECLAIM_CredentialResult) ( 178typedef void (*GNUNET_RECLAIM_CredentialResult) (
163 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 179 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
164 const struct GNUNET_RECLAIM_Credential *credential); 180 const struct GNUNET_RECLAIM_Credential *credential);
165 181
166 182
@@ -189,7 +205,7 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
189struct GNUNET_RECLAIM_Operation * 205struct GNUNET_RECLAIM_Operation *
190GNUNET_RECLAIM_attribute_store ( 206GNUNET_RECLAIM_attribute_store (
191 struct GNUNET_RECLAIM_Handle *h, 207 struct GNUNET_RECLAIM_Handle *h,
192 const struct GNUNET_IDENTITY_PrivateKey *pkey, 208 const struct GNUNET_CRYPTO_PrivateKey *pkey,
193 const struct GNUNET_RECLAIM_Attribute *attr, 209 const struct GNUNET_RECLAIM_Attribute *attr,
194 const struct GNUNET_TIME_Relative *exp_interval, 210 const struct GNUNET_TIME_Relative *exp_interval,
195 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 211 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
@@ -210,7 +226,7 @@ GNUNET_RECLAIM_attribute_store (
210struct GNUNET_RECLAIM_Operation * 226struct GNUNET_RECLAIM_Operation *
211GNUNET_RECLAIM_credential_store ( 227GNUNET_RECLAIM_credential_store (
212 struct GNUNET_RECLAIM_Handle *h, 228 struct GNUNET_RECLAIM_Handle *h,
213 const struct GNUNET_IDENTITY_PrivateKey *pkey, 229 const struct GNUNET_CRYPTO_PrivateKey *pkey,
214 const struct GNUNET_RECLAIM_Credential *credential, 230 const struct GNUNET_RECLAIM_Credential *credential,
215 const struct GNUNET_TIME_Relative *exp_interval, 231 const struct GNUNET_TIME_Relative *exp_interval,
216 GNUNET_RECLAIM_ContinuationWithStatus cont, 232 GNUNET_RECLAIM_ContinuationWithStatus cont,
@@ -231,7 +247,7 @@ GNUNET_RECLAIM_credential_store (
231struct GNUNET_RECLAIM_Operation * 247struct GNUNET_RECLAIM_Operation *
232GNUNET_RECLAIM_attribute_delete ( 248GNUNET_RECLAIM_attribute_delete (
233 struct GNUNET_RECLAIM_Handle *h, 249 struct GNUNET_RECLAIM_Handle *h,
234 const struct GNUNET_IDENTITY_PrivateKey *pkey, 250 const struct GNUNET_CRYPTO_PrivateKey *pkey,
235 const struct GNUNET_RECLAIM_Attribute *attr, 251 const struct GNUNET_RECLAIM_Attribute *attr,
236 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 252 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
237 253
@@ -249,7 +265,7 @@ GNUNET_RECLAIM_attribute_delete (
249struct GNUNET_RECLAIM_Operation * 265struct GNUNET_RECLAIM_Operation *
250GNUNET_RECLAIM_credential_delete ( 266GNUNET_RECLAIM_credential_delete (
251 struct GNUNET_RECLAIM_Handle *h, 267 struct GNUNET_RECLAIM_Handle *h,
252 const struct GNUNET_IDENTITY_PrivateKey *pkey, 268 const struct GNUNET_CRYPTO_PrivateKey *pkey,
253 const struct GNUNET_RECLAIM_Credential *cred, 269 const struct GNUNET_RECLAIM_Credential *cred,
254 GNUNET_RECLAIM_ContinuationWithStatus cont, 270 GNUNET_RECLAIM_ContinuationWithStatus cont,
255 void *cont_cls); 271 void *cont_cls);
@@ -281,7 +297,7 @@ GNUNET_RECLAIM_credential_delete (
281struct GNUNET_RECLAIM_AttributeIterator * 297struct GNUNET_RECLAIM_AttributeIterator *
282GNUNET_RECLAIM_get_attributes_start ( 298GNUNET_RECLAIM_get_attributes_start (
283 struct GNUNET_RECLAIM_Handle *h, 299 struct GNUNET_RECLAIM_Handle *h,
284 const struct GNUNET_IDENTITY_PrivateKey *identity, 300 const struct GNUNET_CRYPTO_PrivateKey *identity,
285 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 301 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
286 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, 302 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
287 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 303 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -337,7 +353,7 @@ GNUNET_RECLAIM_get_attributes_stop (
337struct GNUNET_RECLAIM_CredentialIterator * 353struct GNUNET_RECLAIM_CredentialIterator *
338GNUNET_RECLAIM_get_credentials_start ( 354GNUNET_RECLAIM_get_credentials_start (
339 struct GNUNET_RECLAIM_Handle *h, 355 struct GNUNET_RECLAIM_Handle *h,
340 const struct GNUNET_IDENTITY_PrivateKey *identity, 356 const struct GNUNET_CRYPTO_PrivateKey *identity,
341 GNUNET_SCHEDULER_TaskCallback error_cb, 357 GNUNET_SCHEDULER_TaskCallback error_cb,
342 void *error_cb_cls, 358 void *error_cb_cls,
343 GNUNET_RECLAIM_CredentialResult proc, 359 GNUNET_RECLAIM_CredentialResult proc,
@@ -376,7 +392,7 @@ GNUNET_RECLAIM_get_credentials_stop (
376 * 392 *
377 * @param h the identity provider to use 393 * @param h the identity provider to use
378 * @param iss the issuing identity (= the user) 394 * @param iss the issuing identity (= the user)
379 * @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
380 * @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
381 * @param cb the callback 397 * @param cb the callback
382 * @param cb_cls the callback closure 398 * @param cb_cls the callback closure
@@ -385,8 +401,8 @@ GNUNET_RECLAIM_get_credentials_stop (
385struct GNUNET_RECLAIM_Operation * 401struct GNUNET_RECLAIM_Operation *
386GNUNET_RECLAIM_ticket_issue ( 402GNUNET_RECLAIM_ticket_issue (
387 struct GNUNET_RECLAIM_Handle *h, 403 struct GNUNET_RECLAIM_Handle *h,
388 const struct GNUNET_IDENTITY_PrivateKey *iss, 404 const struct GNUNET_CRYPTO_PrivateKey *iss,
389 const struct GNUNET_IDENTITY_PublicKey *rp, 405 const char *rp_uri,
390 const struct GNUNET_RECLAIM_AttributeList *attrs, 406 const struct GNUNET_RECLAIM_AttributeList *attrs,
391 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); 407 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls);
392 408
@@ -407,7 +423,7 @@ GNUNET_RECLAIM_ticket_issue (
407struct GNUNET_RECLAIM_Operation * 423struct GNUNET_RECLAIM_Operation *
408GNUNET_RECLAIM_ticket_revoke ( 424GNUNET_RECLAIM_ticket_revoke (
409 struct GNUNET_RECLAIM_Handle *h, 425 struct GNUNET_RECLAIM_Handle *h,
410 const struct GNUNET_IDENTITY_PrivateKey *identity, 426 const struct GNUNET_CRYPTO_PrivateKey *identity,
411 const struct GNUNET_RECLAIM_Ticket *ticket, 427 const struct GNUNET_RECLAIM_Ticket *ticket,
412 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls); 428 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
413 429
@@ -417,9 +433,8 @@ GNUNET_RECLAIM_ticket_revoke (
417 * information from the issuer 433 * information from the issuer
418 * 434 *
419 * @param h the identity provider to use 435 * @param h the identity provider to use
420 * @param identity the identity that is the subject of the issued ticket (the
421 * relying party)
422 * @param ticket the issued ticket to consume 436 * @param ticket the issued ticket to consume
437 * @param rp_uri the RP URI
423 * @param cb the callback to call 438 * @param cb the callback to call
424 * @param cb_cls the callback closure 439 * @param cb_cls the callback closure
425 * @return handle to abort the operation 440 * @return handle to abort the operation
@@ -427,8 +442,8 @@ GNUNET_RECLAIM_ticket_revoke (
427struct GNUNET_RECLAIM_Operation * 442struct GNUNET_RECLAIM_Operation *
428GNUNET_RECLAIM_ticket_consume ( 443GNUNET_RECLAIM_ticket_consume (
429 struct GNUNET_RECLAIM_Handle *h, 444 struct GNUNET_RECLAIM_Handle *h,
430 const struct GNUNET_IDENTITY_PrivateKey *identity,
431 const struct GNUNET_RECLAIM_Ticket *ticket, 445 const struct GNUNET_RECLAIM_Ticket *ticket,
446 const char *rp_uri,
432 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); 447 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
433 448
434 449
@@ -452,7 +467,7 @@ GNUNET_RECLAIM_ticket_consume (
452struct GNUNET_RECLAIM_TicketIterator * 467struct GNUNET_RECLAIM_TicketIterator *
453GNUNET_RECLAIM_ticket_iteration_start ( 468GNUNET_RECLAIM_ticket_iteration_start (
454 struct GNUNET_RECLAIM_Handle *h, 469 struct GNUNET_RECLAIM_Handle *h,
455 const struct GNUNET_IDENTITY_PrivateKey *identity, 470 const struct GNUNET_CRYPTO_PrivateKey *identity,
456 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 471 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
457 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, 472 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
458 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 473 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -499,44 +514,6 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
499void 514void
500GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); 515GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
501 516
502/**
503 * Get serialized ticket size
504 *
505 * @param tkt the ticket
506 * @return the buffer length requirement for a serialization
507 */
508size_t
509GNUNET_RECLAIM_ticket_serialize_get_size (const struct GNUNET_RECLAIM_Ticket *tkt);
510
511/**
512 * Deserializes a ticket
513 *
514 * @param buffer the buffer to read from
515 * @param len the length of the buffer
516 * @param tkt the ticket to write to (must be allocated)
517 * @param kb_read how many bytes were read from buffer
518 * @return GNUNET_SYSERR on error
519 */
520enum GNUNET_GenericReturnValue
521GNUNET_RECLAIM_read_ticket_from_buffer (const void *buffer,
522 size_t len,
523 struct GNUNET_RECLAIM_Ticket *tkt,
524 size_t *tb_read);
525
526/**
527 * Serializes a ticket
528 *
529 * @param tkt the ticket to serialize
530 * @param buffer the buffer to serialize to (must be allocated with sufficient size
531 * @param len the length of the buffer
532 * @return the number of written bytes or < 0 on error
533 */
534ssize_t
535GNUNET_RECLAIM_write_ticket_to_buffer (const struct
536 GNUNET_RECLAIM_Ticket *tkt,
537 void *buffer,
538 size_t len);
539
540#if 0 /* keep Emacsens' auto-indent happy */ 517#if 0 /* keep Emacsens' auto-indent happy */
541{ 518{
542#endif 519#endif
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index 45b391ca1..3a8af5389 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -63,24 +63,13 @@ struct GNUNET_REST_Plugin
63 * e.g. http://hostname:port/name 63 * e.g. http://hostname:port/name
64 */ 64 */
65 char *name; 65 char *name;
66
67 /**
68 * Function to process a REST call
69 *
70 * @param method the HTTP method called
71 * @param url the relative url accessed
72 * @param data the REST data (can be NULL)
73 * @param data_size the length of the data
74 * @param proc the callback for result
75 * @param proc_cls closure for callback
76 * @return GNUNET_YES if the request was processed
77 */
78 enum GNUNET_GenericReturnValue (*process_request)(
79 struct GNUNET_REST_RequestHandle *handle,
80 GNUNET_REST_ResultProcessor proc,
81 void *proc_cls);
82}; 66};
83 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);
84 73
85#if 0 /* keep Emacsens' auto-indent happy */ 74#if 0 /* keep Emacsens' auto-indent happy */
86{ 75{
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h
index 81a90189b..427be62ac 100644
--- a/src/include/gnunet_revocation_service.h
+++ b/src/include/gnunet_revocation_service.h
@@ -22,6 +22,7 @@
22#define GNUNET_REVOCATION_SERVICE_H_ 22#define GNUNET_REVOCATION_SERVICE_H_
23 23
24 24
25#include "gnunet_gnsrecord_lib.h"
25#include "gnunet_identity_service.h" 26#include "gnunet_identity_service.h"
26 27
27/** 28/**
@@ -56,71 +57,6 @@ extern "C"
56 */ 57 */
57#define GNUNET_REVOCATION_VERSION 0x00000001 58#define GNUNET_REVOCATION_VERSION 0x00000001
58 59
59/**
60 * Maximum length of a revocation
61 */
62#define GNUNET_REVOCATION_MAX_PROOF_SIZE sizeof(struct GNUNET_REVOCATION_PowP) +\
63 sizeof(struct GNUNET_IDENTITY_PublicKey) +\
64 1024 //FIXME max sig_len
65
66/**
67 * The proof-of-work narrowing factor.
68 * The number of PoWs that are calculates as part of revocation.
69 */
70#define POW_COUNT 32
71
72
73GNUNET_NETWORK_STRUCT_BEGIN
74
75/**
76 * Struct for a proof of work as part of the revocation.
77 */
78struct GNUNET_REVOCATION_PowP
79{
80 /**
81 * The timestamp of the revocation
82 */
83 struct GNUNET_TIME_AbsoluteNBO timestamp;
84
85 /**
86 * The TTL of this revocation (purely informational)
87 */
88 struct GNUNET_TIME_RelativeNBO ttl;
89
90 /**
91 * The PoWs
92 */
93 uint64_t pow[POW_COUNT] GNUNET_PACKED;
94
95 /** followed by the public key type, the key and a signature **/
96};
97
98
99/**
100 * The signature object we use for the PoW
101 */
102struct GNUNET_REVOCATION_SignaturePurposePS
103{
104 /**
105 * The signature purpose
106 */
107 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
108
109 /**
110 * The timestamp of the revocation
111 */
112 struct GNUNET_TIME_AbsoluteNBO timestamp;
113
114 /** Followed by the zone public key type and key **/
115};
116
117GNUNET_NETWORK_STRUCT_END
118
119
120/**
121 * Handle to a running proof-of-work calculation.
122 */
123struct GNUNET_REVOCATION_PowCalculationHandle;
124 60
125/** 61/**
126 * Handle for the key revocation query. 62 * Handle for the key revocation query.
@@ -152,7 +88,7 @@ typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
152 */ 88 */
153struct GNUNET_REVOCATION_Query * 89struct GNUNET_REVOCATION_Query *
154GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, 90GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
155 const struct GNUNET_IDENTITY_PublicKey *key, 91 const struct GNUNET_CRYPTO_PublicKey *key,
156 GNUNET_REVOCATION_Callback func, void *func_cls); 92 GNUNET_REVOCATION_Callback func, void *func_cls);
157 93
158 94
@@ -176,7 +112,7 @@ struct GNUNET_REVOCATION_Handle;
176 * 112 *
177 * @param cfg the configuration to use 113 * @param cfg the configuration to use
178 * @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
179 * iteratively calling #GNUNET_REVOCATION_pow_round) 115 * iteratively calling #GNUNET_CRYPTO_pow_round)
180 * @param func function to call with the result of the check 116 * @param func function to call with the result of the check
181 * (called with `is_valid` being #GNUNET_NO if 117 * (called with `is_valid` being #GNUNET_NO if
182 * the revocation worked). 118 * the revocation worked).
@@ -185,7 +121,7 @@ struct GNUNET_REVOCATION_Handle;
185 */ 121 */
186struct GNUNET_REVOCATION_Handle * 122struct GNUNET_REVOCATION_Handle *
187GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, 123GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
188 const struct GNUNET_REVOCATION_PowP *pow, 124 const struct GNUNET_GNSRECORD_PowP *pow,
189 GNUNET_REVOCATION_Callback func, void *func_cls); 125 GNUNET_REVOCATION_Callback func, void *func_cls);
190 126
191 127
@@ -198,68 +134,6 @@ void
198GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h); 134GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
199 135
200 136
201/**
202 * Check if the given proof-of-work is valid.
203 *
204 * @param pow proof of work
205 * @param matching_bits how many bits must match (configuration)
206 * @param epoch_duration length of single epoch in configuration
207 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
208 */
209enum GNUNET_GenericReturnValue
210GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
211 unsigned int matching_bits,
212 struct GNUNET_TIME_Relative epoch_duration);
213
214
215/**
216 * Initializes a fresh PoW computation.
217 *
218 * @param key the key to calculate the PoW for.
219 * @param pow the pow object to work with in the calculation.
220 */
221void
222GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key,
223 struct GNUNET_REVOCATION_PowP *pow);
224
225
226/**
227 * Starts a proof-of-work calculation given the pow object as well as
228 * target epochs and difficulty.
229 *
230 * @param pow the PoW to based calculations on.
231 * @param epochs the number of epochs for which the PoW must be valid.
232 * @param difficulty the base difficulty of the PoW.
233 * @return a handle for use in PoW rounds
234 */
235struct GNUNET_REVOCATION_PowCalculationHandle*
236GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
237 int epochs,
238 unsigned int difficulty);
239
240
241/**
242 * Calculate a single round in the key revocation PoW.
243 *
244 * @param pc handle to the PoW, initially called with NULL.
245 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
246 */
247enum GNUNET_GenericReturnValue
248GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
249
250
251/**
252 * Stop a PoW calculation
253 *
254 * @param pc the calculation to clean up
255 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
256 * valid
257 */
258void
259GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
260
261size_t
262GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow);
263 137
264 138
265#if 0 /* keep Emacsens' auto-indent happy */ 139#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index 7c6ce0c0e..0ad4fcc3c 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21 21
22#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly." 23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif 24#endif
25 25
@@ -203,7 +203,6 @@ GNUNET_SERVICE_start (const char *service_name,
203void 203void
204GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv); 204GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv);
205 205
206
207/** 206/**
208 * Creates the "main" function for a GNUnet service. You 207 * Creates the "main" function for a GNUnet service. You
209 * should almost always use the #GNUNET_SERVICE_MAIN macro 208 * should almost always use the #GNUNET_SERVICE_MAIN macro
@@ -258,6 +257,56 @@ GNUNET_SERVICE_run_ (int argc,
258 257
259 258
260/** 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/**
261 * Creates the "main" function for a GNUnet service. You 310 * Creates the "main" function for a GNUnet service. You
262 * MUST use this macro to define GNUnet services (except 311 * MUST use this macro to define GNUnet services (except
263 * for ARM, which MUST NOT use the macro). The reason is 312 * for ARM, which MUST NOT use the macro). The reason is
@@ -314,26 +363,51 @@ GNUNET_SERVICE_run_ (int argc,
314 * GNUNET_MQ_handler_end ()); 363 * GNUNET_MQ_handler_end ());
315 * </code> 364 * </code>
316 */ 365 */
366#ifndef HAVE_GNUNET_MONOLITH
317#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ 367#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
318 disconnect_cb, cls, ...) \ 368 disconnect_cb, cls, ...) \
319 int \ 369 int \
320 main (int argc, \ 370 main (int argc, \
321 char *const *argv) \ 371 char *const *argv) \
322 { \ 372 { \
323 struct GNUNET_MQ_MessageHandler mh[] = { \ 373 struct GNUNET_MQ_MessageHandler mh[] = { \
324 __VA_ARGS__ \ 374 __VA_ARGS__ \
325 }; \ 375 }; \
326 return GNUNET_SERVICE_run_ (argc, \ 376 return GNUNET_SERVICE_run_ (argc, \
327 argv, \ 377 argv, \
328 service_name, \ 378 service_name, \
329 service_options, \ 379 service_options, \
330 init_cb, \ 380 init_cb, \
331 connect_cb, \ 381 connect_cb, \
332 disconnect_cb, \ 382 disconnect_cb, \
333 cls, \ 383 cls, \
334 mh); \ 384 mh); \
335 } 385 }
386#else
387#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
388 disconnect_cb, cls, ...) \
389 static int __attribute__ ((constructor)) \
390 init (void) \
391 { \
392 struct GNUNET_MQ_MessageHandler mh[] = { \
393 __VA_ARGS__ \
394 }; \
395 return GNUNET_SERVICE_register_ (service_name, \
396 service_options, \
397 init_cb, \
398 connect_cb, \
399 disconnect_cb, \
400 cls, \
401 mh); \
402 }
403#endif
336 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);
337 411
338/** 412/**
339 * Suspend accepting connections from the listen socket temporarily. 413 * Suspend accepting connections from the listen socket temporarily.
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
new file mode 100644
index 000000000..6ec30bf71
--- /dev/null
+++ b/src/include/gnunet_signatures.h
@@ -0,0 +1,254 @@
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_SIGNATURES_H
21#define GNUNET_SIGNATURES_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add a signature purpose, 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
33
34#ifdef __cplusplus
35extern "C" {
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41
42/**
43 * Network signature purpose definitions. Note that all values
44 * must be uint32_t and encoded in network byte order in the structs.
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)
51 */
52#define GNUNET_SIGNATURE_PURPOSE_TEST 0
53
54
55/**
56 * Signature for confirming that this peer uses a particular address. (GNUnet-TRANSPORT)
57 */
58#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1
59
60
61/**
62 * Signature for confirming that this peer intends to disconnect. (GNUnet-TRANSPORT)
63 */
64#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2
65
66
67/**
68 * GNS zone key revocation (GNS)
69 */
70#define GNUNET_SIGNATURE_PURPOSE_GNS_REVOCATION 3
71
72
73/**
74 * Signature for a namespace/pseudonym advertisement (by the namespace owner). (GNUnet-FS)
75 */
76#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4
77
78
79/**
80 * Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation URIs. (GNUnet-FS)
81 */
82#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5
83
84
85/**
86 * Signature by which a peer affirms that it forwarded a message in the DHT. (GNUnet-DHT)
87 */
88#define GNUNET_SIGNATURE_PURPOSE_DHT_HOP 6
89
90
91/**
92 * Signature by which a peer affirms its address. (GNUnet-HELLO)
93 */
94#define GNUNET_SIGNATURE_PURPOSE_HELLO 7
95
96
97/**
98 * Signature on a GNUNET_DNS_Advertisement. (GNUnet-DNS+Exit)
99 */
100#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11
101
102
103/**
104 * Signature of a chat message. (GNUnet-MESSENGER)
105 */
106#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12
107
108
109/**
110 * Signature of confirmation receipt for a chat message. (GNUnet-MESSENGER)
111 */
112#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13
113
114
115/**
116 * Signature of a network size estimate message. (GNUnet-NSE)
117 */
118#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14
119
120
121/**
122 * GNS record set signature (GNS)
123 */
124#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15
125
126
127/**
128 * Purpose is to set a session key. (GNUnet-CORE)
129 */
130#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16
131
132
133/**
134 * UBlock Signature, done using DSS, not ECC (GNUnet-FS)
135 */
136#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17
137
138
139/**
140 * Accept state in regex DFA. Peer affirms that it offers the matching service. (GNUnet-REGEX)
141 */
142#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18
143
144
145/**
146 * Signature of a conversation ring. (GNUnet-CONVERSATION)
147 */
148#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20
149
150
151/**
152 * Signature for the first round of distributed key generation. (GNUnet-SECRETSHARING)
153 */
154#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21
155
156
157/**
158 * Signature for the second round of distributed key generation. (GNUnet-SECRETSHARING)
159 */
160#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
161
162
163/**
164 * Signature for the cooperative decryption. (GNUnet-SECRETSHARING)
165 */
166#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DECRYPTION 23
167
168
169/**
170 * Signature for a GNUid Ticket (Reclaim)
171 */
172#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27
173
174
175/**
176 * Signature for a GNUnet credential (Reclaim)
177 */
178#define GNUNET_SIGNATURE_PURPOSE_DELEGATE 28
179
180
181/**
182 * Signature by a peer affirming that this is one of its addresses for the given time period. (GNUnet-TRANSPORT)
183 */
184#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29
185
186
187/**
188 * Signature by a peer affirming that the given ephemeral key is currently in use by that peer's transport service. (GNUnet-TRANSPORT)
189 */
190#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30
191
192
193/**
194 * Signature used by TCP communicator handshake. (GNUnet-TRANSPORT-TCP)
195 */
196#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE 31
197
198
199/**
200 * Signature used by TCP communicator rekey. (GNUnet-TRANSPORT-TCP)
201 */
202#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY 32
203
204
205/**
206 * Signature used by UDP communicator handshake. (GNUnet-TRANSPORT-UDP)
207 */
208#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE 33
209
210
211/**
212 * Signature used by UDP broadcasts. (GNUnet-TRANSPORT-UDP)
213 */
214#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST 34
215
216
217/**
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)
219 */
220#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 35
221
222
223/**
224 * Signature by a peer affirming that it is on a DV path. (GNUnet-TRANSPORT)
225 */
226#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 36
227
228
229/**
230 * Signature by a peer affirming that it originated the DV path. (GNUnet-TRANSPORT)
231 */
232#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37
233
234
235/**
236 * Signature by a peer that like to create a connection. (GNUnet-CADET)
237 */
238#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38
239
240
241/**
242 * Signature by a peer sending back the nonce received at initial handshake. (GNUnet-TRANSPORT-TCP)
243 */
244#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK 39
245
246
247#if 0 /* keep Emacsens' auto-indent happy */
248{
249#endif
250#ifdef __cplusplus
251}
252#endif
253
254#endif
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index b751ef044..df70c5e8f 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -18,7 +18,7 @@
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__) 21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly." 22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif 23#endif
24 24
@@ -41,7 +41,7 @@
41 * @{ 41 * @{
42 */ 42 */
43 43
44#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 44#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
45#error "Only <gnunet_util_lib.h> can be included directly." 45#error "Only <gnunet_util_lib.h> can be included directly."
46#endif 46#endif
47 47
@@ -410,6 +410,10 @@ GNUNET_STRINGS_base64_encode (const void *in,
410/** 410/**
411 * url/percent encode (RFC3986). 411 * url/percent encode (RFC3986).
412 * 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 *
413 * @param data the data to decode 417 * @param data the data to decode
414 * @param len the length of the input 418 * @param len the length of the input
415 * @param out where to write the output (*out should be NULL, 419 * @param out where to write the output (*out should be NULL,
@@ -417,8 +421,8 @@ GNUNET_STRINGS_base64_encode (const void *in,
417 * @return the size of the output 421 * @return the size of the output
418 */ 422 */
419size_t 423size_t
420GNUNET_STRINGS_urlencode (const char *data, 424GNUNET_STRINGS_urlencode (size_t len,
421 size_t len, 425 const char data[static len],
422 char **out); 426 char **out);
423 427
424 428
@@ -578,7 +582,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
578 */ 582 */
579enum GNUNET_GenericReturnValue 583enum GNUNET_GenericReturnValue
580GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 584GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
581 uint16_t addrlen, 585 size_t addrlen,
582 struct sockaddr_in6 *r_buf); 586 struct sockaddr_in6 *r_buf);
583 587
584 588
@@ -594,7 +598,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
594 */ 598 */
595enum GNUNET_GenericReturnValue 599enum GNUNET_GenericReturnValue
596GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 600GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
597 uint16_t addrlen, 601 size_t addrlen,
598 struct sockaddr_in *r_buf); 602 struct sockaddr_in *r_buf);
599 603
600 604
@@ -670,6 +674,23 @@ GNUNET_strlcpy (char *dst,
670 size_t n); 674 size_t n);
671 675
672 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
673/* ***************** IPv4/IPv6 parsing ****************** */ 694/* ***************** IPv4/IPv6 parsing ****************** */
674 695
675struct GNUNET_STRINGS_PortPolicy 696struct GNUNET_STRINGS_PortPolicy
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 7ab943b15..000000000
--- a/src/include/gnunet_testbed_logger_service.h
+++ /dev/null
@@ -1,139 +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 * @addtogroup Testing
23 * @{
24 *
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 *
27 * @file
28 * API for submitting data to the testbed logger service
29 *
30 * @defgroup testbed-logger Testbed Logger service
31 * Submit data to the testbed logger service.
32 * @{
33 */
34
35#ifndef GNUNET_TESTBED_LOGGER_SERVICE_H
36#define GNUNET_TESTBED_LOGGER_SERVICE_H
37
38#ifdef __cplusplus
39extern "C"
40{
41#if 0 /* keep Emacsens' auto-indent happy */
42}
43#endif
44#endif
45
46
47#include "gnunet_util_lib.h"
48
49/**
50 * Opaque handle for the logging service
51 */
52struct GNUNET_TESTBED_LOGGER_Handle;
53
54
55/**
56 * Connect to the testbed logger service
57 *
58 * @param cfg configuration to use
59 * @return the handle which can be used for sending data to the service; NULL
60 * upon any error
61 */
62struct GNUNET_TESTBED_LOGGER_Handle *
63GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
64
65
66/**
67 * Disconnect from the logger service. Also cancels any pending send handles.
68 *
69 * @param h the logger handle
70 */
71void
72GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h);
73
74
75/**
76 * Functions of this type are called to notify a successful transmission of the
77 * message to the logger service.
78 *
79 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
80 * @param size the amount of data sent
81 */
82typedef void
83(*GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls,
84 size_t size);
85
86
87/**
88 * Send data to be logged to the logger service. The data will be buffered and
89 * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon
90 * exceeding a threshold size.
91 *
92 * @param h the logger handle
93 * @param data the data to send;
94 * @param size how many bytes of @a data to send
95 */
96void
97GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h,
98 const void *data,
99 size_t size);
100
101
102/**
103 * Flush the buffered data to the logger service
104 *
105 * @param h the logger handle
106 * @param cb the callback to call after the data is flushed
107 * @param cb_cls the closure for @a cb
108 */
109void
110GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
111 GNUNET_TESTBED_LOGGER_FlushCompletion cb,
112 void *cb_cls);
113
114
115/**
116 * Cancel notification upon flush. Should only be used when the flush
117 * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already
118 * called.
119 *
120 * @param h the logger handle
121 */
122void
123GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h);
124
125
126#if 0 /* keep Emacsens' auto-indent happy */
127{
128#endif
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* GNUNET_TESTBED_LOGGER_SERVICE_H */
134
135/** @} */ /* end of group */
136
137/** @} */ /* end of group addition */
138
139/* 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 acd87e2cd..000000000
--- a/src/include/gnunet_testbed_service.h
+++ /dev/null
@@ -1,1735 +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 * @addtogroup Testing
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * API for writing tests and creating large-scale emulation testbeds for GNUnet.
29 *
30 * @defgroup testbed Testbed service
31 * Writing tests and creating large-scale emulation testbeds for GNUnet.
32 *
33 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-Subsystem)
34 *
35 * @{
36 */
37
38#ifndef GNUNET_TESTBED_SERVICE_H
39#define GNUNET_TESTBED_SERVICE_H
40
41
42#include "gnunet_util_lib.h"
43#include "gnunet_testing_lib.h"
44
45#ifdef __cplusplus
46extern "C"
47{
48#if 0 /* keep Emacsens' auto-indent happy */
49}
50#endif
51#endif
52
53
54/**
55 * Opaque handle to a host running experiments managed by the testbed framework.
56 * The master process must be able to SSH to this host without password (via
57 * ssh-agent).
58 */
59struct GNUNET_TESTBED_Host;
60
61/**
62 * Opaque handle to a peer controlled by the testbed framework. A peer runs
63 * at a particular host.
64 */
65struct GNUNET_TESTBED_Peer;
66
67/**
68 * Opaque handle to an abstract operation to be executed by the testbed framework.
69 */
70struct GNUNET_TESTBED_Operation;
71
72/**
73 * Handle to interact with a GNUnet testbed controller. Each
74 * controller has at least one master handle which is created when the
75 * controller is created; this master handle interacts with the
76 * controller process, destroying it destroys the controller (by
77 * closing stdin of the controller process). Additionally,
78 * controllers can interact with each other (in a P2P fashion); those
79 * links are established via TCP/IP on the controller's service port.
80 */
81struct GNUNET_TESTBED_Controller;
82
83
84/**
85 * Create a host to run peers and controllers on.
86 *
87 * @param hostname name of the host, use "NULL" for localhost
88 * @param username username to use for the login; may be NULL
89 * @param cfg the configuration to use as a template while starting a controller
90 * on this host. Operation queue sizes specific to a host are also
91 * read from this configuration handle
92 * @param port port number to use for ssh; use 0 to let ssh decide
93 * @return handle to the host, NULL on error
94 */
95struct GNUNET_TESTBED_Host *
96GNUNET_TESTBED_host_create (const char *hostname,
97 const char *username,
98 const struct GNUNET_CONFIGURATION_Handle *cfg,
99 uint16_t port);
100
101
102/**
103 * Create a host to run peers and controllers on. This function is used
104 * if a peer learns about a host via IPC between controllers (and thus
105 * some higher-level controller has already determined the unique IDs).
106 *
107 * @param id global host ID assigned to the host; 0 is
108 * reserved to always mean 'localhost'
109 * @param hostname name of the host, use "NULL" for localhost
110 * @param username username to use for the login; may be NULL
111 * @param cfg the configuration to use as a template while starting a controller
112 * on this host. Operation queue sizes specific to a host are also
113 * read from this configuration handle
114 * @param port port number to use for ssh; use 0 to let ssh decide
115 * @return handle to the host, NULL on error
116 */
117struct GNUNET_TESTBED_Host *
118GNUNET_TESTBED_host_create_with_id (uint32_t id,
119 const char *hostname,
120 const char *username,
121 const struct GNUNET_CONFIGURATION_Handle
122 *cfg,
123 uint16_t port);
124
125
126/**
127 * Load a set of hosts from a configuration file. The hostfile format is
128 * specified at https://gnunet.org/content/hosts-file-format
129 *
130 * @param filename file with the host specification
131 * @param cfg the configuration to use as a template while starting a controller
132 * on any of the loaded hosts. Operation queue sizes specific to a host
133 * are also read from this configuration handle
134 * @param hosts set to the hosts found in the file; caller must free this if
135 * number of hosts returned is greater than 0
136 * @return number of hosts returned in 'hosts', 0 on error
137 */
138unsigned int
139GNUNET_TESTBED_hosts_load_from_file (const char *filename,
140 const struct GNUNET_CONFIGURATION_Handle
141 *cfg,
142 struct GNUNET_TESTBED_Host ***hosts);
143
144
145/**
146 * Destroy a host handle. Must only be called once everything
147 * running on that host has been stopped.
148 *
149 * @param host handle to destroy
150 */
151void
152GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
153
154
155/**
156 * The handle for whether a host is habitable or not
157 */
158struct GNUNET_TESTBED_HostHabitableCheckHandle;
159
160
161/**
162 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
163 * inform whether the given host is habitable or not. The Handle returned by
164 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
165 *
166 * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
167 * @param host the host whose status is being reported; will be NULL if the host
168 * given to GNUNET_TESTBED_is_host_habitable() is NULL
169 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
170 */
171typedef void
172(*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
173 const struct GNUNET_TESTBED_Host *host,
174 int status);
175
176
177/**
178 * Checks whether a host can be used to start testbed service
179 *
180 * @param host the host to check
181 * @param config the configuration handle to lookup the path of the testbed
182 * helper
183 * @param cb the callback to call to inform about habitability of the given host
184 * @param cb_cls the closure for the callback
185 * @return NULL upon any error or a handle which can be passed to
186 * GNUNET_TESTBED_is_host_habitable_cancel()
187 */
188struct GNUNET_TESTBED_HostHabitableCheckHandle *
189GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
190 const struct GNUNET_CONFIGURATION_Handle
191 *config,
192 GNUNET_TESTBED_HostHabitableCallback cb,
193 void *cb_cls);
194
195
196/**
197 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
198 *
199 * @param handle the habitability check handle
200 */
201void
202GNUNET_TESTBED_is_host_habitable_cancel (struct
203 GNUNET_TESTBED_HostHabitableCheckHandle
204 *handle);
205
206/**
207 * Obtain the host's hostname.
208 *
209 * @param host handle to the host, NULL means 'localhost'
210 * @return hostname of the host
211 */
212const char *
213GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
214
215
216/**
217 * Enumeration with (at most 64) possible event types that
218 * can be monitored using the testbed framework.
219 */
220enum GNUNET_TESTBED_EventType
221{
222 /**
223 * A peer has been started.
224 */
225 GNUNET_TESTBED_ET_PEER_START = 0,
226
227 /**
228 * A peer has been stopped.
229 */
230 GNUNET_TESTBED_ET_PEER_STOP = 1,
231
232 /**
233 * A connection between two peers was established.
234 */
235 GNUNET_TESTBED_ET_CONNECT = 2,
236
237 /**
238 * A connection between two peers was torn down.
239 */
240 GNUNET_TESTBED_ET_DISCONNECT = 3,
241
242 /**
243 * A requested testbed operation has been completed.
244 */
245 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
246};
247
248
249/**
250 * Types of information that can be requested about a peer.
251 */
252enum GNUNET_TESTBED_PeerInformationType
253{
254 /**
255 * Special value (not valid for requesting information)
256 * that is used in the event struct if a 'generic' pointer
257 * is returned (for other operations not related to this
258 * enumeration).
259 */
260 GNUNET_TESTBED_PIT_GENERIC = 0,
261
262 /**
263 * What configuration is the peer using? Returns a 'const struct
264 * GNUNET_CONFIGURATION_Handle *'. Valid until
265 * 'GNUNET_TESTNIG_operation_done' is called. However, the
266 * values may be inaccurate if the peer is reconfigured in
267 * the meantime.
268 */
269 GNUNET_TESTBED_PIT_CONFIGURATION,
270
271 /**
272 * What is the identity of the peer? Returns a
273 * 'const struct GNUNET_PeerIdentity *'. Valid until
274 * 'GNUNET_TESTNIG_operation_done' is called.
275 */
276 GNUNET_TESTBED_PIT_IDENTITY
277};
278
279
280/**
281 * Argument to GNUNET_TESTBED_ControllerCallback with details about
282 * the event.
283 */
284struct GNUNET_TESTBED_EventInformation
285{
286 /**
287 * Type of the event.
288 */
289 enum GNUNET_TESTBED_EventType type;
290
291 /**
292 * Handle for the corresponding operation that generated this event
293 */
294 struct GNUNET_TESTBED_Operation *op;
295
296 /**
297 * Closure given while creating the above operation
298 */
299 void *op_cls;
300
301 /**
302 * Details about the event.
303 */
304 union
305 {
306 /**
307 * Details about peer start event.
308 */
309 struct
310 {
311 /**
312 * Handle for the host where the peer
313 * was started.
314 */
315 struct GNUNET_TESTBED_Host *host;
316
317 /**
318 * Handle for the peer that was started.
319 */
320 struct GNUNET_TESTBED_Peer *peer;
321 } peer_start;
322
323 /**
324 * Details about peer stop event.
325 */
326 struct
327 {
328 /**
329 * Handle for the peer that was started.
330 */
331 struct GNUNET_TESTBED_Peer *peer;
332 } peer_stop;
333
334 /**
335 * Details about connect event.
336 */
337 struct
338 {
339 /**
340 * Handle for one of the connected peers.
341 */
342 struct GNUNET_TESTBED_Peer *peer1;
343
344 /**
345 * Handle for one of the connected peers.
346 */
347 struct GNUNET_TESTBED_Peer *peer2;
348 } peer_connect;
349
350 /**
351 * Details about disconnect event.
352 */
353 struct
354 {
355 /**
356 * Handle for one of the disconnected peers.
357 */
358 struct GNUNET_TESTBED_Peer *peer1;
359
360 /**
361 * Handle for one of the disconnected peers.
362 */
363 struct GNUNET_TESTBED_Peer *peer2;
364 } peer_disconnect;
365
366 /**
367 * Details about an operation finished event.
368 */
369 struct
370 {
371 /**
372 * Error message for the operation, NULL on success.
373 */
374 const char *emsg;
375
376 /**
377 * No result (NULL pointer) or generic result
378 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
379 */
380 void *generic;
381 } operation_finished;
382 } details;
383};
384
385
386/**
387 * Signature of the event handler function called by the
388 * respective event controller.
389 *
390 * @param cls closure
391 * @param event information about the event
392 */
393typedef void
394(*GNUNET_TESTBED_ControllerCallback)(void *cls,
395 const struct
396 GNUNET_TESTBED_EventInformation *event);
397
398
399/**
400 * Opaque Handle for Controller process
401 */
402struct GNUNET_TESTBED_ControllerProc;
403
404
405/**
406 * Callback to signal successful startup of the controller process
407 *
408 * @param cls the closure from GNUNET_TESTBED_controller_start()
409 * @param cfg the configuration with which the controller has been started;
410 * NULL if status is not #GNUNET_OK
411 * @param status #GNUNET_OK if the startup is successful; #GNUNET_SYSERR if not,
412 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
413 */
414typedef void
415(*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
416 const struct
417 GNUNET_CONFIGURATION_Handle *cfg,
418 int status);
419
420
421/**
422 * Starts a controller process at the given host. The given host's configuration
423 * is used as a Template configuration to use for the remote controller; the
424 * remote controller will be started with a slightly modified configuration
425 * (port numbers, unix domain sockets and service home values are changed as per
426 * TESTING library on the remote host). The modified configuration replaces the
427 * host's existing configuration before signalling success through the
428 * GNUNET_TESTBED_ControllerStatusCallback()
429 *
430 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
431 * HOST(all connections form this ip are permitted by the testbed) when
432 * starting testbed controller at host. This can either be a single ip
433 * address or a network address in CIDR notation.
434 * @param host the host where the controller has to be started. CANNOT be NULL.
435 * @param cb function called when the controller is successfully started or
436 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
437 * called if cb is called with GNUNET_SYSERR as status. Will never be
438 * called in the same task as 'GNUNET_TESTBED_controller_start'
439 * (synchronous errors will be signalled by returning NULL). This
440 * parameter cannot be NULL.
441 * @param cls closure for above callbacks
442 * @return the controller process handle, NULL on errors
443 */
444struct GNUNET_TESTBED_ControllerProc *
445GNUNET_TESTBED_controller_start (const char *trusted_ip,
446 struct GNUNET_TESTBED_Host *host,
447 GNUNET_TESTBED_ControllerStatusCallback cb,
448 void *cls);
449
450
451/**
452 * Stop the controller process (also will terminate all peers and controllers
453 * dependent on this controller). This function blocks until the testbed has
454 * been fully terminated (!). The controller status cb from
455 * GNUNET_TESTBED_controller_start() will not be called.
456 *
457 * @param cproc the controller process handle
458 */
459void
460GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
461
462
463/**
464 * Connect to a controller process. The configuration to use for the connection
465 * is retrieved from the given host where a controller is started using
466 * GNUNET_TESTBED_controller_start().
467 *
468 * @param host host to run the controller on; This should be the same host if
469 * the controller was previously started with
470 * GNUNET_TESTBED_controller_start()
471 * @param event_mask bit mask with set of events to call 'cc' for;
472 * or-ed values of "1LL" shifted by the
473 * respective 'enum GNUNET_TESTBED_EventType'
474 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
475 * @param cc controller callback to invoke on events
476 * @param cc_cls closure for cc
477 * @return handle to the controller
478 */
479struct GNUNET_TESTBED_Controller *
480GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
481 uint64_t event_mask,
482 GNUNET_TESTBED_ControllerCallback cc,
483 void *cc_cls);
484
485
486/**
487 * Stop the given controller (also will terminate all peers and
488 * controllers dependent on this controller). This function
489 * blocks until the testbed has been fully terminated (!).
490 *
491 * @param c handle to controller to stop
492 */
493void
494GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
495
496
497/**
498 * Opaque handle for host registration
499 */
500struct GNUNET_TESTBED_HostRegistrationHandle;
501
502
503/**
504 * Callback which will be called to after a host registration succeeded or failed
505 *
506 * @param cls the closure
507 * @param emsg the error message; NULL if host registration is successful
508 */
509typedef void
510(*GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
511 const char *emsg);
512
513
514/**
515 * Register a host with the controller. This makes the controller aware of the
516 * host. A host should be registered at the controller before starting a
517 * sub-controller on that host using GNUNET_TESTBED_controller_link().
518 *
519 * @param controller the controller handle
520 * @param host the host to register
521 * @param cc the completion callback to call to inform the status of
522 * registration. After calling this callback the registration handle
523 * will be invalid. Cannot be NULL
524 * @param cc_cls the closure for the cc
525 * @return handle to the host registration which can be used to cancel the
526 * registration; NULL if another registration handle is present and
527 * is not cancelled
528 */
529struct GNUNET_TESTBED_HostRegistrationHandle *
530GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
531 struct GNUNET_TESTBED_Host *host,
532 GNUNET_TESTBED_HostRegistrationCompletion cc,
533 void *cc_cls);
534
535
536/**
537 * Cancel the pending registration. Note that the registration message will
538 * already be queued to be sent to the service, cancellation has only the
539 * effect that the registration completion callback for the registration is
540 * never called and from our perspective the host is not registered until the
541 * completion callback is called.
542 *
543 * @param handle the registration handle to cancel
544 */
545void
546GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
547 *handle);
548
549
550/**
551 * Callback to be called when an operation is completed
552 *
553 * @param cls the callback closure from functions generating an operation
554 * @param op the operation that has been finished
555 * @param emsg error message in case the operation has failed; will be NULL if
556 * operation has executed successfully.
557 */
558typedef void
559(*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
560 struct GNUNET_TESTBED_Operation *
561 op,
562 const char *emsg);
563
564
565/**
566 * Create a link from slave controller to delegated controller. Whenever the
567 * master controller is asked to start a peer at the delegated controller the
568 * request will be routed towards slave controller (if a route exists). The
569 * slave controller will then route it to the delegated controller. The
570 * configuration of the delegated controller is given and is used to either
571 * create the delegated controller or to connect to an existing controller. Note
572 * that while starting the delegated controller the configuration will be
573 * modified to accommodate available free ports. the 'is_subordinate' specifies
574 * if the given delegated controller should be started and managed by the slave
575 * controller, or if the delegated controller already has a master and the slave
576 * controller connects to it as a non master controller. The success or failure
577 * of this operation will be signalled through the
578 * GNUNET_TESTBED_ControllerCallback() with an event of type
579 * #GNUNET_TESTBED_ET_OPERATION_FINISHED
580 *
581 * @param op_cls the operation closure for the event which is generated to
582 * signal success or failure of this operation
583 * @param master handle to the master controller who creates the association
584 * @param delegated_host requests to which host should be delegated; cannot be NULL
585 * @param slave_host which host is used to run the slave controller; use NULL to
586 * make the master controller connect to the delegated host
587 * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
588 * be started by the slave controller; #GNUNET_NO if the slave
589 * controller has to connect to the already started delegated
590 * controller via TCP/IP
591 * @return the operation handle
592 */
593struct GNUNET_TESTBED_Operation *
594GNUNET_TESTBED_controller_link (void *op_cls,
595 struct GNUNET_TESTBED_Controller *master,
596 struct GNUNET_TESTBED_Host *delegated_host,
597 struct GNUNET_TESTBED_Host *slave_host,
598 int is_subordinate);
599
600
601/**
602 * Function to acquire the configuration of a running slave controller. The
603 * completion of the operation is signalled through the controller_cb from
604 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
605 * handle to the configuration is available in the generic pointer of
606 * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
607 *
608 * @param op_cls the closure for the operation
609 * @param master the handle to master controller
610 * @param slave_host the host where the slave controller is running; the handle
611 * to the slave_host should remain valid until this operation is
612 * cancelled or marked as finished
613 * @return the operation handle; NULL if the slave_host is not registered at
614 * master
615 */
616struct GNUNET_TESTBED_Operation *
617GNUNET_TESTBED_get_slave_config (void *op_cls,
618 struct GNUNET_TESTBED_Controller *master,
619 struct GNUNET_TESTBED_Host *slave_host);
620
621
622/**
623 * Functions of this signature are called when a peer has been successfully
624 * created
625 *
626 * @param cls the closure from GNUNET_TESTBED_peer_create()
627 * @param peer the handle for the created peer; NULL on any error during
628 * creation
629 * @param emsg NULL if peer is not NULL; else MAY contain the error description
630 */
631typedef void
632(*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
633 struct GNUNET_TESTBED_Peer *peer,
634 const char *emsg);
635
636
637/**
638 * Create the given peer at the specified host using the given
639 * controller. If the given controller is not running on the target
640 * host, it should find or create a controller at the target host and
641 * delegate creating the peer. Explicit delegation paths can be setup
642 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
643 * path exists, a direct link with a subordinate controller is setup
644 * for the first delegated peer to a particular host; the subordinate
645 * controller is then destroyed once the last peer that was delegated
646 * to the remote host is stopped.
647 *
648 * Creating the peer only creates the handle to manipulate and further
649 * configure the peer; use #GNUNET_TESTBED_peer_start and
650 * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
651 * processes.
652 *
653 * Note that the given configuration will be adjusted by the
654 * controller to avoid port/path conflicts with other peers.
655 * The "final" configuration can be obtained using
656 * #GNUNET_TESTBED_peer_get_information.
657 *
658 * @param controller controller process to use
659 * @param host host to run the peer on; cannot be NULL
660 * @param cfg Template configuration to use for the peer. Should exist until
661 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
662 * @param cb the callback to call when the peer has been created
663 * @param cls the closure to the above callback
664 * @return the operation handle
665 */
666struct GNUNET_TESTBED_Operation *
667GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
668 struct GNUNET_TESTBED_Host *host,
669 const struct GNUNET_CONFIGURATION_Handle *cfg,
670 GNUNET_TESTBED_PeerCreateCallback cb,
671 void *cls);
672
673
674/**
675 * Functions of this signature are called when a peer has been successfully
676 * started or stopped.
677 *
678 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
679 * @param emsg NULL on success; otherwise an error description
680 */
681typedef void
682(*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
683 const char *emsg);
684
685
686/**
687 * Start the given peer.
688 *
689 * @param op_cls the closure for this operation; will be set in the event
690 * information
691 * @param peer peer to start
692 * @param pcc function to call upon completion
693 * @param pcc_cls closure for 'pcc'
694 * @return handle to the operation
695 */
696struct GNUNET_TESTBED_Operation *
697GNUNET_TESTBED_peer_start (void *op_cls,
698 struct GNUNET_TESTBED_Peer *peer,
699 GNUNET_TESTBED_PeerChurnCallback pcc,
700 void *pcc_cls);
701
702
703/**
704 * Stop the given peer. The handle remains valid (use
705 * #GNUNET_TESTBED_peer_destroy to fully clean up the
706 * state of the peer).
707 *
708 * @param op_cls the closure for this operation; will be set in the event
709 * information
710 * @param peer peer to stop
711 * @param pcc function to call upon completion
712 * @param pcc_cls closure for 'pcc'
713 * @return handle to the operation
714 */
715struct GNUNET_TESTBED_Operation *
716GNUNET_TESTBED_peer_stop (void *op_cls,
717 struct GNUNET_TESTBED_Peer *peer,
718 GNUNET_TESTBED_PeerChurnCallback pcc,
719 void *pcc_cls);
720
721
722/**
723 * Data returned from GNUNET_TESTBED_peer_get_information
724 */
725struct GNUNET_TESTBED_PeerInformation
726{
727 /**
728 * Peer information type; captures which of the types
729 * in the 'op_result' is actually in use.
730 */
731 enum GNUNET_TESTBED_PeerInformationType pit;
732
733 /**
734 * The result of the get information operation; Choose according to the pit
735 */
736 union
737 {
738 /**
739 * The configuration of the peer
740 */
741 struct GNUNET_CONFIGURATION_Handle *cfg;
742
743 /**
744 * The identity of the peer
745 */
746 struct GNUNET_PeerIdentity *id;
747 } result;
748};
749
750
751/**
752 * Callback to be called when the requested peer information is available
753 * The peer information in the callback is valid until the operation 'op' is canceled.
754 *
755 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
756 * @param op the operation this callback corresponds to
757 * @param pinfo the result; will be NULL if the operation has failed
758 * @param emsg error message if the operation has failed; will be NULL if the
759 * operation is successful
760 */
761typedef void
762(*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
763 struct GNUNET_TESTBED_Operation *op,
764 const struct
765 GNUNET_TESTBED_PeerInformation *pinfo,
766 const char *emsg);
767
768
769/**
770 * Request information about a peer. The controller callback will not be called
771 * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
772 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
773 * be called.
774 * The peer information in the callback is valid until the operation is canceled.
775 *
776 * @param peer peer to request information about
777 * @param pit desired information
778 * @param cb the convenience callback to be called when results for this
779 * operation are available
780 * @param cb_cls the closure for @a cb
781 * @return handle to the operation
782 */
783struct GNUNET_TESTBED_Operation *
784GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
785 enum GNUNET_TESTBED_PeerInformationType
786 pit,
787 GNUNET_TESTBED_PeerInfoCallback cb,
788 void *cb_cls);
789
790
791/**
792 * Change @a peer configuration. Ports and paths cannot be changed this
793 * way.
794 *
795 * @param peer peer to change configuration for
796 * @param cfg new configuration
797 * @return handle to the operation
798 */
799struct GNUNET_TESTBED_Operation *
800GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
801 const struct
802 GNUNET_CONFIGURATION_Handle *cfg);
803
804
805/**
806 * Destroy the given peer; the peer should have been
807 * stopped first (if it was started).
808 *
809 * @param peer peer to stop
810 * @return handle to the operation
811 */
812struct GNUNET_TESTBED_Operation *
813GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
814
815
816/**
817 * Start or stop given service at a peer. This should not be called to
818 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
819 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
820 * or failure of the generated operation is signalled through the controller
821 * event callback and/or operation completion callback.
822 *
823 * @param op_cls the closure for the operation
824 * @param peer the peer whose service is to be started/stopped
825 * @param service_name the name of the service
826 * @param cb the operation completion callback
827 * @param cb_cls the closure for @a cb
828 * @param start 1 to start the service; 0 to stop the service
829 * @return an operation handle; NULL upon error (peer not running)
830 */
831struct GNUNET_TESTBED_Operation *
832GNUNET_TESTBED_peer_manage_service (void *op_cls,
833 struct GNUNET_TESTBED_Peer *peer,
834 const char *service_name,
835 GNUNET_TESTBED_OperationCompletionCallback
836 cb,
837 void *cb_cls,
838 unsigned int start);
839
840
841/**
842 * Stops and destroys all peers. Is equivalent of calling
843 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
844 * except that the peer stop event and operation finished event corresponding to
845 * the respective functions are not generated. This function should be called
846 * when there are no other pending operations. If there are pending operations,
847 * it will return NULL
848 *
849 * @param c the controller to send this message to
850 * @param op_cls closure for the operation
851 * @param cb the callback to call when all peers are stopped and destroyed
852 * @param cb_cls the closure for the callback
853 * @return operation handle on success; NULL if any pending operations are
854 * present
855 */
856struct GNUNET_TESTBED_Operation *
857GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
858 void *op_cls,
859 GNUNET_TESTBED_OperationCompletionCallback cb,
860 void *cb_cls);
861
862
863/**
864 * Options for peer connections.
865 */
866enum GNUNET_TESTBED_ConnectOption
867{
868 /**
869 * No option (not valid as an argument).
870 */
871 GNUNET_TESTBED_CO_NONE = 0,
872
873 /**
874 * Allow or disallow a connection between the specified peers.
875 * Followed by #GNUNET_NO (int) if a connection is disallowed
876 * or #GNUNET_YES if a connection is allowed. Note that the
877 * default (all connections allowed or disallowed) is
878 * specified in the configuration of the controller.
879 */
880 GNUNET_TESTBED_CO_ALLOW = 1,
881
882 /**
883 * FIXME: add (and implement) options to limit connection to
884 * particular transports, force simulation of particular latencies
885 * or message loss rates, or set bandwidth limitations.
886 */
887};
888
889
890/**
891 * Manipulate the P2P underlay topology by configuring a link
892 * between two peers.
893 *
894 * @param op_cls closure argument to give with the operation event
895 * @param p1 first peer
896 * @param p2 second peer
897 * @param co option to change
898 * @param ap option-specific values
899 * @return handle to the operation, NULL if configuring the link at this
900 * time is not allowed
901 */
902struct GNUNET_TESTBED_Operation *
903GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
904 struct GNUNET_TESTBED_Peer *p1,
905 struct GNUNET_TESTBED_Peer *p2,
906 enum GNUNET_TESTBED_ConnectOption co,
907 va_list ap);
908
909
910/**
911 * Manipulate the P2P underlay topology by configuring a link
912 * between two peers.
913 *
914 * @param op_cls closure argument to give with the operation event
915 * @param p1 first peer
916 * @param p2 second peer
917 * @param co option to change
918 * @param ... option-specific values
919 * @return handle to the operation, NULL if configuring the link at this
920 * time is not allowed
921 */
922struct GNUNET_TESTBED_Operation *
923GNUNET_TESTBED_underlay_configure_link (void *op_cls,
924 struct GNUNET_TESTBED_Peer *p1,
925 struct GNUNET_TESTBED_Peer *p2,
926 enum GNUNET_TESTBED_ConnectOption co,
927 ...);
928
929
930/**
931 * Topologies and topology options supported for testbeds. Options should always
932 * end with #GNUNET_TESTBED_TOPOLOGY_OPTION_END
933 */
934enum GNUNET_TESTBED_TopologyOption
935{
936 /**
937 * A clique (everyone connected to everyone else). No options. If there are N
938 * peers this topology results in (N * (N -1)) connections.
939 */
940 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
941
942 /**
943 * Small-world network (2d torus plus random links). Followed
944 * by the number of random links to add (unsigned int).
945 */
946 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
947
948 /**
949 * Small-world network (ring plus random links). Followed
950 * by the number of random links to add (unsigned int).
951 */
952 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
953
954 /**
955 * Ring topology. No options.
956 */
957 GNUNET_TESTBED_TOPOLOGY_RING,
958
959 /**
960 * Star topology. No options.
961 */
962 GNUNET_TESTBED_TOPOLOGY_STAR,
963
964 /**
965 * 2-d torus. No options.
966 */
967 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
968
969 /**
970 * Random graph. Followed by the number of random links to be established
971 * (unsigned int)
972 */
973 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
974
975 /**
976 * Certain percentage of peers are unable to communicate directly
977 * replicating NAT conditions. Followed by the fraction of
978 * NAT'ed peers (float).
979 */
980 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
981
982 /**
983 * Scale free topology. It is generated according to the method described in
984 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
985 *
986 * This options takes two arguments in the following order: an uint16_t to
987 * determine the maximum number of edges a peer is permitted to have while
988 * generating scale free topology, a good value for this argument is 70; and
989 * an uint8_t to determine the number of edges to be established when adding a
990 * new node to the scale free network, a good value for this argument is 4.
991 */
992 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
993
994 /**
995 * Straight line topology. No options.
996 */
997 GNUNET_TESTBED_TOPOLOGY_LINE,
998
999 /**
1000 * Read a topology from a given file. Followed by the name of the file (const char *).
1001 */
1002 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
1003
1004 /**
1005 * All peers are disconnected. No options.
1006 */
1007 GNUNET_TESTBED_TOPOLOGY_NONE,
1008
1009 /**
1010 * The options should always end with this
1011 */
1012 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1013
1014 /* The following are not topologies but influence how the topology has to be
1015 setup. These options should follow the topology specific options (if
1016 required by the chosen topology). Note that these should be given before
1017 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1018
1019 /**
1020 * How many times should the failed overlay connect operations be retried
1021 * before giving up. The default if this option is not specified is to retry
1022 * 3 times. This option takes and unsigned integer as a parameter. Use this
1023 * option with parameter 0 to disable retrying of failed overlay connect
1024 * operations.
1025 */
1026 GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1027};
1028
1029
1030/**
1031 * Configure overall network topology to have a particular shape.
1032 *
1033 * @param op_cls closure argument to give with the operation event
1034 * @param num_peers number of peers in @a peers
1035 * @param peers array of @a num_peers with the peers to configure
1036 * @param topo desired underlay topology to use
1037 * @param ap topology-specific options
1038 * @return handle to the operation, NULL if configuring the topology
1039 * is not allowed at this time
1040 */
1041struct GNUNET_TESTBED_Operation *
1042GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1043 unsigned int num_peers,
1044 struct GNUNET_TESTBED_Peer **
1045 peers,
1046 enum
1047 GNUNET_TESTBED_TopologyOption
1048 topo,
1049 va_list ap);
1050
1051
1052/**
1053 * Configure overall network topology to have a particular shape.
1054 *
1055 * @param op_cls closure argument to give with the operation event
1056 * @param num_peers number of peers in @a peers
1057 * @param peers array of @a num_peers with the peers to configure
1058 * @param topo desired underlay topology to use
1059 * @param ... topology-specific options
1060 * @return handle to the operation, NULL if configuring the topology
1061 * is not allowed at this time
1062 */
1063struct GNUNET_TESTBED_Operation *
1064GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1065 unsigned int num_peers,
1066 struct GNUNET_TESTBED_Peer **peers,
1067 enum GNUNET_TESTBED_TopologyOption
1068 topo,
1069 ...);
1070
1071
1072/**
1073 * Both peers must have been started before calling this function.
1074 * This function then obtains a HELLO from @a p1, gives it to @a p2
1075 * and asks @a p2 to connect to @a p1.
1076 *
1077 * @param op_cls closure argument to give with the operation event
1078 * @param cb the callback to call when this operation has finished
1079 * @param cb_cls the closure for @a cb
1080 * @param p1 first peer
1081 * @param p2 second peer
1082 * @return handle to the operation, NULL if connecting these two
1083 * peers is fundamentally not possible at this time (peers
1084 * not running or underlay disallows)
1085 */
1086struct GNUNET_TESTBED_Operation *
1087GNUNET_TESTBED_overlay_connect (void *op_cls,
1088 GNUNET_TESTBED_OperationCompletionCallback cb,
1089 void *cb_cls,
1090 struct GNUNET_TESTBED_Peer *p1,
1091 struct GNUNET_TESTBED_Peer *p2);
1092
1093
1094/**
1095 * Callbacks of this type are called when topology configuration is completed
1096 *
1097 * @param cls the operation closure given to
1098 * GNUNET_TESTBED_overlay_configure_topology_va() and
1099 * GNUNET_TESTBED_overlay_configure() calls
1100 * @param nsuccess the number of successful overlay connects
1101 * @param nfailures the number of overlay connects which failed
1102 */
1103typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1104 unsigned int
1105 nsuccess,
1106 unsigned int
1107 nfailures);
1108
1109
1110/**
1111 * All peers must have been started before calling this function.
1112 * This function then connects the given peers in the P2P overlay
1113 * using the given topology.
1114 *
1115 * @param op_cls closure argument to give with the peer connect operation events
1116 * generated through this function
1117 * @param num_peers number of peers in 'peers'
1118 * @param peers array of 'num_peers' with the peers to configure
1119 * @param max_connections the maximums number of overlay connections that will
1120 * be made to achieve the given topology
1121 * @param comp_cb the completion callback to call when the topology generation
1122 * is completed
1123 * @param comp_cb_cls closure for the @a comp_cb
1124 * @param topo desired underlay topology to use
1125 * @param va topology-specific options
1126 * @return handle to the operation, NULL if connecting these
1127 * peers is fundamentally not possible at this time (peers
1128 * not running or underlay disallows) or if num_peers is less than 2
1129 */
1130struct GNUNET_TESTBED_Operation *
1131GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1132 unsigned int num_peers,
1133 struct GNUNET_TESTBED_Peer **peers,
1134 unsigned int *max_connections,
1135 GNUNET_TESTBED_TopologyCompletionCallback
1136 comp_cb,
1137 void *comp_cb_cls,
1138 enum GNUNET_TESTBED_TopologyOption
1139 topo,
1140 va_list va);
1141
1142
1143/**
1144 * All peers must have been started before calling this function.
1145 * This function then connects the given peers in the P2P overlay
1146 * using the given topology.
1147 *
1148 * @param op_cls closure argument to give with the peer connect operation events
1149 * generated through this function
1150 * @param num_peers number of peers in 'peers'
1151 * @param peers array of 'num_peers' with the peers to configure
1152 * @param max_connections the maximums number of overlay connections that will
1153 * be made to achieve the given topology
1154 * @param comp_cb the completion callback to call when the topology generation
1155 * is completed
1156 * @param comp_cb_cls closure for the above completion callback
1157 * @param topo desired underlay topology to use
1158 * @param ... topology-specific options
1159 * @return handle to the operation, NULL if connecting these
1160 * peers is fundamentally not possible at this time (peers
1161 * not running or underlay disallows) or if num_peers is less than 2
1162 */
1163struct GNUNET_TESTBED_Operation *
1164GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1165 unsigned int num_peers,
1166 struct GNUNET_TESTBED_Peer **peers,
1167 unsigned int *max_connections,
1168 GNUNET_TESTBED_TopologyCompletionCallback
1169 comp_cb,
1170 void *comp_cb_cls,
1171 enum GNUNET_TESTBED_TopologyOption
1172 topo,
1173 ...);
1174
1175
1176/**
1177 * Ask the testbed controller to write the current overlay topology to
1178 * a file. Naturally, the file will only contain a snapshot as the
1179 * topology may evolve all the time.
1180 * FIXME: needs continuation!?
1181 *
1182 * @param controller overlay controller to inspect
1183 * @param filename name of the file the topology should
1184 * be written to.
1185 */
1186void
1187GNUNET_TESTBED_overlay_write_topology_to_file (struct
1188 GNUNET_TESTBED_Controller *
1189 controller,
1190 const char *filename);
1191
1192
1193/**
1194 * Adapter function called to establish a connection to
1195 * a service.
1196 *
1197 * @param cls closure
1198 * @param cfg configuration of the peer to connect to; will be available until
1199 * GNUNET_TESTBED_operation_done() is called on the operation returned
1200 * from GNUNET_TESTBED_service_connect()
1201 * @return service handle to return in 'op_result', NULL on error
1202 */
1203typedef void *
1204(*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1205 const struct GNUNET_CONFIGURATION_Handle *cfg);
1206
1207
1208/**
1209 * Adapter function called to destroy a connection to
1210 * a service.
1211 *
1212 * @param cls closure
1213 * @param op_result service handle returned from the connect adapter
1214 */
1215typedef void
1216(*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1217 void *op_result);
1218
1219
1220/**
1221 * Callback to be called when a service connect operation is completed
1222 *
1223 * @param cls the callback closure from functions generating an operation
1224 * @param op the operation that has been finished
1225 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1226 * @param emsg error message in case the operation has failed; will be NULL if
1227 * operation has executed successfully.
1228 */
1229typedef void
1230(*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1231 struct
1232 GNUNET_TESTBED_Operation *op,
1233 void *ca_result,
1234 const char *emsg);
1235
1236
1237/**
1238 * Connect to a service offered by the given peer. Will ensure that
1239 * the request is queued to not overwhelm our ability to create and
1240 * maintain connections with other systems. The actual service
1241 * handle is then returned via the 'op_result' member in the event
1242 * callback. The @a ca callback is used to create the connection
1243 * when the time is right; the @a da callback will be used to
1244 * destroy the connection (upon #GNUNET_TESTBED_operation_done).
1245 * #GNUNET_TESTBED_operation_done can be used to abort this
1246 * operation until the event callback has been called.
1247 *
1248 * @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
1249 * @param peer peer that runs the service
1250 * @param service_name name of the service to connect to
1251 * @param cb the callback to call when this operation is ready (that is,
1252 * right after the connect adapter returns)
1253 * @param cb_cls closure for @a cb
1254 * @param ca helper function to establish the connection
1255 * @param da helper function to close the connection
1256 * @param cada_cls closure for @a ca and @a da
1257 * @return handle for the operation
1258 */
1259struct GNUNET_TESTBED_Operation *
1260GNUNET_TESTBED_service_connect (void *op_cls,
1261 struct GNUNET_TESTBED_Peer *peer,
1262 const char *service_name,
1263 GNUNET_TESTBED_ServiceConnectCompletionCallback
1264 cb,
1265 void *cb_cls,
1266 GNUNET_TESTBED_ConnectAdapter ca,
1267 GNUNET_TESTBED_DisconnectAdapter da,
1268 void *cada_cls);
1269
1270
1271/**
1272 * This function is used to signal that the event information (struct
1273 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1274 * i.e. if the event callback is ever called for this operation. If the event
1275 * callback for this operation has not yet been called, calling this function
1276 * cancels the operation, frees its resources and ensures the no event is
1277 * generated with respect to this operation. Note that however cancelling an
1278 * operation does NOT guarantee that the operation will be fully undone (or that
1279 * nothing ever happened).
1280 *
1281 * This function MUST be called for every operation to fully remove the
1282 * operation from the operation queue. After calling this function, if
1283 * operation is completed and its event information is of type
1284 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1285
1286 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1287 * calling this function on such as operation calls the disconnect adapter if
1288 * the connect adapter was ever called.
1289 *
1290 * @param operation operation to signal completion or cancellation
1291 */
1292void
1293GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1294
1295
1296/**
1297 * Callback function to process statistic values from all peers.
1298 *
1299 * @param cls closure
1300 * @param peer the peer the statistic belong to
1301 * @param subsystem name of subsystem that created the statistic
1302 * @param name the name of the datum
1303 * @param value the current value
1304 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1305 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1306 */
1307typedef int
1308(*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1309 const struct GNUNET_TESTBED_Peer *peer,
1310 const char *subsystem,
1311 const char *name,
1312 uint64_t value,
1313 int is_persistent);
1314
1315
1316/**
1317 * Convenience method that iterates over all (running) peers
1318 * and retrieves all statistics from each peer.
1319 *
1320 * @param num_peers number of peers to iterate over
1321 * @param peers array of peers to iterate over
1322 * @param subsystem limit to the specified subsystem, NULL for all subsystems
1323 * @param name name of the statistic value, NULL for all values
1324 * @param proc processing function for each statistic retrieved
1325 * @param cont continuation to call once call is completed. The completion of this
1326 * operation is *ONLY* signalled through this callback -- no
1327 * GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1328 * @param cls closure to pass to proc and cont
1329 * @return operation handle to cancel the operation
1330 */
1331struct GNUNET_TESTBED_Operation *
1332GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1333 struct GNUNET_TESTBED_Peer **peers,
1334 const char *subsystem, const char *name,
1335 GNUNET_TESTBED_StatisticsIterator proc,
1336 GNUNET_TESTBED_OperationCompletionCallback cont,
1337 void *cls);
1338
1339
1340/**
1341 * Return the index of the peer inside of the total peer array,
1342 * aka. the peer's "unique ID".
1343 *
1344 * @param peer Peer handle.
1345 *
1346 * @return The peer's unique ID.
1347 */
1348uint32_t
1349GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer);
1350
1351
1352/**
1353 * Handle for testbed run helper functions
1354 */
1355struct GNUNET_TESTBED_RunHandle;
1356
1357
1358/**
1359 * Signature of a main function for a testcase.
1360 *
1361 * @param cls closure
1362 * @param h the run handle
1363 * @param num_peers number of peers in 'peers'
1364 * @param peers handle to peers run in the testbed. NULL upon timeout (see
1365 * GNUNET_TESTBED_test_run()).
1366 * @param links_succeeded the number of overlay link connection attempts that
1367 * succeeded
1368 * @param links_failed the number of overlay link connection attempts that
1369 * failed
1370 * @see GNUNET_TESTBED_test_run()
1371 */
1372typedef void
1373(*GNUNET_TESTBED_TestMaster)(void *cls,
1374 struct GNUNET_TESTBED_RunHandle *h,
1375 unsigned int num_peers,
1376 struct GNUNET_TESTBED_Peer **peers,
1377 unsigned int links_succeeded,
1378 unsigned int links_failed);
1379
1380
1381/**
1382 * Convenience method for running a testbed with
1383 * a single call. Underlay and overlay topology
1384 * are configured using the "UNDERLAY" and "OVERLAY"
1385 * options in the "[testbed]" section of the configuration\
1386 * (with possible options given in "UNDERLAY_XXX" and/or
1387 * "OVERLAY_XXX").
1388 *
1389 * The test_master callback will be called once the testbed setup is finished or
1390 * upon a timeout. This timeout is given through the configuration file by
1391 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1392 *
1393 * The testbed is to be terminated using a call to
1394 * "GNUNET_SCHEDULER_shutdown".
1395 *
1396 * @param host_filename name of the file with the 'hosts', NULL
1397 * to run everything on 'localhost'
1398 * @param cfg configuration to use (for testbed, controller and peers)
1399 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1400 * cfg?; should be greater than 0
1401 * @param event_mask bit mask with set of events to call 'cc' for;
1402 * or-ed values of "1LL" shifted by the
1403 * respective 'enum GNUNET_TESTBED_EventType'
1404 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1405 * @param cc controller callback to invoke on events; This callback is called
1406 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1407 * set in the event_mask as this is the only way get access to the
1408 * handle of each peer
1409 * @param cc_cls closure for cc
1410 * @param test_master this callback will be called once the test is ready or
1411 * upon timeout
1412 * @param test_master_cls closure for 'test_master'.
1413 */
1414void
1415GNUNET_TESTBED_run (const char *host_filename,
1416 const struct GNUNET_CONFIGURATION_Handle *cfg,
1417 unsigned int num_peers,
1418 uint64_t event_mask,
1419 GNUNET_TESTBED_ControllerCallback cc,
1420 void *cc_cls,
1421 GNUNET_TESTBED_TestMaster test_master,
1422 void *test_master_cls);
1423
1424
1425/**
1426 * Convenience method for running a "simple" test on the local system
1427 * with a single call from 'main'. Underlay and overlay topology are
1428 * configured using the "UNDERLAY" and "OVERLAY" options in the
1429 * "[TESTBED]" section of the configuration (with possible options
1430 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1431 *
1432 * The test_master callback will be called once the testbed setup is finished or
1433 * upon a timeout. This timeout is given through the configuration file by
1434 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1435 *
1436 * The test is to be terminated using a call to
1437 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1438 * the program is stopped without 'master' ever being run.
1439 *
1440 * NOTE: this function should be called from 'main', NOT from
1441 * within a GNUNET_SCHEDULER-loop. This function will initialize
1442 * the scheduler loop, the testbed and then pass control to
1443 * 'master'.
1444 *
1445 * @param testname name of the testcase (to configure logging, etc.)
1446 * @param cfg_filename configuration filename to use
1447 * (for testbed, controller and peers)
1448 * @param num_peers number of peers to start; should be greter than 0
1449 * @param event_mask bit mask with set of events to call 'cc' for;
1450 * or-ed values of "1LL" shifted by the
1451 * respective 'enum GNUNET_TESTBED_EventType'
1452 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1453 * @param cc controller callback to invoke on events; This callback is called
1454 * for all peer start events even if #GNUNET_TESTBED_ET_PEER_START isn't
1455 * set in the event_mask as this is the only way get access to the
1456 * handle of each peer
1457 * @param cc_cls closure for @a cc
1458 * @param test_master this callback will be called once the test is ready or
1459 * upon timeout
1460 * @param test_master_cls closure for @a test_master.
1461 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1462 */
1463int
1464GNUNET_TESTBED_test_run (const char *testname,
1465 const char *cfg_filename,
1466 unsigned int num_peers,
1467 uint64_t event_mask,
1468 GNUNET_TESTBED_ControllerCallback cc,
1469 void *cc_cls,
1470 GNUNET_TESTBED_TestMaster test_master,
1471 void *test_master_cls);
1472
1473
1474/**
1475 * Obtain handle to the master controller from a testbed run. The handle
1476 * returned should not be disconnected.
1477 *
1478 * @param h the testbed run handle
1479 * @return handle to the master controller
1480 */
1481struct GNUNET_TESTBED_Controller *
1482GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
1483
1484
1485/**
1486 * Opaque handle for barrier
1487 */
1488struct GNUNET_TESTBED_Barrier;
1489
1490
1491/**
1492 * Status of a barrier
1493 */
1494enum GNUNET_TESTBED_BarrierStatus
1495{
1496 /**
1497 * Barrier initialised successfully
1498 */
1499 GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
1500
1501 /**
1502 * Barrier is crossed
1503 */
1504 GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
1505
1506 /**
1507 * Error status
1508 */
1509 GNUNET_TESTBED_BARRIERSTATUS_ERROR,
1510};
1511
1512
1513/**
1514 * Functions of this type are to be given as callback argument to
1515 * GNUNET_TESTBED_barrier_init(). The callback will be called when status
1516 * information is available for the barrier.
1517 *
1518 * @param cls the closure given to GNUNET_TESTBED_barrier_init()
1519 * @param name the name of the barrier
1520 * @param barrier the barrier handle
1521 * @param status status of the barrier. The barrier is removed once it has been
1522 * crossed or an error occurs while processing it. Therefore it is
1523 * invalid to call GNUNET_TESTBED_barrier_cancel() on a crossed or
1524 * errored barrier.
1525 * @param emsg if the status were to be #GNUNET_SYSERR, this parameter has the
1526 * error message
1527 */
1528typedef void
1529(*GNUNET_TESTBED_barrier_status_cb) (void *cls,
1530 const char *name,
1531 struct GNUNET_TESTBED_Barrier *barrier,
1532 enum GNUNET_TESTBED_BarrierStatus status,
1533 const char *emsg);
1534
1535
1536/**
1537 * Initialise a barrier and call the given callback when the required percentage
1538 * of peers (quorum) reach the barrier.
1539 *
1540 * @param controller the handle to the controller
1541 * @param name identification name of the barrier
1542 * @param quorum the percentage of peers that is required to reach the barrier.
1543 * Peers signal reaching a barrier by calling
1544 * GNUNET_TESTBED_barrier_reached().
1545 * @param cb the callback to call when the barrier is reached or upon error.
1546 * Cannot be NULL.
1547 * @param cb_cls closure for @a cb
1548 * @return barrier handle
1549 */
1550struct GNUNET_TESTBED_Barrier *
1551GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
1552 const char *name,
1553 unsigned int quorum,
1554 GNUNET_TESTBED_barrier_status_cb cb,
1555 void *cb_cls);
1556
1557
1558/**
1559 * Cancel a barrier.
1560 *
1561 * @param barrier the barrier handle
1562 */
1563void
1564GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
1565
1566
1567/**
1568 * Opaque handle for barrier wait
1569 */
1570struct GNUNET_TESTBED_BarrierWaitHandle;
1571
1572
1573/**
1574 * Functions of this type are to be given as acallback argument to
1575 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
1576 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
1577 *
1578 * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
1579 * @param name the barrier name
1580 * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
1581 * #GNUNET_OK if the barrier is crossed
1582 */
1583typedef void
1584(*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
1585 const char *name,
1586 int status);
1587
1588
1589/**
1590 * Wait for a barrier to be crossed. This function should be called by the
1591 * peers which have been started by the testbed. If the peer is not started by
1592 * testbed this function may return error
1593 *
1594 * @param name the name of the barrier
1595 * @param cb the barrier wait callback
1596 * @param cls the closure for the above callback
1597 * @return barrier wait handle which can be used to cancel the waiting at
1598 * anytime before the callback is called. NULL upon error.
1599 */
1600struct GNUNET_TESTBED_BarrierWaitHandle *
1601GNUNET_TESTBED_barrier_wait (const char *name,
1602 GNUNET_TESTBED_barrier_wait_cb cb,
1603 void *cls);
1604
1605
1606/**
1607 * Cancel a barrier wait handle. Should not be called in or after the callback
1608 * given to GNUNET_TESTBED_barrier_wait() has been called.
1609 *
1610 * @param h the barrier wait handle
1611 */
1612void
1613GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
1614
1615
1616/**
1617 * Model for configuring underlay links of a peer
1618 * @ingroup underlay
1619 */
1620struct GNUNET_TESTBED_UnderlayLinkModel;
1621
1622
1623/**
1624 * The type of GNUNET_TESTBED_UnderlayLinkModel
1625 * @ingroup underlay
1626 */
1627enum GNUNET_TESTBED_UnderlayLinkModelType
1628{
1629 /**
1630 * The model is based on white listing of peers to which underlay connections
1631 * are permitted. Underlay connections to all other peers will not be
1632 * permitted.
1633 */
1634 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST,
1635
1636 /**
1637 * The model is based on black listing of peers to which underlay connections
1638 * are not permitted. Underlay connections to all other peers will be
1639 * permitted
1640 */
1641 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_WHITELIST
1642};
1643
1644
1645/**
1646 * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can
1647 * have ONLY ONE model and it can be either a blacklist or whitelist based one.
1648 *
1649 * @ingroup underlay
1650 * @param peer the peer for which the model has to be created
1651 * @param type the type of the model
1652 * @return the model
1653 */
1654struct GNUNET_TESTBED_UnderlayLinkModel *
1655GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
1656 enum
1657 GNUNET_TESTBED_UnderlayLinkModelType
1658 type);
1659
1660
1661/**
1662 * Add a peer to the given model. Underlay connections to the given peer will
1663 * be permitted if the model is whitelist based; otherwise they will not be
1664 * permitted.
1665 *
1666 * @ingroup underlay
1667 * @param model the model
1668 * @param peer the peer to add
1669 */
1670void
1671GNUNET_TESTBED_underlaylinkmodel_add_peer (struct
1672 GNUNET_TESTBED_UnderlayLinkModel *
1673 model,
1674 struct GNUNET_TESTBED_Peer *peer);
1675
1676
1677/**
1678 * Set the metrics for a link to the given peer in the underlay model. The link
1679 * SHOULD be permittable according to the given model.
1680 *
1681 * @ingroup underlay
1682 * @param model the model
1683 * @param peer the other end peer of the link
1684 * @param latency latency of the link in microseconds
1685 * @param loss data loss of the link expressed as a percentage
1686 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
1687 */
1688void
1689GNUNET_TESTBED_underlaylinkmodel_set_link (struct
1690 GNUNET_TESTBED_UnderlayLinkModel *
1691 model,
1692 struct GNUNET_TESTBED_Peer *peer,
1693 uint32_t latency,
1694 uint32_t loss,
1695 uint32_t bandwidth);
1696
1697
1698/**
1699 * Commit the model. The model is freed in this function(!).
1700 *
1701 * @ingroup underlay
1702 * @param model the model to commit
1703 */
1704void
1705GNUNET_TESTBED_underlaylinkmodel_commit (struct
1706 GNUNET_TESTBED_UnderlayLinkModel *model);
1707
1708
1709/**
1710 * Free the resources of the model. Use this function only if the model has not
1711 * be committed and has to be unallocated. The peer can then have another model
1712 * created.
1713 *
1714 * @ingroup underlay
1715 * @param model the model to unallocate
1716 */
1717void
1718GNUNET_TESTBED_underlaylinkmodel_free (struct
1719 GNUNET_TESTBED_UnderlayLinkModel *model);
1720
1721
1722#if 0 /* keep Emacsens' auto-indent happy */
1723{
1724#endif
1725
1726
1727#ifdef __cplusplus
1728}
1729#endif
1730
1731#endif
1732
1733/** @} */ /* end of group */
1734
1735/** @} */ /* end of group addition */
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_barrier.h b/src/include/gnunet_testing_barrier.h
deleted file mode 100644
index 4384dd055..000000000
--- a/src/include/gnunet_testing_barrier.h
+++ /dev/null
@@ -1,115 +0,0 @@
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 * @file include/gnunet_testing_barrier.h
23 * @brief API to manage barriers.
24 * @author t3sserakt
25 */
26
27#ifndef GNUNET_TESTING_BARRIER_LIB_H
28#define GNUNET_TESTING_BARRIER_LIB_H
29
30#include "gnunet_testing_plugin.h"
31
32#define GNUNET_TESTING_BARRIER_MAX 32
33
34/**
35 * An entry for a barrier list
36 */
37struct GNUNET_TESTING_BarrierListEntry
38{
39 /* DLL */
40 struct GNUNET_TESTING_BarrierListEntry *next;
41
42 /* DLL */
43 struct GNUNET_TESTING_BarrierListEntry *prev;
44
45 /* The barrier name*/
46 char *barrier_name;
47
48 /**
49 * Number of commands attached to the barrier.
50 */
51 unsigned int expected_reaches;
52 };
53
54/**
55 * A list to hold barriers provided by plugins
56 */
57struct GNUNET_TESTING_BarrierList
58{
59 /** List head **/
60 struct GNUNET_TESTING_BarrierListEntry *head;
61
62 /** List tail **/
63 struct GNUNET_TESTING_BarrierListEntry *tail;
64};
65
66
67/**
68 * Command to create a barrier.
69 *
70 * FIXME: high-level it is baffling how we need both the GNUNET_TESTING_Barrier
71 * and the Command that creates barriers. Conceptually this seems to be
72 * very much separate. Can we move _Barrier completely into testing as private?
73 *
74 * @param label The label of this command.
75 * @param percentage_to_be_reached If this percentage of processes reached
76 * this barrier, all processes waiting at
77 * this barrier can pass it. Must not be
78 * used together with number_to_be_reached.
79 * @param number_to_be_reached If this number of processes reached
80 * this barrier, all processes waiting at
81 * this barrier can pass it. Must not be
82 * used together with percentage_to_be_reached.
83 */
84struct GNUNET_TESTING_Command
85GNUNET_TESTING_cmd_barrier_create (
86 const char *label,
87 double percentage_to_be_reached,
88 unsigned int number_to_be_reached);
89
90/**
91 * If this command is executed the the process is signaling the master process
92 * that it reached a barrier. If this command is synchronous it will block.
93 *
94 * FIXME: Now this, as it returns a Command, seems to me like it should be
95 * part of the public API?
96 *
97 * @param label name for command.
98 * @param barrier_label The name of the barrier we waited for and which was reached.
99 * @param asynchronous_finish If GNUNET_YES this command will not block.
100 * @param node_number The global number of the node the cmd runs on.
101 * @param running_on_master Is this cmd running on the master loop?
102 * @param write_message Callback to write messages to the master loop.
103 * @return command.
104 */
105struct GNUNET_TESTING_Command
106GNUNET_TESTING_cmd_barrier_reached (
107 const char *label,
108 const char *barrier_label,
109 unsigned int asynchronous_finish,
110 unsigned int node_number,
111 unsigned int running_on_master,
112 GNUNET_TESTING_cmd_helper_write_cb write_message);
113
114#endif
115/* end of testing_barrier.h */
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 cd9d88822..0ee3a68b8 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,462 +19,959 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Testing 22 * @brief Central interpreter and command loop for writing an interpreter to test asynchronous systems
23 * @{ 23 * @author Christian Grothoff <christian@grothoff.org>
24 * 24 * @author Marcello Stanisci
25 * @author Christian Grothoff 25 * @author t3sserakt
26 * 26 */
27 * @file 27#ifndef GNUNET_TESTING_LIB_H
28 * Convenience API for writing testcases for GNUnet 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.
29 * 54 *
30 * @defgroup testing Testing library 55 * @param is interpreter
31 * 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.
32 * 116 *
33 * It can start/stop one or more peers on a system; testing is responsible for 117 * @param ac command-specific context
34 * managing private keys, ports and paths; it is a low-level library that does 118 */
35 * not support higher-level functions such as P2P connection, topology 119void
36 * management or distributed testbed maintenance (those are provided by the 120GNUNET_TESTING_async_fail (
37 * [Testbed service](@ref testbed)) 121 struct GNUNET_TESTING_AsyncContext *ac);
122
123
124/**
125 * The asynchronous command of @a ac has finished.
38 * 126 *
39 * @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.
40 * 141 *
41 * @{ 142 * @param cls closure
143 * @param is interpreter running the command
42 */ 144 */
145typedef void
146(*GNUNET_TESTING_CommandRunRoutine)(
147 void *cls,
148 struct GNUNET_TESTING_Interpreter *is);
43 149
44#ifndef GNUNET_TESTING_LIB_H
45#define GNUNET_TESTING_LIB_H
46 150
151/**
152 * Signature of a function used to clean up resources allocated
153 * by a command.
154 *
155 * @param cls closure
156 */
157typedef void
158(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
47 159
48#include "gnunet_util_lib.h"
49#include "gnunet_statistics_service.h"
50#include "gnunet_arm_service.h"
51 160
52#ifdef __cplusplus 161/**
53extern "C" 162 * Signature of a function used to extract traits exposed by a
54{ 163 * command.
55#if 0 /* keep Emacsens' auto-indent happy */ 164 *
56} 165 * @param cls closure
57#endif 166 * @param[out] ret where to return the trait data
58#endif 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
170 */
171typedef enum GNUNET_GenericReturnValue
172(*GNUNET_TESTING_CommandGetTraits) (void *cls,
173 const void **ret,
174 const char *trait,
175 unsigned int index);
59 176
60/** 177/**
61 * Size of each hostkey in the hostkey file (in BYTES). 178 * Create a new command that may be asynchronous.
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
62 */ 188 */
63#define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \ 189struct GNUNET_TESTING_Command
64 GNUNET_CRYPTO_EddsaPrivateKey) 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);
197
65 198
66/** 199/**
67 * The environmental variable, if set, that dictates where testing should place 200 * Create a new command
68 * generated peer configurations 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
69 */ 208 */
70#define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX" 209#define GNUNET_TESTING_command_new(cls,label,run,cleanup,traits) \
210 GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL)
71 211
72 212
73/** 213/**
74 * Handle for a system on which GNUnet peers are executed; 214 * Structure with storage space for a label.
75 * a system is used for reserving unique paths and ports.
76 */ 215 */
77struct GNUNET_TESTING_System; 216struct GNUNET_TESTING_CommandLabel
217{
218 char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
219};
78 220
79 221
80/** 222/**
81 * Handle for a GNUnet peer controlled by testing. 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
82 */ 228 */
83struct GNUNET_TESTING_Peer; 229void
230GNUNET_TESTING_set_label (
231 struct GNUNET_TESTING_CommandLabel *label,
232 const char *value);
84 233
85 234
86/** 235/**
87 * Specification of a service that is to be shared among peers 236 * A command to be run by the interpreter.
88 */ 237 */
89struct GNUNET_TESTING_SharedService 238struct GNUNET_TESTING_Command
90{ 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
91 /** 304 /**
92 * The name of the service. 305 * When did the execution of this command start?
93 */ 306 */
94 const char *service; 307 struct GNUNET_TIME_Absolute start_time;
95 308
96 /** 309 /**
97 * The configuration template for the service. Cannot be NULL 310 * When did the execution of this command finish?
98 */ 311 */
99 const struct GNUNET_CONFIGURATION_Handle *cfg; 312 struct GNUNET_TIME_Absolute finish_time;
100 313
101 /** 314 /**
102 * 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
103 * 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.
104 */ 322 */
105 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
106}; 340};
107 341
108 342
109/** 343/**
110 * Create a system handle. There must only be one system handle per operating 344 * Lookup command by label.
111 * system. Uses a default range for allowed ports. Ports are still tested for 345 *
112 * availability. 346 * @param is interpreter to lookup command in
113 * 347 * @param label label of the command to lookup.
114 * @param testdir only the directory name without any path. This is used for all 348 * @return the command, if it is found, or NULL.
115 * service homes; the directory will be created in a temporary location 349 */
116 * depending on the underlying OS. This variable will be 350const struct GNUNET_TESTING_Command *
117 * overridden with the value of the environmental variable 351GNUNET_TESTING_interpreter_lookup_command (
118 * GNUNET_TESTING_PREFIX, if it exists. 352 struct GNUNET_TESTING_Interpreter *is,
119 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all 353 const char *label);
120 * service configurations generated to allow control connections from 354
121 * this ip. This can either be a single ip address or a network address 355
122 * in CIDR notation. 356/**
123 * @param hostname the hostname of the system we are using for testing; NULL for 357 * Get command from hash map by variable name.
124 * localhost 358 *
125 * @param shared_services NULL terminated array describing services that are to 359 * @param is interpreter state.
126 * be shared among peers 360 * @param name name of the variable to get command by
127 * @return handle to this system, NULL on error 361 * @return the command, if it is found, or NULL.
128 */ 362 */
129struct GNUNET_TESTING_System * 363const struct GNUNET_TESTING_Command *
130GNUNET_TESTING_system_create (const char *testdir, 364GNUNET_TESTING_interpreter_get_command (
131 const char *trusted_ip, 365 struct GNUNET_TESTING_Interpreter *is,
132 const char *hostname, 366 const char *name);
133 const struct GNUNET_TESTING_SharedService * 367
134 shared_services); 368
135 369/**
136 370 * Update the last request time of the current command
137/** 371 * to the current time.
138 * Create a system handle. There must only be one system 372 *
139 * handle per operating system. Use this function directly 373 * @param[in,out] is interpreter state where to show
140 * if multiple system objects are created for the same host 374 * that we are doing something
141 * (only really useful when testing --- or to make the port
142 * range configurable).
143 *
144 * @param testdir only the directory name without any path. This is used for
145 * all service homes; the directory will be created in a temporary
146 * location depending on the underlying OS. This variable will be
147 * overridden with the value of the environmental variable
148 * GNUNET_TESTING_PREFIX, if it exists.
149 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all
150 * service configurations generated to allow control connections from
151 * this ip. This can either be a single ip address or a network address
152 * in CIDR notation.
153 * @param hostname the hostname of the system we are using for testing; NULL for
154 * localhost
155 * @param shared_services NULL terminated array describing services that are to
156 * be shared among peers
157 * @param lowport lowest port number this system is allowed to allocate (inclusive)
158 * @param highport highest port number this system is allowed to allocate (exclusive)
159 * @return handle to this system, NULL on error
160 */
161struct GNUNET_TESTING_System *
162GNUNET_TESTING_system_create_with_portrange (const char *testdir,
163 const char *trusted_ip,
164 const char *hostname,
165 const struct
166 GNUNET_TESTING_SharedService *
167 shared_services,
168 uint16_t lowport,
169 uint16_t highport);
170
171
172/**
173 * Free system resources.
174 *
175 * @param system system to be freed
176 * @param remove_paths should the 'testdir' and all subdirectories
177 * be removed (clean up on shutdown)?
178 */ 375 */
179void 376void
180GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 377GNUNET_TESTING_interpreter_current_cmd_touch (
181 int remove_paths); 378 struct GNUNET_TESTING_Interpreter *is);
182 379
183 380
184/** 381/**
185 * Testing includes a number of pre-created hostkeys for 382 * Increment the 'num_tries' counter for the current command.
186 * faster peer startup. This function can be used to
187 * access the n-th key of those pre-created hostkeys; note
188 * that these keys are ONLY useful for testing and not
189 * secure as the private keys are part of the public
190 * GNUnet source code.
191 * 383 *
192 * This is primarily a helper function used internally 384 * @param[in,out] is interpreter state where to
193 * by #GNUNET_TESTING_peer_configure(). 385 * increment the counter
386 */
387void
388GNUNET_TESTING_interpreter_current_cmd_inc_tries (
389 struct GNUNET_TESTING_Interpreter *is);
390
391
392/**
393 * Obtain label of the command being now run.
194 * 394 *
195 * @param system the testing system handle 395 * @param is interpreter state.
196 * @param key_number desired pre-created hostkey to obtain 396 * @return the label.
197 * @param id set to the peer's identity (hash of the public
198 * key; if NULL, #GNUNET_SYSERR is returned immediately
199 * @return NULL on error (not enough keys)
200 */ 397 */
201struct GNUNET_CRYPTO_EddsaPrivateKey * 398const char *
202GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, 399GNUNET_TESTING_interpreter_current_cmd_get_label (
203 uint32_t key_number, 400 struct GNUNET_TESTING_Interpreter *is);
204 struct GNUNET_PeerIdentity *id);
205 401
206 402
207/** 403/**
208 * Reserve a port for a peer. 404 * Current command failed, clean up and fail the test case.
209 * 405 *
210 * @param system system to use for reservation tracking 406 * @param is interpreter state.
211 * @return 0 if no free port was available
212 */ 407 */
213uint16_t 408void
214GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system); 409GNUNET_TESTING_interpreter_fail (
410 struct GNUNET_TESTING_Interpreter *is);
215 411
216 412
217/** 413/**
218 * Release reservation of a TCP or UDP port for a peer 414 * Skips the current test, the environment is
219 * (used during GNUNET_TESTING_peer_destroy). 415 * not prepared correctly.
220 * 416 *
221 * @param system system to use for reservation tracking 417 * @param is interpreter state.
222 * @param port reserved port to release
223 */ 418 */
224void 419void
225GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, 420GNUNET_TESTING_interpreter_skip (
226 uint16_t port); 421 struct GNUNET_TESTING_Interpreter *is);
227 422
228 423
229/** 424/**
230 * Create a new configuration using the given configuration as a template; 425 * Callback over commands of an interpreter.
231 * ports and paths will be modified to select available ports on the local
232 * system. The default configuration will be available in PATHS section under
233 * the option DEFAULTCONFIG after the call. SERVICE_HOME is also set in PATHS
234 * section to the temporary directory specific to this configuration. If we run
235 * out of "*port" numbers, return #GNUNET_SYSERR.
236 * 426 *
237 * This is primarily a helper function used internally 427 * @param cls closure
238 * by #GNUNET_TESTING_peer_configure(). 428 * @param cmd a command to process
429 */
430typedef void
431(*GNUNET_TESTING_CommandIterator)(
432 void *cls,
433 const struct GNUNET_TESTING_Command *cmd);
434
435
436/**
437 * Iterates over all of the top-level commands of an
438 * interpreter.
239 * 439 *
240 * @param system system to use to coordinate resource usage 440 * @param[in] is interpreter to iterate over
241 * @param cfg template configuration to update 441 * @param asc true in execution order, false for reverse execution order
242 * @return #GNUNET_OK on success, 442 * @param cb function to call on each command
243 * #GNUNET_SYSERR on error - the configuration will 443 * @param cb_cls closure for cb
244 * be incomplete and should not be used there upon
245 */ 444 */
246int 445void
247GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 446GNUNET_TESTING_interpreter_commands_iterate (
248 struct GNUNET_CONFIGURATION_Handle *cfg); 447 struct GNUNET_TESTING_Interpreter *is,
448 bool asc,
449 GNUNET_TESTING_CommandIterator cb,
450 void *cb_cls);
451
249 452
250// FIXME: add dual to 'release' ports again... 453/* ************** Fundamental interpreter commands ************ */
251 454
252 455
253/** 456/**
254 * Configure a GNUnet peer. GNUnet must be installed on the local 457 * Create command array terminator.
255 * system and available in the PATH.
256 * 458 *
257 * @param system system to use to coordinate resource usage 459 * @return a end-command.
258 * @param cfg configuration to use; will be UPDATED (to reflect needed
259 * changes in port numbers and paths)
260 * @param key_number number of the hostkey to use for the peer
261 * @param id identifier for the daemon, will be set, can be NULL
262 * @param emsg set to freshly allocated error message (set to NULL on success),
263 * can be NULL
264 * @return handle to the peer, NULL on error
265 */ 460 */
266struct GNUNET_TESTING_Peer * 461struct GNUNET_TESTING_Command
267GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, 462GNUNET_TESTING_cmd_end (void);
268 struct GNUNET_CONFIGURATION_Handle *cfg,
269 uint32_t key_number,
270 struct GNUNET_PeerIdentity *id,
271 char **emsg);
272 463
273 464
274/** 465/**
275 * Obtain the peer identity from a peer handle. 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.
276 * 470 *
277 * @param peer peer handle for which we want the peer's identity 471 * @param label the command label.
278 * @param id identifier for the daemon, will be set 472 * @param batch array of CMDs to execute.
473 * @return the command.
279 */ 474 */
280void 475struct GNUNET_TESTING_Command
281GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 476GNUNET_TESTING_cmd_batch (
282 struct GNUNET_PeerIdentity *id); 477 const char *label,
478 struct GNUNET_TESTING_Command *batch);
283 479
284 480
285/** 481/**
286 * Start the peer. 482 * Performance counter.
483 */
484struct GNUNET_TESTING_Timer
485{
486 /**
487 * For which type of commands.
488 */
489 const char *prefix;
490
491 /**
492 * Total time spend in all commands of this type.
493 */
494 struct GNUNET_TIME_Relative total_duration;
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};
512
513/**
514 * Obtain performance data from the interpreter.
287 * 515 *
288 * @param peer peer to start 516 * @param label command label.
289 * @return #GNUNET_OK on success, 517 * @param[in,out] timers NULL-prefix terminated array that specifies what commands (by label) to obtain runtimes for
290 * #GNUNET_SYSERR on error (i.e. peer already running) 518 * @return the command
291 */ 519 */
292int 520struct GNUNET_TESTING_Command
293GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); 521GNUNET_TESTING_cmd_stat (
522 const char *label,
523 struct GNUNET_TESTING_Timer *timers);
294 524
295 525
296/** 526/**
297 * Stop the peer. This call is blocking as it kills the peer's main ARM process 527 * Set variable to command as side-effect of
298 * by sending a SIGTERM and waits on it. For asynchronous shutdown of peer, see 528 * running a command.
299 * GNUNET_TESTING_peer_stop_async().
300 * 529 *
301 * @param peer peer to stop 530 * @param name name of the variable to set
302 * @return #GNUNET_OK on success, 531 * @param cmd command to set to variable when run
303 * #GNUNET_SYSERR on error (i.e. peer not running) 532 * @return modified command
304 */ 533 */
305int 534struct GNUNET_TESTING_Command
306GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); 535GNUNET_TESTING_cmd_set_var (
536 const char *name,
537 struct GNUNET_TESTING_Command cmd);
307 538
308 539
309/** 540/**
310 * Destroy the peer. Releases resources locked during peer configuration. 541 * Command to create a barrier.
311 * If the peer is still running, it will be stopped AND a warning will be
312 * printed (users of the API should stop the peer explicitly first).
313 * 542 *
314 * @param peer peer to destroy 543 * @param label The label of this command.
544 * @param number_to_be_reached If this number of processes reached
545 * this barrier, all processes waiting at
546 * this barrier can pass it.
315 */ 547 */
316void 548struct GNUNET_TESTING_Command
317GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); 549GNUNET_TESTING_cmd_barrier_create (
550 const char *label,
551 unsigned int number_to_be_reached);
318 552
319 553
320/** 554/**
321 * Sends SIGTERM to the peer's main process 555 * If this command is executed the the process is signaling the master process
556 * that it reached a barrier. If this command is synchronous it will block.
322 * 557 *
323 * @param peer the handle to the peer 558 * @param label name for command.
324 * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL 559 * @param barrier_label The name of the barrier we waited for and which was reached.
325 * or upon any error while sending SIGTERM 560 * @return command.
326 */ 561 */
327int 562struct GNUNET_TESTING_Command
328GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer); 563GNUNET_TESTING_cmd_barrier_reached (
564 const char *label,
565 const char *barrier_label);
566
329 567
568#define GNUNET_TESTING_NETJAIL_START_SCRIPT "netjail_start.sh"
569
570#define GNUNET_TESTING_NETJAIL_STOP_SCRIPT "netjail_stop.sh"
330 571
331/** 572/**
332 * Waits for a peer to terminate. The peer's main process will also be destroyed. 573 * Create command.
333 * 574 *
334 * @param peer the handle to the peer 575 * @param label Name for the command.
335 * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL 576 * @param topology_data topology data
336 * or upon any error while waiting 577 * @param timeout Before this timeout is reached this cmd MUST finish.
578 * @return command.
337 */ 579 */
338int 580struct GNUNET_TESTING_Command
339GNUNET_TESTING_peer_wait (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);
340 585
341 586
342/** 587/**
343 * Callback to inform whether the peer is running or stopped. 588 * This command executes a shell script to setup the netjail environment.
344 * 589 *
345 * @param cls the closure given to GNUNET_TESTING_peer_stop_async() 590 * @param label name for command.
346 * @param peer the respective peer whose status is being reported 591 * @param script which script to run, e.g. #GNUNET_TESTING_NETJAIL_START_SCRIPT
347 * @param success #GNUNET_YES if the peer is stopped; #GNUNET_SYSERR upon any 592 * @param topology_config Configuration file for the test topology.
348 * error 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.
349 */ 595 */
350typedef void 596struct GNUNET_TESTING_Command
351(*GNUNET_TESTING_PeerStopCallback) (void *cls, 597GNUNET_TESTING_cmd_netjail_setup (
352 struct GNUNET_TESTING_Peer *peer, 598 const char *label,
353 int success); 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);
354 613
355 614
356/** 615/**
357 * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled 616 * Turn asynchronous command into non-blocking command by setting
358 * through the GNUNET_TESTING_PeerStopCallback(). 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.
359 * 623 *
360 * @param peer the peer to stop 624 * @param[in,out] cmd command to make non-blocking
361 * @param cb the callback to signal peer shutdown 625 * @return a finish-command.
362 * @param cb_cls closure for the @a cb
363 * @return #GNUNET_OK upon successfully giving the request to the ARM API (this
364 * does not mean that the peer is successfully stopped); #GNUNET_SYSERR
365 * upon any error.
366 */ 626 */
367int 627struct GNUNET_TESTING_Command
368GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, 628GNUNET_TESTING_cmd_make_unblocking (
369 GNUNET_TESTING_PeerStopCallback cb, 629 struct GNUNET_TESTING_Command cmd);
370 void *cb_cls);
371 630
372 631
373/** 632/**
374 * Cancel a previous asynchronous peer stop request. 633 * Create (synchronous) command that waits for another command to finish.
375 * GNUNET_TESTING_peer_stop_async() should have been called before on the given 634 * If @a cmd_ref did not finish after @a timeout, this command will fail
376 * peer. It is an error to call this function if the peer stop callback was 635 * the test case.
377 * already called
378 * 636 *
379 * @param peer the peer on which GNUNET_TESTING_peer_stop_async() was called 637 * @param finish_label label for this command
380 * before. 638 * @param cmd_ref reference to a previous command which we should
639 * wait for (call `finish()` on)
640 * @param timeout how long to wait at most for @a cmd_ref to finish
641 * @return a finish-command.
381 */ 642 */
382void 643const struct GNUNET_TESTING_Command
383GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer); 644GNUNET_TESTING_cmd_finish (
645 const char *finish_label,
646 const char *cmd_ref,
647 struct GNUNET_TIME_Relative timeout);
648
649
650/**
651 * Create a "signal" CMD.
652 *
653 * @param label command label.
654 * @param process_label label of a command that has a process trait
655 * @param signal signal to send to @a process.
656 * @return the command.
657 */
658struct GNUNET_TESTING_Command
659GNUNET_TESTING_cmd_signal (
660 const char *label,
661 const char *process_label,
662 int signal);
663
664
665/**
666 * Sleep for @a duration.
667 *
668 * @param label command label.
669 * @param duration time to sleep
670 * @return the command.
671 */
672struct GNUNET_TESTING_Command
673GNUNET_TESTING_cmd_sleep (
674 const char *label,
675 struct GNUNET_TIME_Relative duration);
676
677
678/**
679 * Command to execute a command.
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 ...);
384 702
385 703
386/** 704/**
387 * Signature of the 'main' function for a (single-peer) testcase that 705 * Make the instruction pointer point to @a target_label
388 * is run using #GNUNET_TESTING_peer_run(). 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.
389 * 728 *
390 * @param cls closure 729 * @param cls closure
391 * @param cfg configuration of the peer that was started 730 * @param rv #GNUNET_OK if the test passed
392 * @param peer identity of the peer that was created
393 */ 731 */
394typedef void 732typedef void
395(*GNUNET_TESTING_TestMain) (void *cls, 733(*GNUNET_TESTING_ResultCallback)(
396 const struct GNUNET_CONFIGURATION_Handle *cfg, 734 void *cls,
397 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);
398 755
399 756
400/** 757/**
401 * 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
402 * Starts a peer using the given configuration and then invokes the 759 * success. Expected to be called directly from main().
403 * given callback. This function ALSO initializes the scheduler loop
404 * and should thus be called directly from "main". The testcase
405 * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown().
406 * 760 *
407 * @param testdir only the directory name without any path. This is used for 761 * @param commands the list of command to execute
408 * all service homes; the directory will be created in a temporary 762 * @param timeout how long to wait for each command to execute
409 * location depending on the underlying OS 763 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
410 * @param cfgfilename name of the configuration file to use;
411 * use NULL to only run with defaults
412 * @param tm main function of the testcase
413 * @param tm_cls closure for @a tm
414 * @return 0 on success, 1 on error
415 */ 764 */
416int 765int
417GNUNET_TESTING_peer_run (const char *testdir, 766GNUNET_TESTING_main (
418 const char *cfgfilename, 767 const struct GNUNET_TESTING_Command *commands,
419 GNUNET_TESTING_TestMain tm, 768 struct GNUNET_TIME_Relative timeout);
420 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);
421 841
422 842
423/** 843/**
424 * Start a single service (no ARM, except of course if the given 844 * Obtain value of a trait from a command.
425 * service name is 'arm') and run a test using the testing library.
426 * Starts a service using the given configuration and then invokes the
427 * given callback. This function ALSO initializes the scheduler loop
428 * and should thus be called directly from "main". The testcase
429 * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown().
430 * 845 *
431 * This function is useful if the testcase is for a single service 846 * @param traits the array of all the traits.
432 * 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.
433 * 863 *
434 * @param testdir only the directory name without any path. This is used for 864 * @param prefix symbol prefix to use
435 * all service homes; the directory will be created in a temporary 865 * @param name name of the trait
436 * location depending on the underlying OS 866 * @param type data type for the trait
437 * @param service_name name of the service to run
438 * @param cfgfilename name of the configuration file to use;
439 * use NULL to only run with defaults
440 * @param tm main function of the testcase
441 * @param tm_cls closure for @a tm
442 * @return 0 on success, 1 on error
443 */ 867 */
444int 868#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \
445GNUNET_TESTING_service_run (const char *testdir, 869 enum GNUNET_GenericReturnValue \
446 const char *service_name, 870 prefix ## _get_trait_ ## name ( \
447 const char *cfgfilename, 871 const struct GNUNET_TESTING_Command *cmd, \
448 GNUNET_TESTING_TestMain tm, 872 type * *ret); \
449 void *tm_cls); 873 struct GNUNET_TESTING_Trait \
874 prefix ## _make_trait_ ## name ( \
875 type * value);
450 876
451 877
452/** 878/**
453 * Sometimes we use the binary name to determine which specific 879 * Create C implementation for a trait with name @a name for statically
454 * test to run. In those cases, the string after the last "_" 880 * allocated data of type @a type.
455 * in 'argv[0]' specifies a string that determines the configuration
456 * file or plugin to use.
457 * 881 *
458 * This function returns the respective substring, taking care 882 * @param prefix symbol prefix to use
459 * 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.
460 * 913 *
461 * @param argv0 the name of the binary 914 * @param prefix symbol prefix to use
462 * @return string between the last '_' and the '.exe' (or the end of the string), 915 * @param name name of the trait
463 * NULL if argv0 has no '_' 916 * @param type data type for the trait
464 */ 917 */
465char * 918#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \
466GNUNET_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);
467 928
468 929
469#if 0 /* keep Emacsens' auto-indent happy */ 930/**
470{ 931 * Create C implementation for a trait with name @a name for statically
471#endif 932 * allocated data of type @a type.
472#ifdef __cplusplus 933 */
473} 934#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \
474#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 }
475 959
476#endif
477 960
478/** @} */ /* 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
479 972
480/** @} */ /* end of group addition */ 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 106d7cdae..000000000
--- a/src/include/gnunet_testing_netjail_lib.h
+++ /dev/null
@@ -1,525 +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_testing_ng_lib.h"
31#include "gnunet_testing_plugin.h"
32
33struct GNUNET_TESTING_AsyncContext;
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_NodeType
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_NodeType 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 * Head of the DLL with the connections which shall be established to other nodes.
149 */
150 struct GNUNET_TESTING_NodeConnection *node_connections_head;
151
152 /**
153 * Tail of the DLL with the connections which shall be established to other nodes.
154 */
155 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
156
157 /**
158 * Plugin for the test case to be run on this node.
159 */
160 char *plugin;
161
162 /**
163 * Flag indicating if this node is a global known node.
164 */
165 unsigned int is_global;
166
167 /**
168 * The number of the subnet this node is running in.
169 */
170 unsigned int namespace_n;
171
172 /**
173 * The number of this node in the subnet.
174 */
175 unsigned int node_n;
176
177 /**
178 * The overall number of the node in the whole test system.
179 */
180 unsigned int node_number;
181
182 /**
183 * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value.
184 */
185 unsigned int additional_connects;
186
187 /**
188 * The number of cmds waiting for a specific barrier.
189 */
190 unsigned int expected_reaches;
191};
192
193
194/**
195 * Subnet in a topology.
196 */
197struct GNUNET_TESTING_NetjailNamespace
198{
199 /**
200 * The number of the subnet.
201 */
202 unsigned int namespace_n;
203
204 /**
205 * Router of the subnet.
206 */
207 struct GNUNET_TESTING_NetjailRouter *router;
208
209 /**
210 * Hash map containing the nodes in this subnet.
211 */
212 struct GNUNET_CONTAINER_MultiShortmap *nodes;
213};
214
215/**
216 * Toplogy of our netjail setup.
217 */
218struct GNUNET_TESTING_NetjailTopology
219{
220
221 /**
222 * Default plugin for the test case to be run on nodes.
223 */
224 char *plugin;
225
226 /**
227 * Number of subnets.
228 */
229 unsigned int namespaces_n;
230
231 /**
232 * Number of nodes per subnet.
233 */
234 unsigned int nodes_m;
235
236 /**
237 * Number of global known nodes.
238 */
239 unsigned int nodes_x;
240
241 /**
242 * Hash map containing the subnets (for natted nodes) of the topology.
243 */
244 struct GNUNET_CONTAINER_MultiShortmap *map_namespaces;
245
246 /**
247 * Hash map containing the global known nodes which are not natted.
248 */
249 struct GNUNET_CONTAINER_MultiShortmap *map_globals;
250
251 /**
252 * Additional connects we do expect, beside the connects which are configured in the topology.
253 */
254 unsigned int additional_connects;
255};
256
257/**
258 * Getting the topology from file.
259 *
260 * @param filename The name of the topology file.
261 * @return The GNUNET_TESTING_NetjailTopology
262 */
263struct GNUNET_TESTING_NetjailTopology *
264GNUNET_TESTING_get_topo_from_file (const char *filename);
265
266
267/**
268 * FIXME: this could use a "to_string".
269 * Parse the topology data.
270 *
271 * @param data The topology data.
272 * @return The GNUNET_TESTING_NetjailTopology
273 */
274struct GNUNET_TESTING_NetjailTopology *
275GNUNET_TESTING_get_topo_from_string (const char *data);
276
277
278/**
279 * Get the number of unintentional additional connections the node waits for.
280 *
281 * @param num The specific node we want the additional connects for.
282 * @return The number of additional connects
283 */
284unsigned int
285GNUNET_TESTING_get_additional_connects (unsigned int num,
286 struct GNUNET_TESTING_NetjailTopology *
287 topology);
288
289/**
290 * Get a node from the topology.
291 *
292 * @param num The specific node we want the connections for.
293 * @param topology The topology we get the connections from.
294 * @return The connections of the node.
295 */
296struct GNUNET_TESTING_NetjailNode *
297GNUNET_TESTING_get_node (unsigned int num,
298 struct GNUNET_TESTING_NetjailTopology *topology);
299
300
301/**
302 * Get the connections to other nodes for a specific node.
303 *
304 * @param num The specific node we want the connections for.
305 * @param topology The topology we get the connections from.
306 * @return The connections of the node.
307 */
308struct GNUNET_TESTING_NodeConnection *
309GNUNET_TESTING_get_connections (unsigned int num,
310 const struct GNUNET_TESTING_NetjailTopology *topology);
311
312
313/**
314 * Get the address for a specific communicator from a connection.
315 *
316 * @param connection The connection we like to have the address from.
317 * @param prefix The communicator protocol prefix.
318 * @return The address of the communicator.
319 */
320char *
321GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
322 const char *prefix);
323
324
325/**
326 * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
327 *
328 * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
329 */
330void
331GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
332
333
334/**
335 * Calculate the unique id identifying a node from a given connection.
336 *
337 * @param node_connection The connection we calculate the id from.
338 * @param topology The topology we get all needed information from.
339 * @return The unique id of the node from the connection.
340 */
341unsigned int
342GNUNET_TESTING_calculate_num (struct
343 GNUNET_TESTING_NodeConnection *node_connection,
344 struct GNUNET_TESTING_NetjailTopology *topology);
345
346/**
347 * Struct with information for callbacks.
348 *
349 */
350struct GNUNET_TESTING_BlockState
351{
352 /**
353 * Context for our asynchronous completion.
354 */
355 struct GNUNET_TESTING_AsyncContext ac;
356
357 /**
358 * The label of this command.
359 */
360 const char *label;
361
362 /**
363 * If this command will block.
364 */
365 unsigned int asynchronous_finish;
366};
367
368/**
369 * Struct to hold information for callbacks.
370 *
371 */
372struct GNUNET_TESTING_LocalPreparedState
373{
374 /**
375 * Context for our asynchronous completion.
376 */
377 struct GNUNET_TESTING_AsyncContext ac;
378
379 /**
380 * Callback to write messages to the master loop.
381 *
382 */
383 GNUNET_TESTING_cmd_helper_write_cb write_message;
384};
385
386/**
387 * This command destroys the ressources allocated for the test system setup.
388 *
389 * @param label Name for command.
390 * @param create_label Label of the cmd which started the test system.
391 * @param write_message Callback to write messages to the master loop.
392 * @return command.
393 */
394struct GNUNET_TESTING_Command
395GNUNET_TESTING_cmd_system_destroy (const char *label,
396 const char *create_label);
397
398/**
399 * This command is setting up a test environment for a peer to start.
400 *
401 * @param label Name for command.
402 * @param testdir Only the directory name without any path. Temporary
403 * directory used for all service homes.
404 */
405struct GNUNET_TESTING_Command
406GNUNET_TESTING_cmd_system_create (const char *label,
407 const char *testdir);
408
409
410/**
411 * This command executes a shell script to setup the netjail environment.
412 *
413 * @param label name for command.
414 * @param topology_config Configuration file for the test topology.
415 * @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.
416 * @return command.
417 */
418struct GNUNET_TESTING_Command
419GNUNET_TESTING_cmd_netjail_start (const char *label,
420 char *topology_config,
421 unsigned int *read_file);
422
423
424/**
425 * This command executes a shell script to remove the netjail environment.
426 *
427 * @param label name for command.
428 * @param topology_config Configuration file for the test topology.
429 * @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.
430 * @return command.
431 */
432struct GNUNET_TESTING_Command
433GNUNET_TESTING_cmd_netjail_stop (const char *label,
434 char *topology_config,
435 unsigned int *read_file);
436
437
438/**
439 * This command executes a shell script which starts a helper process.
440 * This process is running on a netjail node, executing a defined test case.
441 *
442 * @param label Name for the command.
443 * @param topology The complete topology information.
444 * @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.
445 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
446 * @param timeout Before this timeout is reached this cmd MUST finish.
447 * @return command.
448 */
449struct GNUNET_TESTING_Command
450GNUNET_TESTING_cmd_netjail_start_cmds_helper (
451 const char *label,
452 struct GNUNET_TESTING_NetjailTopology *topology,
453 unsigned int *read_file,
454 char *topology_data,
455 struct GNUNET_TIME_Relative timeout);
456
457
458/**
459 * Create command.
460 *
461 * @param label name for command.
462 * @param helper_start_label label of the cmd to start the test system.
463 * @param topology The complete topology information.
464 * @return command.
465 */
466struct GNUNET_TESTING_Command
467GNUNET_TESTING_cmd_stop_cmds_helper (
468 const char *label,
469 const char *helper_start_label,
470 struct GNUNET_TESTING_NetjailTopology *topology);
471
472
473/**
474 * This command is used to block the loop, until the command is finished by other commands,
475 * using a trait to get this commands struct GNUNET_TESTING_AsyncContext.
476 *
477 * @param label name for command.
478 * @return command.
479 */
480struct GNUNET_TESTING_Command
481GNUNET_TESTING_cmd_block_until_external_trigger (
482 const char *label);
483
484/**
485 * DEPRECATED
486 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
487 *
488 * @param label name for command.
489 * @param write_message Callback to write messages to the master loop.
490 * @return command.
491 */
492struct GNUNET_TESTING_Command
493GNUNET_TESTING_cmd_send_peer_ready (const char *label,
494 GNUNET_TESTING_cmd_helper_write_cb write_message);
495
496
497/**
498 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop.
499 *
500 * @param label name for command.
501 * @param write_message Callback to write messages to the master loop.
502 * @return command.
503 */
504struct GNUNET_TESTING_Command
505GNUNET_TESTING_cmd_local_test_prepared (const char *label,
506 GNUNET_TESTING_cmd_helper_write_cb
507 write_message);
508
509
510/* ***** Netjail trait support ***** */
511
512
513/**
514 * Call #op on all simple traits.
515 */
516#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op) \
517 op (test_system, const struct GNUNET_TESTING_System) \
518 op (async_context, const struct GNUNET_TESTING_AsyncContext) \
519 op (helper_handles, const struct GNUNET_HELPER_Handle *) \
520 op (local_prepared_state, const struct GNUNET_TESTING_LocalPreparedState) \
521 op (block_state, const struct GNUNET_TESTING_BlockState)
522
523GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
524
525#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
deleted file mode 100644
index aae918ff3..000000000
--- a/src/include/gnunet_testing_ng_lib.h
+++ /dev/null
@@ -1,722 +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
31#include "gnunet_util_lib.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 * Maximum length of label in command
44 */
45#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
46
47/* ********************* Helper functions ********************* */
48
49/**
50 * Print failing line number and trigger shutdown. Useful
51 * quite any time after the command "run" method has been called.
52 */
53#define GNUNET_TESTING_FAIL(is) \
54 do \
55 { \
56 GNUNET_break (0); \
57 GNUNET_TESTING_interpreter_fail (is); \
58 return; \
59 } while (0)
60
61
62/* ******************* Generic interpreter logic ************ */
63
64/**
65 * Global state of the interpreter, used by a command
66 * to access information about other commands.
67 */
68struct GNUNET_TESTING_Interpreter;
69
70/**
71 * State each asynchronous command must have in its closure.
72 */
73struct GNUNET_TESTING_AsyncContext
74{
75
76 /**
77 * Interpreter we are part of.
78 */
79 struct GNUNET_TESTING_Interpreter *is;
80
81 /**
82 * Function to call when done.
83 */
84 GNUNET_SCHEDULER_TaskCallback cont;
85
86 /**
87 * Closure for @e cont.
88 */
89 void *cont_cls;
90
91 /**
92 * Indication if the command finished (#GNUNET_OK).
93 * #GNUNET_NO if it did not finish,
94 * #GNUNET_SYSERR if it failed.
95 */
96 enum GNUNET_GenericReturnValue finished;
97};
98
99typedef void
100(*GNUNET_TESTING_CommandRunRoutine)(void *cls,
101 struct GNUNET_TESTING_Interpreter *is);
102
103typedef void
104(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
105
106typedef enum GNUNET_GenericReturnValue
107(*GNUNET_TESTING_CommandGetTraits) (void *cls,
108 const void **ret,
109 const char *trait,
110 unsigned int index);
111
112/**
113 * Create a new command
114 *
115 * @param cls the closure
116 * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
117 * @param run the run routing
118 * @param cleanup the cleanup function
119 * @param traits the traits function (optional)
120 * @param the async context
121 * @return the command the function cannot fail
122 */
123struct GNUNET_TESTING_Command
124GNUNET_TESTING_command_new (void *cls,
125 const char *label,
126 GNUNET_TESTING_CommandRunRoutine run,
127 GNUNET_TESTING_CommandCleanupRoutine cleanup,
128 GNUNET_TESTING_CommandGetTraits traits,
129 struct GNUNET_TESTING_AsyncContext *ac);
130
131/**
132 * A command to be run by the interpreter.
133 */
134struct GNUNET_TESTING_Command
135{
136 /**
137 * Closure for all commands with command-specific context information.
138 */
139 void *cls;
140
141 /**
142 * Label for the command.
143 */
144 char label[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
145
146 /**
147 * Runs the command. Note that upon return, the interpreter
148 * will not automatically run the next command, as the command
149 * may continue asynchronously in other scheduler tasks. Thus,
150 * the command must ensure to eventually call
151 * #GNUNET_TESTING_interpreter_next() or
152 * #GNUNET_TESTING_interpreter_fail().
153 *
154 * If this function creates some asynchronous activity, it should
155 * initialize @e finish to a function that can be used to wait for
156 * the asynchronous activity to terminate.
157 *
158 * @param cls closure
159 * @param is interpreter state
160 */
161 GNUNET_TESTING_CommandRunRoutine run;
162
163 /**
164 * Pointer to the asynchronous context in the command's
165 * closure. Used by the
166 * #GNUNET_TESTING_async_finish() and
167 * #GNUNET_TESTING_async_fail() functions.
168 *
169 * Must be NULL if a command is synchronous.
170 */
171 struct GNUNET_TESTING_AsyncContext *ac;
172
173 /**
174 * Clean up after the command. Run during forced termination
175 * (CTRL-C) or test failure or test success.
176 *
177 * @param cls closure
178 */
179 GNUNET_TESTING_CommandCleanupRoutine cleanup;
180
181 /**
182 * Extract information from a command that is useful for other
183 * commands. Can be NULL if a command has no traits.
184 *
185 * @param cls closure
186 * @param[out] ret result (could be anything)
187 * @param trait name of the trait
188 * @param index index number of the object to extract.
189 * @return #GNUNET_OK on success,
190 * #GNUNET_NO if no trait was found
191 */
192 GNUNET_TESTING_CommandGetTraits traits;
193
194 /**
195 * When did the execution of this command start?
196 */
197 struct GNUNET_TIME_Absolute start_time;
198
199 /**
200 * When did the execution of this command finish?
201 */
202 struct GNUNET_TIME_Absolute finish_time;
203
204 /**
205 * When did we start the last run of this command? Delta to @e finish_time
206 * gives the latency for the last successful run. Useful in case @e
207 * num_tries was positive and the command was run multiple times. In that
208 * case, the @e start_time gives the time when we first tried to run the
209 * command, so the difference between @e start_time and @e finish_time would
210 * be the time all of the @e num_tries took, while the delta to @e
211 * last_req_time is the time the last (successful) execution took.
212 */
213 struct GNUNET_TIME_Absolute last_req_time;
214
215 /**
216 * In case @e asynchronous_finish is true, how long should we wait for this
217 * command to complete? If @e finish did not complete after this amount of
218 * time, the interpreter will fail. Should be set generously to ensure
219 * tests do not fail on slow systems.
220 */
221 struct GNUNET_TIME_Relative default_timeout;
222
223 /**
224 * How often did we try to execute this command? (In case it is a request
225 * that is repated.) Note that a command must have some built-in retry
226 * mechanism for this value to be useful.
227 */
228 unsigned int num_tries;
229
230 /**
231 * If "true", the interpreter should not immediately call
232 * @e finish, even if @e finish is non-NULL. Otherwise,
233 * #GNUNET_TESTING_cmd_finish() must be used
234 * to ensure that a command actually completed.
235 */
236 bool asynchronous_finish;
237
238};
239
240
241/**
242 * Lookup command by label.
243 * Only future commands 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_future_command (
251 struct GNUNET_TESTING_Interpreter *is,
252 const char *label);
253
254
255/**
256 * Lookup command by label.
257 *
258 * @param is interpreter to lookup command in
259 * @param label label of the command to lookup.
260 * @return the command, if it is found, or NULL.
261 */
262const struct GNUNET_TESTING_Command *
263GNUNET_TESTING_interpreter_lookup_command (
264 struct GNUNET_TESTING_Interpreter *is,
265 const char *label);
266
267
268/**
269 * Lookup command by label.
270 * All commands, first into the past, then into the future are looked up.
271 *
272 * @param is interpreter to lookup command in
273 * @param label label of the command to lookup.
274 * @return the command, if it is found, or NULL.
275 */
276const struct GNUNET_TESTING_Command *
277GNUNET_TESTING_interpreter_lookup_command_all (
278 struct GNUNET_TESTING_Interpreter *is,
279 const char *label);
280
281
282/**
283 * Obtain label of the command being now run.
284 *
285 * @param is interpreter state.
286 * @return the label.
287 */
288const char *
289GNUNET_TESTING_interpreter_get_current_label (
290 struct GNUNET_TESTING_Interpreter *is);
291
292
293/**
294 * Current command failed, clean up and fail the test case.
295 *
296 * @param is interpreter state.
297 */
298void
299GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
300
301
302/**
303 * The asynchronous command of @a ac has failed.
304 *
305 * @param ac command-specific context
306 */
307void
308GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
309
310
311/**
312 * The asynchronous command of @a ac has finished.
313 *
314 * @param ac command-specific context
315 */
316void
317GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
318
319
320/**
321 * Create command array terminator.
322 *
323 * @return a end-command.
324 */
325struct GNUNET_TESTING_Command
326GNUNET_TESTING_cmd_end (void);
327
328
329/**
330 * Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
331 * FIXME: what is this API doing? Is it returning a new cmd which is unblocking?
332 * Is it modifying cmd?
333 * Looking at the code, it both modifying cmd AND returning a copy oO
334 *
335 * @param cmd command to make synchronous.
336 * @return a finish-command.
337 */
338struct GNUNET_TESTING_Command
339GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
340
341
342/**
343 * Create (synchronous) command that waits for another command to finish.
344 * If @a cmd_ref did not finish after @a timeout, this command will fail
345 * the test case.
346 *
347 * @param finish_label label for this command
348 * @param cmd_ref reference to a previous command which we should
349 * wait for (call `finish()` on)
350 * @param timeout how long to wait at most for @a cmd_ref to finish
351 * @return a finish-command.
352 */
353const struct GNUNET_TESTING_Command
354GNUNET_TESTING_cmd_finish (const char *finish_label,
355 const char *cmd_ref,
356 struct GNUNET_TIME_Relative timeout);
357
358
359/**
360 * Make the instruction pointer point to @a target_label
361 * only if @a counter is greater than zero.
362 *
363 * @param label command label
364 * @param target_label label of the new instruction pointer's destination after the jump;
365 * must be before the current instruction
366 * @param counter counts how many times the rewinding is to happen.
367 */
368struct GNUNET_TESTING_Command
369GNUNET_TESTING_cmd_rewind_ip (const char *label,
370 const char *target_label,
371 unsigned int counter);
372
373
374/**
375 * Function called with the final result of the test.
376 * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g.
377 * GNUNET_EC_TESTING_*)
378 *
379 * @param cls closure
380 * @param rv #GNUNET_OK if the test passed
381 */
382typedef void
383(*GNUNET_TESTING_ResultCallback)(void *cls,
384 enum GNUNET_GenericReturnValue rv);
385
386
387/**
388 * Run the testsuite. Note, CMDs are copied into
389 * the interpreter state because they are _usually_
390 * defined into the "run" method that returns after
391 * having scheduled the test interpreter.
392 *
393 * @param commands the array of command to execute
394 * @param timeout how long to wait for each command to execute
395 * @param rc function to call with the final result
396 * @param rc_cls closure for @a rc
397 * @return The interpreter.
398 */
399struct GNUNET_TESTING_Interpreter *
400GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
401 struct GNUNET_TIME_Relative timeout,
402 GNUNET_TESTING_ResultCallback rc,
403 void *rc_cls);
404
405
406/**
407 * Start a GNUnet scheduler event loop and
408 * run the testsuite. Return 0 upon success.
409 * Expected to be called directly from main().
410 * FIXME: Why is this commands array here not const?
411 *
412 * @param commands the list of command to execute
413 * @param timeout how long to wait for each command to execute
414 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
415 */
416int
417GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
418 struct GNUNET_TIME_Relative timeout);
419
420
421/* ************** Specific interpreter commands ************ */
422
423
424/**
425 * Check if the command is running.
426 * FIXME: Unused function.
427 *
428 * @param command The command to check.
429 * @return GNUNET_NO if the command is not running, GNUNET_YES if it is running.
430 */
431enum GNUNET_GenericReturnValue
432GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
433
434
435/**
436 * Check if a command is finished.
437 * FIXME: Unused function
438 *
439 * @param command The command to check.
440 * @return GNUNET_NO if the command is not finished, GNUNET_YES if it is finished.
441 */
442enum GNUNET_GenericReturnValue
443GNUNET_TESTING_finished (const struct GNUNET_TESTING_Command *command);
444
445
446/**
447 * Create a "signal" CMD.
448 *
449 * @param label command label.
450 * @param process_label label of a command that has a process trait
451 * @param process_index index of the process trait at @a process_label // FIXME: enum? needed?
452 * @param signal signal to send to @a process.
453 * @return the command.
454 */
455struct GNUNET_TESTING_Command
456GNUNET_TESTING_cmd_signal (const char *label,
457 const char *process_label,
458 unsigned int process_index,
459 int signal);
460
461
462/**
463 * Sleep for @a duration.
464 *
465 * @param label command label.
466 * @param duration time to sleep
467 * @return the command.
468 */
469struct GNUNET_TESTING_Command
470GNUNET_TESTING_cmd_sleep (const char *label,
471 struct GNUNET_TIME_Relative duration);
472
473
474/**
475 * Create a "batch" command. Such command takes a end_CMD-terminated array of
476 * CMDs and executed them. Once it hits the end CMD, it passes the control to
477 * the next top-level CMD, regardless of it being another batch or ordinary
478 * CMD.
479 *
480 * @param label the command label.
481 * @param batch array of CMDs to execute.
482 * @return the command.
483 */
484struct GNUNET_TESTING_Command
485GNUNET_TESTING_cmd_batch (const char *label,
486 struct GNUNET_TESTING_Command *batch);
487
488
489/**
490 * Performance counter.
491 * // FIXME: this might not belong here!
492 */
493struct GNUNET_TESTING_Timer
494{
495 /**
496 * For which type of commands.
497 */
498 const char *prefix;
499
500 /**
501 * Total time spend in all commands of this type.
502 */
503 struct GNUNET_TIME_Relative total_duration;
504
505 /**
506 * Total time spend waiting for the *successful* exeuction
507 * in all commands of this type.
508 */
509 struct GNUNET_TIME_Relative success_latency;
510
511 /**
512 * Number of commands summed up.
513 */
514 unsigned int num_commands;
515
516 /**
517 * Number of retries summed up.
518 */
519 unsigned int num_retries;
520};
521
522
523/**
524 * Retrieve peer identity from the test system with the unique node id.
525 *
526 * @param num The unique node id.
527 * @param tl_system The test system.
528 * @return The peer identity wrapping the public key.
529 */
530struct GNUNET_PeerIdentity *
531GNUNET_TESTING_get_peer (unsigned int num,
532 const struct GNUNET_TESTING_System *tl_system);
533
534
535/**
536 * Obtain performance data from the interpreter.
537 *
538 * @param timers what commands (by label) to obtain runtimes for
539 * @return the command
540 */
541struct GNUNET_TESTING_Command
542GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
543
544
545/* *** Generic trait logic for implementing traits ********* */
546
547/**
548 * A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
549 *
550 * Therefor the cmd which like to provide data to other cmds has to implement
551 * the trait function, where an array of traits is defined with the help of the
552 * GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the
553 * GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make
554 * use of the macros.
555 */
556struct GNUNET_TESTING_Trait
557{
558 /**
559 * Index number associated with the trait. This gives the
560 * possibility to have _multiple_ traits on offer under the
561 * same name.
562 */
563 unsigned int index;
564
565 /**
566 * Trait type, for example "reserve-pub" or "coin-priv".
567 */
568 const char *trait_name;
569
570 /**
571 * Pointer to the piece of data to offer.
572 */
573 const void *ptr;
574};
575
576
577/**
578 * "end" trait. Because traits are offered into arrays,
579 * this type of trait is used to mark the end of such arrays;
580 * useful when iterating over those.
581 */
582struct GNUNET_TESTING_Trait
583GNUNET_TESTING_trait_end (void);
584
585
586/**
587 * Extract a trait.
588 * FIXME: Naming. This is something like "contains trait".
589 *
590 * @param traits the array of all the traits.
591 * @param[out] ret where to store the result.
592 * @param trait type of the trait to extract.
593 * @param index index number of the trait to extract.
594 * @return #GNUNET_OK when the trait is found.
595 */
596enum GNUNET_GenericReturnValue
597GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
598 const void **ret,
599 const char *trait,
600 unsigned int index);
601
602
603/* ****** Specific traits supported by this component ******* */
604
605
606/**
607 * Create headers for a trait with name @a name for
608 * statically allocated data of type @a type.
609 */
610#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
611 enum GNUNET_GenericReturnValue \
612 GNUNET_TESTING_get_trait_ ## name ( \
613 const struct GNUNET_TESTING_Command *cmd, \
614 type **ret); \
615 struct GNUNET_TESTING_Trait \
616 GNUNET_TESTING_make_trait_ ## name ( \
617 type * value);
618
619
620/**
621 * Create C implementation for a trait with name @a name for statically
622 * allocated data of type @a type.
623 */
624#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
625 enum GNUNET_GenericReturnValue \
626 GNUNET_TESTING_get_trait_ ## name ( \
627 const struct GNUNET_TESTING_Command *cmd, \
628 type * *ret) \
629 { \
630 if (NULL == cmd->traits) return GNUNET_SYSERR; \
631 return cmd->traits (cmd->cls, \
632 (const void **) ret, \
633 GNUNET_S (name), \
634 0); \
635 } \
636 struct GNUNET_TESTING_Trait \
637 GNUNET_TESTING_make_trait_ ## name ( \
638 type * value) \
639 { \
640 struct GNUNET_TESTING_Trait ret = { \
641 .trait_name = GNUNET_S (name), \
642 .ptr = (const void *) value \
643 }; \
644 return ret; \
645 }
646
647
648/**
649 * Create headers for a trait with name @a name for
650 * statically allocated data of type @a type.
651 */
652#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
653 enum GNUNET_GenericReturnValue \
654 GNUNET_TESTING_get_trait_ ## name ( \
655 const struct GNUNET_TESTING_Command *cmd, \
656 unsigned int index, \
657 type **ret); \
658 struct GNUNET_TESTING_Trait \
659 GNUNET_TESTING_make_trait_ ## name ( \
660 unsigned int index, \
661 type *value);
662
663
664/**
665 * Create C implementation for a trait with name @a name for statically
666 * allocated data of type @a type.
667 */
668#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
669 enum GNUNET_GenericReturnValue \
670 GNUNET_TESTING_get_trait_ ## name ( \
671 const struct GNUNET_TESTING_Command *cmd, \
672 unsigned int index, \
673 type * *ret) \
674 { \
675 if (NULL == cmd->traits) return GNUNET_SYSERR; \
676 return cmd->traits (cmd->cls, \
677 (const void **) ret, \
678 GNUNET_S (name), \
679 index); \
680 } \
681 struct GNUNET_TESTING_Trait \
682 GNUNET_TESTING_make_trait_ ## name ( \
683 unsigned int index, \
684 type * value) \
685 { \
686 struct GNUNET_TESTING_Trait ret = { \
687 .index = index, \
688 .trait_name = GNUNET_S (name), \
689 .ptr = (const void *) value \
690 }; \
691 return ret; \
692 }
693
694
695/**
696 * Call #op on all simple traits.
697 */
698#define GNUNET_TESTING_SIMPLE_TRAITS(op) \
699 op (batch_cmds, struct GNUNET_TESTING_Command *) \
700 op (process, struct GNUNET_OS_Process *)
701
702
703/**
704 * Call #op on all indexed traits.
705 */
706#define GNUNET_TESTING_INDEXED_TRAITS(op) \
707 op (uint32, const uint32_t) \
708 op (uint64, const uint64_t) \
709 op (int64, const int64_t) \
710 op (uint, const unsigned int) \
711 op (string, const char) \
712 op (cmd, const struct GNUNET_TESTING_Command) \
713 op (uuid, const struct GNUNET_Uuid) \
714 op (time, const struct GNUNET_TIME_Absolute) \
715 op (absolute_time, const struct GNUNET_TIME_Absolute) \
716 op (relative_time, const struct GNUNET_TIME_Relative)
717
718GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
719
720GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT)
721
722#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
deleted file mode 100644
index 12fbd7b75..000000000
--- a/src/include/gnunet_testing_plugin.h
+++ /dev/null
@@ -1,141 +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#include "gnunet_common.h"
32
33#ifdef __cplusplus
34extern "C"
35{
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41struct GNUNET_TESTING_Barrier;
42
43/**
44 * Callback function to write messages from the helper process running on a netjail node to the master process.
45 *
46 * @param message The message to write.
47 * @param msg_length The length of the message.
48 */
49typedef void
50(*GNUNET_TESTING_cmd_helper_write_cb) (struct GNUNET_MessageHeader *message,
51 size_t msg_length);
52
53/**
54 * Callback function which writes a message from the helper process running on a netjail node to the master process * signaling that the test case running on the netjail node finished.
55 */
56typedef void
57(*GNUNET_TESTING_cmd_helper_finish_cb) ();
58
59/**
60 * Function to be implemented for each test case plugin which starts the test case on a netjail node.
61 *
62 * @param write_message Callback function to write messages from the helper process running on a
63 * netjail node to the master process.
64 * @param router_ip Global address of the network namespace, if the helper process is for a node in a subnet.
65 * @param node_ip The IP address of the node.
66 * @param m The number of the node in a network namespace.
67 * @param n The number of the network namespace.
68 * @param local_m The number of nodes in a network namespace.
69 * @param topology_data A file name for the file containing the topology configuration, or a string containing
70 * the topology configuration.
71 * @param read_file If read_file is GNUNET_YES this string is the filename for the topology configuration,
72 * if read_file is GNUNET_NO the string contains the topology configuration.
73 * @param finish_cb Callback function which writes a message from the helper process running on a netjail
74 * node to the master process * signaling that the test case running on the netjail node finished.
75 * @return Returns The struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node.
76 */
77typedef struct GNUNET_TESTING_Interpreter *
78(*GNUNET_TESTING_PLUGIN_StartTestCase) (GNUNET_TESTING_cmd_helper_write_cb
79 write_message,
80 const char *router_ip,
81 const char *node_ip,
82 const char *n,
83 const char *m,
84 const char *local_m,
85 const char *topology_data,
86 unsigned int *read_file,
87 GNUNET_TESTING_cmd_helper_finish_cb finish_cb);
88
89/**
90 * DEPRECATED
91 * The helper process received a message of type
92 * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED. This will finish the blocking command
93 * GNUNET_TESTING_cmd_block_until_external_trigger which was execute right after the command
94 * GNUNET_TESTING_cmd_send_peer_ready.
95 */
96typedef void
97(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
98
99/**
100 * DEPRECATED
101 * The helper process received a message of type
102 * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED. This will finish the blocking command
103 * GNUNET_TESTING_cmd_local_test_prepared which was execute right after the command
104 * GNUNET_TRANSPORT_cmd_connect_peers.
105 */
106typedef void
107(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) ();
108
109/**
110 * This function returns a struct GNUNET_TESTING_BarrierList, which is a list of all barriers
111 * this test case will wait for.
112 *
113 * @return A struct GNUNET_TESTING_BarrierList.
114 */
115typedef struct GNUNET_TESTING_BarrierList*
116(*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void);
117
118
119/**
120 * The plugin API every test case plugin has to implement.
121 */
122struct GNUNET_TESTING_PluginFunctions
123{
124
125 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
126
127 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
128
129 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared;
130
131 GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS get_waiting_for_barriers;
132};
133
134#if 0 /* keep Emacsens' auto-indent happy */
135{
136#endif
137#ifdef __cplusplus
138}
139#endif
140
141#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 308aadb53..88dafc62c 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -619,6 +619,17 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
619 * Multiply relative time by a given factor. 619 * Multiply relative time by a given factor.
620 * 620 *
621 * @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
622 * @param factor integer to multiply with 633 * @param factor integer to multiply with
623 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 634 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
624 */ 635 */
diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h
index 6ec1aa578..c093ad96a 100644
--- a/src/include/gnunet_transport_application_service.h
+++ b/src/include/gnunet_transport_application_service.h
@@ -19,7 +19,7 @@
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone 21 * @addtogroup Backbone
22 * @{ 22 * @{
23 * 23 *
24 * @file 24 * @file
25 * Bandwidth allocation API for applications to interact with 25 * Bandwidth allocation API for applications to interact with
@@ -27,7 +27,7 @@
27 * @author Christian Grothoff 27 * @author Christian Grothoff
28 * @author Matthias Wachs 28 * @author Matthias Wachs
29 * 29 *
30 * @defgroup transport Transport service 30 * @defgroup TNG Transport Next Generation service
31 * @{ 31 * @{
32 */ 32 */
33#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H 33#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H
@@ -36,9 +36,6 @@
36 36
37#include "gnunet_constants.h" 37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
39#include "gnunet_nt_lib.h"
40#include "gnunet_testing_lib.h"
41#include "gnunet_testing_ng_lib.h"
42 39
43/** 40/**
44 * Handle to the TRANSPORT subsystem for making suggestions about 41 * Handle to the TRANSPORT subsystem for making suggestions about
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index b523f1536..ea947911f 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -27,7 +27,7 @@
27 * @file 27 * @file
28 * API of the transport service towards the communicator processes. 28 * API of the transport service towards the communicator processes.
29 * 29 *
30 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
31 * Low-level communication with other peers 31 * Low-level communication with other peers
32 * 32 *
33 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -47,7 +47,6 @@ extern "C" {
47 47
48 48
49#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
50#include "gnunet_nt_lib.h"
51 50
52/** 51/**
53 * Version number of the transport communication API. 52 * Version number of the transport communication API.
@@ -75,7 +74,7 @@ extern "C" {
75 * @param address where to send the message, human-readable 74 * @param address where to send the message, human-readable
76 * communicator-specific format, 0-terminated, UTF-8 75 * communicator-specific format, 0-terminated, UTF-8
77 * @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
78 * invalid 77 * invalid, #GNUNET_NO if this address is already (beging) connected to.
79 */ 78 */
80typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( 79typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) (
81 void *cls, 80 void *cls,
@@ -139,7 +138,7 @@ typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) (
139 * Connect to the transport service. 138 * Connect to the transport service.
140 * 139 *
141 * @param cfg configuration to use 140 * @param cfg configuration to use
142 * @param config_section_name section of the configuration to use for 141 * @param config_section_name section of the configuration to use for
143 * options 142 * options
144 * @param addr_prefix address prefix for addresses supported by this 143 * @param addr_prefix address prefix for addresses supported by this
145 * communicator, could be NULL for incoming-only communicators 144 * communicator, could be NULL for incoming-only communicators
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h
index 9153161d3..f7907a12d 100644
--- a/src/include/gnunet_transport_core_service.h
+++ b/src/include/gnunet_transport_core_service.h
@@ -26,7 +26,7 @@
26 * @file 26 * @file
27 * API of the transport service towards the CORE service (TNG version) 27 * API of the transport service towards the CORE service (TNG version)
28 * 28 *
29 * @defgroup transport TRANSPORT service 29 * @defgroup TNG Transport Next Generation service
30 * Communication with other peers 30 * Communication with other peers
31 * 31 *
32 * @see [Documentation](https://gnunet.org/transport-service) 32 * @see [Documentation](https://gnunet.org/transport-service)
diff --git a/src/include/gnunet_transport_hello_service.h b/src/include/gnunet_transport_hello_service.h
deleted file mode 100644
index 03305ec27..000000000
--- a/src/include/gnunet_transport_hello_service.h
+++ /dev/null
@@ -1,207 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * obtain information about our current address
29 *
30 * @deprecated, in TNG applications should query PEERSTORE directly!
31 *
32 * @defgroup transport Transport service
33 * address information
34 *
35 * @see [Documentation](https://gnunet.org/transport-service)
36 *
37 * @{
38 */
39#ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H
40#define GNUNET_TRANSPORT_HELLO_SERVICE_H
41
42#ifdef __cplusplus
43extern "C" {
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
49
50#include "gnunet_util_lib.h"
51#include "gnunet_ats_service.h"
52
53/**
54 * Version number of the transport API.
55 */
56#define GNUNET_TRANSPORT_HELLO_VERSION 0x00000000
57
58
59/**
60 * Some addresses contain sensitive information or are
61 * not suitable for global distribution. We use address
62 * classes to filter addresses by which domain they make
63 * sense to be used in. These are used in a bitmask.
64 */
65enum GNUNET_TRANSPORT_AddressClass
66{
67 /**
68 * No address.
69 */
70 GNUNET_TRANSPORT_AC_NONE = 0,
71
72 /**
73 * Addresses that fall into no other category
74 * (i.e. incoming which we cannot use elsewhere).
75 */
76 GNUNET_TRANSPORT_AC_OTHER = 1,
77
78 /**
79 * Addresses that are global and are insensitive
80 * (i.e. IPv4).
81 */
82 GNUNET_TRANSPORT_AC_GLOBAL = 2,
83
84 /**
85 * Addresses that are global and are sensitive
86 * (i.e. IPv6 with our MAC).
87 */
88 GNUNET_TRANSPORT_AC_GLOBAL_PRIVATE = 4,
89
90 /**
91 * Addresses useful in the local wired network,
92 * i.e. a MAC. Sensitive, but obvious to people nearby.
93 * Useful for broadcasts.
94 */
95 GNUNET_TRANSPORT_AC_LAN = 8,
96
97 /**
98 * Addresses useful in the local wireless network,
99 * i.e. a MAC. Sensitive, but obvious to people nearby.
100 * Useful for broadcasts.
101 */
102 GNUNET_TRANSPORT_AC_WLAN = 16,
103
104 /**
105 * Addresses useful in the local bluetooth network. Sensitive, but
106 * obvious to people nearby. Useful for broadcasts.
107 */
108 GNUNET_TRANSPORT_AC_BT = 32,
109
110 /**
111 * Bitmask for "any" address.
112 */
113 GNUNET_TRANSPORT_AC_ANY = 65535
114};
115
116
117/**
118 * Function called whenever there is an update to the
119 * HELLO of this peer.
120 *
121 * @param cls closure
122 * @param hello our updated HELLO
123 */
124typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (
125 void *cls,
126 const struct GNUNET_MessageHeader *hello);
127
128
129/**
130 * Handle to cancel a #GNUNET_TRANSPORT_hello_get() operation.
131 */
132struct GNUNET_TRANSPORT_HelloGetHandle;
133
134
135/**
136 * Obtain updates on changes to the HELLO message for this peer. The callback
137 * given in this function is never called synchronously.
138 *
139 * @param cfg configuration to use
140 * @param ac which network type should the addresses from the HELLO belong to?
141 * @param rec function to call with the HELLO
142 * @param rec_cls closure for @a rec
143 * @return handle to cancel the operation
144 */
145struct GNUNET_TRANSPORT_HelloGetHandle *
146GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
147 enum GNUNET_TRANSPORT_AddressClass ac,
148 GNUNET_TRANSPORT_HelloUpdateCallback rec,
149 void *rec_cls);
150
151
152/**
153 * Stop receiving updates about changes to our HELLO message.
154 *
155 * @param ghh handle to cancel
156 */
157void
158GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
159
160
161/**
162 * Function with addresses found in a HELLO.
163 *
164 * @param cls closure
165 * @param peer identity of the peer
166 * @param address the address (UTF-8, 0-terminated)
167 * @param nt network type of the address
168 * @param expiration when does this address expire?
169 */
170typedef void (*GNUNET_TRANSPORT_AddressCallback) (
171 void *cls,
172 const struct GNUNET_PeerIdentity *peer,
173 const char *address,
174 enum GNUNET_NetworkType nt,
175 struct GNUNET_TIME_Absolute expiration);
176
177
178/**
179 * Parse a HELLO message that we have received into its
180 * constituent addresses.
181 *
182 * @param hello message to parse
183 * @param cb function to call on each address found
184 * @param cb_cls closure for @a cb
185 * @return #GNUNET_OK if hello was well-formed, #GNUNET_SYSERR if not
186 */
187int
188GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello,
189 GNUNET_TRANSPORT_AddressCallback cb,
190 void *cb_cls);
191
192
193#if 0 /* keep Emacsens' auto-indent happy */
194{
195#endif
196#ifdef __cplusplus
197}
198#endif
199
200/* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */
201#endif
202
203/** @} */ /* end of group */
204
205/** @} */ /* end of group addition */
206
207/* 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 694ca7dca..000000000
--- a/src/include/gnunet_transport_manipulation_service.h
+++ /dev/null
@@ -1,123 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * Low-level P2P IO
29 *
30 * @defgroup transport Transport service
31 * Low-level P2P IO
32 *
33 * @see [Documentation](https://gnunet.org/transport-service)
34 *
35 * @{
36 */
37
38#ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
39#define GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
40
41
42#ifdef __cplusplus
43extern "C"
44{
45#if 0 /* keep Emacsens' auto-indent happy */
46}
47#endif
48#endif
49
50
51#include "gnunet_util_lib.h"
52#include "gnunet_ats_service.h"
53
54/**
55 * Version number of the transport API.
56 */
57#define GNUNET_TRANSPORT_MANIPULATION_VERSION 0x00000003
58
59/**
60 * Handle for transport manipulation.
61 */
62struct GNUNET_TRANSPORT_ManipulationHandle;
63
64
65/**
66 * Connect to the transport service. Note that the connection may
67 * complete (or fail) asynchronously.
68 *
69 * @param cfg configuration to use
70 * @return NULL on error
71 */
72struct GNUNET_TRANSPORT_ManipulationHandle *
73GNUNET_TRANSPORT_manipulation_connect (const struct
74 GNUNET_CONFIGURATION_Handle *cfg);
75
76
77/**
78 * Disconnect from the transport service.
79 *
80 * @param handle handle returned from connect
81 */
82void
83GNUNET_TRANSPORT_manipulation_disconnect (struct
84 GNUNET_TRANSPORT_ManipulationHandle *
85 handle);
86
87
88/**
89 * Set transport metrics for a peer and a direction
90 *
91 * @param handle transport handle
92 * @param peer the peer to set the metric for
93 * @param prop the performance metrics to set
94 * @param delay_in inbound delay to introduce
95 * @param delay_out outbound delay to introduce
96 *
97 * Note: Delay restrictions in receiving direction will be enforced
98 * with one message delay.
99 */
100void
101GNUNET_TRANSPORT_manipulation_set (struct
102 GNUNET_TRANSPORT_ManipulationHandle *handle,
103 const struct GNUNET_PeerIdentity *peer,
104 const struct GNUNET_ATS_Properties *prop,
105 struct GNUNET_TIME_Relative delay_in,
106 struct GNUNET_TIME_Relative delay_out);
107
108
109#if 0 /* keep Emacsens' auto-indent happy */
110{
111#endif
112#ifdef __cplusplus
113}
114#endif
115
116/* ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H */
117#endif
118
119/** @} */ /* end of group */
120
121/** @} */ /* end of group addition */
122
123/* 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 acf7ade69..7c586b51e 100644
--- a/src/include/gnunet_transport_monitor_service.h
+++ b/src/include/gnunet_transport_monitor_service.h
@@ -27,7 +27,7 @@
27 * @file 27 * @file
28 * Monitoring / diagnostics API for the transport service 28 * Monitoring / diagnostics API for the transport service
29 * 29 *
30 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
31 * Communication with other peers 31 * Communication with other peers
32 * 32 *
33 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -47,7 +47,6 @@ extern "C"
47 47
48 48
49#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
50#include "gnunet_ats_transport_service.h"
51#include "gnunet_transport_communication_service.h" 50#include "gnunet_transport_communication_service.h"
52 51
53 52
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
deleted file mode 100644
index 0ab4a995c..000000000
--- a/src/include/gnunet_transport_plugin.h
+++ /dev/null
@@ -1,733 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * Transport service plugin API
29 *
30 * @defgroup transport-plugin Transport Service plugin API
31 *
32 * Specifies the struct that is given to the plugin's entry method and the other
33 * struct that must be returned. Note that the destructors of transport plugins
34 * will be given the value returned by the constructor and is expected to return
35 * a NULL pointer.
36 *
37 * @{
38 */
39#ifndef PLUGIN_TRANSPORT_H
40#define PLUGIN_TRANSPORT_H
41
42
43#include "gnunet_configuration_lib.h"
44#include "gnunet_scheduler_lib.h"
45#include "gnunet_statistics_service.h"
46#include "gnunet_transport_service.h"
47#include "gnunet_ats_service.h"
48
49#define TRANSPORT_SESSION_INBOUND_STRING "<inbound>"
50
51/**
52 * Opaque pointer that plugins can use to distinguish specific
53 * connections to a given peer. Typically used by stateful plugins to
54 * allow the service to refer to specific streams instead of a more
55 * general notion of "some connection" to the given peer. This is
56 * useful since sometimes (e.g. for inbound TCP connections) a
57 * connection may not have an address that can be used for meaningful
58 * distinction between sessions to the same peer.
59 *
60 * Each 'struct GNUNET_ATS_Session' MUST start with the 'struct GNUNET_PeerIdentity'
61 * of the peer the session is for (which will be used for some error
62 * checking by the ATS code).
63 */
64struct GNUNET_ATS_Session;
65
66
67/**
68 * Function that will be called whenever the plugin internally
69 * cleans up a session pointer and hence the service needs to
70 * discard all of those sessions as well. Plugins that do not
71 * use sessions can simply omit calling this function and always
72 * use NULL wherever a session pointer is needed. This function
73 * should be called BEFORE a potential "TransmitContinuation"
74 * from the "TransmitFunction".
75 *
76 * @param cls closure
77 * @param peer which peer was the session for
78 * @param session which session is being destroyed
79 */
80typedef void
81(*GNUNET_TRANSPORT_SessionEnd) (void *cls,
82 const struct GNUNET_HELLO_Address *address,
83 struct GNUNET_ATS_Session *session);
84
85
86/**
87 * Plugin tells transport service about a new inbound session
88 *
89 * @param cls unused
90 * @param address the address
91 * @param session the new session
92 * @param net network information
93 */
94typedef void
95(*GNUNET_TRANSPORT_SessionStart) (void *cls,
96 const struct GNUNET_HELLO_Address *address,
97 struct GNUNET_ATS_Session *session,
98 enum GNUNET_NetworkType net);
99
100
101/**
102 * Function called by the transport for each received message.
103 * This function should also be called with "NULL" for the
104 * message to signal that the other peer disconnected.
105 *
106 * @param cls closure
107 * @param peer (claimed) identity of the other peer
108 * @param message the message, NULL if we only care about
109 * learning about the delay until we should receive again
110 * @param session identifier used for this session (NULL for plugins
111 * that do not offer bi-directional communication to the sender
112 * using the same "connection")
113 * @param sender_address binary address of the sender (if we established the
114 * connection or are otherwise sure of it; should be NULL
115 * for inbound TCP/UDP connections since it it not clear
116 * that we could establish ourselves a connection to that
117 * IP address and get the same system)
118 * @param sender_address_len number of bytes in @a sender_address
119 * @return how long the plugin should wait until receiving more data;
120 * returning #GNUNET_TIME_UNIT_FOREVER_REL means that the
121 * connection should be closed
122 */
123typedef struct GNUNET_TIME_Relative
124(*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
125 const struct
126 GNUNET_HELLO_Address *address,
127 struct GNUNET_ATS_Session *session,
128 const struct
129 GNUNET_MessageHeader *message);
130
131
132/**
133 * Function that can be called by plugins to figure if an address is
134 * an loopback, LAN or WAN address. Ultimately invokes
135 * #GNUNET_ATS_address_get_type().
136 *
137 * @param cls closure
138 * @param addr binary address
139 * @param addrlen length of the @a addr
140 * @return type of the network the address belongs to
141 */
142typedef enum GNUNET_NetworkType
143(*GNUNET_TRANSPORT_AddressToType)(void *cls,
144 const struct sockaddr *addr,
145 size_t addrlen);
146
147
148/**
149 * Function called when distance of an address changes.
150 *
151 * @param cls closure
152 * @param peer peer
153 * @param distance new distance
154 */
155typedef void
156(*GNUNET_TRANSPORT_UpdateAddressDistance) (void *cls,
157 const struct
158 GNUNET_HELLO_Address *address,
159 uint32_t distance);
160
161
162/**
163 * Function that will be called for each address the transport
164 * is aware that it might be reachable under.
165 *
166 * @param cls closure
167 * @param add_remove should the address added (#GNUNET_YES) or removed (#GNUNET_NO) from the
168 * set of valid addresses?
169 * @param address the address to add or remove
170 */
171typedef void
172(*GNUNET_TRANSPORT_AddressNotification) (void *cls,
173 int add_remove,
174 const struct
175 GNUNET_HELLO_Address *address);
176
177
178/**
179 * Function that will be called whenever the plugin receives data over
180 * the network and wants to determine how long it should wait until
181 * the next time it reads from the given peer. Note that some plugins
182 * (such as UDP) may not be able to wait (for a particular peer), so
183 * the waiting part is optional. Plugins that can wait should call
184 * this function, sleep the given amount of time, and call it again
185 * (with zero bytes read) UNTIL it returns zero and only then read.
186 *
187 * @param cls closure
188 * @param peer which peer did we read data from
189 * @param amount_recved number of bytes read (can be zero)
190 * @return how long to wait until reading more from this peer
191 * (to enforce inbound quotas); returning #GNUNET_TIME_UNIT_FOREVER_REL
192 * means that the connection should be closed
193 */
194typedef struct GNUNET_TIME_Relative
195(*GNUNET_TRANSPORT_TrafficReport) (void *cls,
196 const struct GNUNET_PeerIdentity *peer,
197 size_t amount_recved);
198
199
200/**
201 * Function that returns a HELLO message.
202 *
203 * @return HELLO message (FIXME with what?)
204 */
205typedef const struct GNUNET_MessageHeader *
206(*GNUNET_TRANSPORT_GetHelloCallback) (void);
207
208
209/**
210 * The transport service will pass a pointer to a struct
211 * of this type as the first and only argument to the
212 * entry point of each transport plugin.
213 */
214struct GNUNET_TRANSPORT_PluginEnvironment
215{
216 /**
217 * Configuration to use.
218 */
219 const struct GNUNET_CONFIGURATION_Handle *cfg;
220
221 /**
222 * Identity of this peer.
223 */
224 const struct GNUNET_PeerIdentity *my_identity;
225
226 /**
227 * Closure for the various callbacks.
228 */
229 void *cls;
230
231 /**
232 * Handle for reporting statistics.
233 */
234 struct GNUNET_STATISTICS_Handle *stats;
235
236 /**
237 * Function that should be called by the transport plugin
238 * whenever a message is received. If this field is "NULL",
239 * the plugin should load in 'stub' mode and NOT fully
240 * initialize and instead only return an API with the
241 * @e address_pretty_printer, @e address_to_string and
242 * @e string_to_address functions.
243 */
244 GNUNET_TRANSPORT_PluginReceiveCallback receive;
245
246 /**
247 * Function that returns our HELLO.
248 */
249 GNUNET_TRANSPORT_GetHelloCallback get_our_hello;
250
251 /**
252 * Function that must be called by each plugin to notify the
253 * transport service about the addresses under which the transport
254 * provided by the plugin can be reached.
255 */
256 GNUNET_TRANSPORT_AddressNotification notify_address;
257
258 /**
259 * Function that must be called by the plugin when a non-NULL
260 * session handle stops being valid (is destroyed).
261 */
262 GNUNET_TRANSPORT_SessionEnd session_end;
263
264 /**
265 * Function called by the plugin when a new (incoming) session was created
266 * not explicitly created using the the get_session function
267 */
268 GNUNET_TRANSPORT_SessionStart session_start;
269
270 /**
271 * Function that will be called to figure if an address is an loopback,
272 * LAN, WAN etc. address
273 */
274 GNUNET_TRANSPORT_AddressToType get_address_type;
275
276 /**
277 * Function that will be called by DV to update distance for
278 * an address.
279 */
280 GNUNET_TRANSPORT_UpdateAddressDistance update_address_distance;
281
282 /**
283 * What is the maximum number of connections that this transport
284 * should allow? Transports that do not have sessions (such as
285 * UDP) can ignore this value.
286 */
287 uint32_t max_connections;
288};
289
290
291/**
292 * Function called by the #GNUNET_TRANSPORT_TransmitFunction
293 * upon "completion". In the case that a peer disconnects,
294 * this function must be called for each pending request
295 * (with a 'failure' indication) AFTER notifying the service
296 * about the disconnect event (so that the service won't try
297 * to transmit more messages, believing the connection still
298 * exists...).
299 *
300 * @param cls closure
301 * @param target who was the recipient of the message?
302 * @param result #GNUNET_OK on success
303 * #GNUNET_SYSERR if the target disconnected;
304 * disconnect will ALSO be signalled using
305 * the ReceiveCallback.
306 * @param size_payload bytes of payload from transport service in message
307 * @param size_on_wire bytes required on wire for transmission,
308 * 0 if result == #GNUNET_SYSERR
309 */
310typedef void
311(*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
312 const struct
313 GNUNET_PeerIdentity *target,
314 int result,
315 size_t size_payload,
316 size_t size_on_wire);
317
318
319/**
320 * The new send function with just the session and no address
321 *
322 * Function that can be used by the transport service to transmit
323 * a message using the plugin. Note that in the case of a
324 * peer disconnecting, the continuation MUST be called
325 * prior to the disconnect notification itself. This function
326 * will be called with this peer's HELLO message to initiate
327 * a fresh connection to another peer.
328 *
329 * @param cls closure
330 * @param session which session must be used
331 * @param msgbuf the message to transmit
332 * @param msgbuf_size number of bytes in @a msgbuf
333 * @param priority how important is the message (most plugins will
334 * ignore message priority and just FIFO)
335 * @param to how long to wait at most for the transmission (does not
336 * require plugins to discard the message after the timeout,
337 * just advisory for the desired delay; most plugins will ignore
338 * this as well)
339 * @param cont continuation to call once the message has
340 * been transmitted (or if the transport is ready
341 * for the next transmission call; or if the
342 * peer disconnected...); can be NULL
343 * @param cont_cls closure for @a cont
344 * @return number of bytes used (on the physical network, with overheads);
345 * -1 on hard errors (i.e. address invalid); 0 is a legal value
346 * and does NOT mean that the message was not transmitted (DV)
347 */
348typedef ssize_t
349(*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
350 struct GNUNET_ATS_Session *session,
351 const char *msgbuf,
352 size_t msgbuf_size,
353 unsigned int priority,
354 struct GNUNET_TIME_Relative to,
355 GNUNET_TRANSPORT_TransmitContinuation cont,
356 void *cont_cls);
357
358
359/**
360 * Function that can be called to force a disconnect from the
361 * specified neighbour for the given session only. . This should
362 * also cancel all previously scheduled transmissions for this
363 * session. Obviously the transmission may have been partially
364 * completed already, which is OK. The plugin is supposed to close
365 * the connection (if applicable).
366 *
367 * @param cls closure with the `struct Plugin`
368 * @param session session to destroy
369 * @return #GNUNET_OK on success
370 */
371typedef int
372(*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls,
373 struct GNUNET_ATS_Session *
374 session);
375
376
377/**
378 * Function that is called to get the keepalive factor.
379 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
380 * calculate the interval between keepalive packets.
381 *
382 * @param cls closure with the `struct Plugin`
383 * @return keepalive factor
384 */
385typedef unsigned int
386(*GNUNET_TRANSPORT_QueryKeepaliveFactorFunction) (void *cls);
387
388
389/**
390 * Function that can be called to force a disconnect from the
391 * specified neighbour. This should also cancel all previously
392 * scheduled transmissions. Obviously the transmission may have been
393 * partially completed already, which is OK. The plugin is supposed
394 * to close the connection (if applicable) and no longer call the
395 * transmit continuation(s).
396 *
397 * @param cls closure
398 * @param target peer for which the last transmission is
399 * to be cancelled
400 */
401typedef void
402(*GNUNET_TRANSPORT_DisconnectPeerFunction) (void *cls,
403 const struct
404 GNUNET_PeerIdentity *target);
405
406
407/**
408 * Function called by the pretty printer for the resolved address for
409 * each human-readable address obtained. The callback can be called
410 * several times. The last invocation must be with a @a address of
411 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
412 * errors, the callback might be called first with @a address NULL and
413 * @a res being #GNUNET_SYSERR. In that case, there must still be a
414 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
415 *
416 * @param cls closure
417 * @param address one of the names for the host, NULL on last callback
418 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on failure,
419 * #GNUNET_OK on last callback
420 */
421typedef void
422(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
423 const char *address,
424 int res);
425
426
427/**
428 * Convert the transports address to a nice, human-readable
429 * format.
430 *
431 * @param cls closure
432 * @param type name of the transport that generated the address
433 * @param addr one of the addresses of the host, NULL for the last address
434 * the specific address format depends on the transport
435 * @param addrlen length of the @a addr
436 * @param numeric should (IP) addresses be displayed in numeric form?
437 * @param timeout after how long should we give up?
438 * @param asc function to call on each string
439 * @param asc_cls closure for @a asc
440 */
441typedef void
442(*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
443 const char *type,
444 const void *addr,
445 size_t addrlen,
446 int numeric,
447 struct GNUNET_TIME_Relative timeout,
448 GNUNET_TRANSPORT_AddressStringCallback
449 asc,
450 void *asc_cls);
451
452
453/**
454 * Another peer has suggested an address for this peer and transport
455 * plugin. Check that this could be a valid address. This function
456 * is not expected to 'validate' the address in the sense of trying to
457 * connect to it but simply to see if the binary format is technically
458 * legal for establishing a connection to this peer (and make sure that
459 * the address really corresponds to our network connection/settings
460 * and not some potential man-in-the-middle).
461 *
462 * @param addr pointer to the address
463 * @param addrlen length of @a addr
464 * @return #GNUNET_OK if this is a plausible address for this peer
465 * and transport, #GNUNET_SYSERR if not
466 */
467typedef int
468(*GNUNET_TRANSPORT_CheckAddress) (void *cls,
469 const void *addr,
470 size_t addrlen);
471
472
473/**
474 * Create a new session to transmit data to the target
475 * This session will used to send data to this peer and the plugin will
476 * notify us by calling the env->session_end function
477 *
478 * @param cls the plugin
479 * @param address the hello address
480 * @return the session if the address is valid, NULL otherwise
481 */
482typedef struct GNUNET_ATS_Session *
483(*GNUNET_TRANSPORT_CreateSession) (void *cls,
484 const struct GNUNET_HELLO_Address *address);
485
486
487/**
488 * Function that will be called whenever the transport service wants to
489 * notify the plugin that a session is still active and in use and
490 * therefore the session timeout for this session has to be updated
491 *
492 * @param cls closure
493 * @param peer which peer was the session for
494 * @param session which session is being updated
495 */
496typedef void
497(*GNUNET_TRANSPORT_UpdateSessionTimeout) (void *cls,
498 const struct
499 GNUNET_PeerIdentity *peer,
500 struct GNUNET_ATS_Session *session);
501
502
503/**
504 * Function that will be called whenever the transport service wants to
505 * notify the plugin that the inbound quota changed and that the plugin
506 * should update it's delay for the next receive value
507 *
508 * @param cls closure
509 * @param peer which peer was the session for
510 * @param session which session is being updated
511 * @param delay new delay to use for receiving
512 */
513typedef void
514(*GNUNET_TRANSPORT_UpdateInboundDelay) (void *cls,
515 const struct GNUNET_PeerIdentity *peer,
516 struct GNUNET_ATS_Session *session,
517 struct GNUNET_TIME_Relative delay);
518
519
520/**
521 * Function called for a quick conversion of the binary address to
522 * a numeric address. Note that the caller must not free the
523 * address and that the next call to this function is allowed
524 * to override the address again.
525 *
526 * @param cls closure
527 * @param addr binary address
528 * @param addr_len length of the @a addr
529 * @return string representing the same address
530 */
531typedef const char *
532(*GNUNET_TRANSPORT_AddressToString) (void *cls,
533 const void *addr,
534 size_t addrlen);
535
536
537/**
538 * Function called to convert a string address to
539 * a binary address.
540 *
541 * @param cls closure (`struct Plugin*`)
542 * @param addr string address
543 * @param addrlen length of the @a addr including \0 termination
544 * @param buf location to store the buffer
545 * If the function returns #GNUNET_SYSERR, its contents are undefined.
546 * @param added length of created address
547 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
548 */
549typedef int
550(*GNUNET_TRANSPORT_StringToAddress) (void *cls,
551 const char *addr,
552 uint16_t addrlen,
553 void **buf,
554 size_t *added);
555
556
557/**
558 * Function to obtain the network type for a session
559 *
560 * @param cls closure (`struct Plugin *`)
561 * @param session the session
562 * @return the network type
563 */
564typedef enum GNUNET_NetworkType
565(*GNUNET_TRANSPORT_GetNetworkType)(void *cls,
566 struct GNUNET_ATS_Session *session);
567
568
569/**
570 * Function to obtain the network type for an address.
571 *
572 * @param cls closure (`struct Plugin *`)
573 * @param address the address
574 * @return the network type
575 */
576typedef enum GNUNET_NetworkType
577(*GNUNET_TRANSPORT_GetNetworkTypeForAddress)(void *cls,
578 const struct
579 GNUNET_HELLO_Address *address);
580
581
582/**
583 * Function called by the plugin with information about the
584 * current sessions managed by the plugin (for monitoring).
585 *
586 * @param cls closure
587 * @param session session handle this information is about,
588 * NULL to indicate that we are "in sync" (initial
589 * iteration complete)
590 * @param info information about the state of the session,
591 * NULL if @a session is also NULL and we are
592 * merely signalling that the initial iteration is over
593 */
594typedef void
595(*GNUNET_TRANSPORT_SessionInfoCallback) (void *cls,
596 struct GNUNET_ATS_Session *session,
597 const struct
598 GNUNET_TRANSPORT_SessionInfo *info);
599
600
601/**
602 * Begin monitoring sessions of a plugin. There can only
603 * be one active monitor per plugin (i.e. if there are
604 * multiple monitors, the transport service needs to
605 * multiplex the generated events over all of them).
606 *
607 * @param cls closure of the plugin
608 * @param sic callback to invoke, NULL to disable monitor;
609 * plugin will being by iterating over all active
610 * sessions immediately and then enter monitor mode
611 * @param sic_cls closure for @a sic
612 */
613typedef void
614(*GNUNET_TRANSPORT_SessionMonitorSetup) (void *cls,
615 GNUNET_TRANSPORT_SessionInfoCallback
616 sic,
617 void *sic_cls);
618
619
620/**
621 * Each plugin is required to return a pointer to a struct of this
622 * type as the return value from its entry point.
623 */
624struct GNUNET_TRANSPORT_PluginFunctions
625{
626 /**
627 * Closure for all of the callbacks.
628 */
629 void *cls;
630
631 /**
632 * Function that the transport service will use to transmit data to
633 * another peer. May be NULL for plugins that only support
634 * receiving data. After this call, the plugin call the specified
635 * continuation with success or error before notifying us about the
636 * target having disconnected.
637 */
638 GNUNET_TRANSPORT_TransmitFunction send;
639
640 /**
641 * Function that can be used to force the plugin to disconnect from
642 * the given peer and cancel all previous transmissions (and their
643 * continuations).
644 */
645 GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer;
646
647 /**
648 * Function that can be used to force the plugin to disconnect from
649 * the given peer and cancel all previous transmissions (and their
650 * continuations).
651 */
652 GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session;
653
654 /**
655 * Function that will be called whenever the transport service wants to
656 * notify the plugin that a session is still active and in use and
657 * therefore the session timeout for this session has to be updated
658 */
659 GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout;
660
661 /**
662 * Function that will be called whenever the transport service wants to
663 * notify the plugin that the inbound quota changed and that the plugin
664 * should update it's delay for the next receive value
665 */
666 GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay;
667
668 /**
669 * Function that is used to query keepalive factor.
670 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
671 * calculate the interval between keepalive packets.
672 */
673 GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor;
674
675 /**
676 * Function to pretty-print addresses.
677 */
678 GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
679
680 /**
681 * Function that will be called to check if a binary address
682 * for this plugin is well-formed and corresponds to an
683 * address for THIS peer (as per our configuration). Naturally,
684 * if absolutely necessary, plugins can be a bit conservative in
685 * their answer, but in general plugins should make sure that the
686 * address does not redirect traffic to a 3rd party that might
687 * try to man-in-the-middle our traffic.
688 */
689 GNUNET_TRANSPORT_CheckAddress check_address;
690
691 /**
692 * Function that will be called to convert a binary address
693 * to a string (numeric conversion only).
694 */
695 GNUNET_TRANSPORT_AddressToString address_to_string;
696
697 /**
698 * Function that will be called to convert a string address
699 * to binary (numeric conversion only).
700 */
701 GNUNET_TRANSPORT_StringToAddress string_to_address;
702
703 /**
704 * Function that will be called tell the plugin to create a session
705 * object.
706 */
707 GNUNET_TRANSPORT_CreateSession get_session;
708
709 /**
710 * Function to obtain the network type for a session
711 */
712 GNUNET_TRANSPORT_GetNetworkType get_network;
713
714 /**
715 * Function to obtain the network type for an address
716 */
717 GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address;
718
719 /**
720 * Function to monitor the sessions managed by the plugin.
721 */
722 GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor;
723};
724
725
726/*#ifndef PLUGIN_TRANSPORT_H*/
727#endif
728
729/** @} */ /* end of group */
730
731/** @} */ /* end of group addition */
732
733/* 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 72cdbe0a7..000000000
--- a/src/include/gnunet_transport_service.h
+++ /dev/null
@@ -1,715 +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 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 *
27 * @file
28 * Low-level P2P IO
29 *
30 * @defgroup transport Transport service
31 * Low-level P2P IO
32 *
33 * @see [Documentation](https://gnunet.org/transport-service)
34 *
35 * @{
36 */
37
38#ifndef GNUNET_TRANSPORT_SERVICE_H
39#define GNUNET_TRANSPORT_SERVICE_H
40
41#ifdef __cplusplus
42extern "C" {
43#if 0 /* keep Emacsens' auto-indent happy */
44}
45#endif
46#endif
47
48
49#include "gnunet_util_lib.h"
50#include "gnunet_ats_service.h"
51
52/**
53 * Version number of the transport API.
54 */
55#define GNUNET_TRANSPORT_VERSION 0x00000003
56
57
58/* *************************** HELLO *************************** */
59
60/**
61 * Handle for a #GNUNET_TRANSPORT_offer_hello operation
62 */
63struct GNUNET_TRANSPORT_OfferHelloHandle;
64
65
66/**
67 * Offer the transport service the HELLO of another peer. Note that
68 * the transport service may just ignore this message if the HELLO is
69 * malformed or useless due to our local configuration.
70 *
71 * @param cfg configuration
72 * @param hello the hello message
73 * @param cont continuation to call when HELLO has been sent,
74 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
75 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
76 * @param cont_cls closure for @a cont
77 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on
78 * failure, in case of failure @a cont will not be called
79 *
80 */
81struct GNUNET_TRANSPORT_OfferHelloHandle *
82GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
83 const struct GNUNET_MessageHeader *hello,
84 GNUNET_SCHEDULER_TaskCallback cont,
85 void *cont_cls);
86
87
88/**
89 * Cancel the request to transport to offer the HELLO message
90 *
91 * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
92 */
93void
94GNUNET_TRANSPORT_offer_hello_cancel (
95 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
96
97
98/* *********************** Address to String ******************* */
99
100/**
101 * Handle to cancel a pending address lookup.
102 */
103struct GNUNET_TRANSPORT_AddressToStringContext;
104
105
106/**
107 * Function to call with a textual representation of an address. This
108 * function will be called several times with different possible
109 * textual representations, and a last time with @a address being NULL
110 * to signal the end of the iteration. Note that @a address NULL
111 * always is the last call, regardless of the value in @a res.
112 *
113 * @param cls closure
114 * @param address NULL on end of iteration,
115 * otherwise 0-terminated printable UTF-8 string,
116 * in particular an empty string if @a res is #GNUNET_NO
117 * @param res result of the address to string conversion:
118 * if #GNUNET_OK: conversion successful
119 * if #GNUNET_NO: address was invalid (or not supported)
120 * if #GNUNET_SYSERR: communication error (IPC error)
121 */
122typedef void
123(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
124 const char *address,
125 int res);
126
127
128/**
129 * Convert a binary address into a human readable address.
130 *
131 * @param cfg configuration to use
132 * @param address address to convert (binary format)
133 * @param numeric should (IP) addresses be displayed in numeric form
134 * (otherwise do reverse DNS lookup)
135 * @param timeout how long is the lookup allowed to take at most
136 * @param aluc function to call with the results
137 * @param aluc_cls closure for @a aluc
138 * @return handle to cancel the operation, NULL on error
139 */
140struct GNUNET_TRANSPORT_AddressToStringContext *
141GNUNET_TRANSPORT_address_to_string (
142 const struct GNUNET_CONFIGURATION_Handle *cfg,
143 const struct GNUNET_HELLO_Address *address,
144 int numeric,
145 struct GNUNET_TIME_Relative timeout,
146 GNUNET_TRANSPORT_AddressToStringCallback aluc,
147 void *aluc_cls);
148
149
150/**
151 * Cancel request for address conversion.
152 *
153 * @param alc the context handle
154 */
155void
156GNUNET_TRANSPORT_address_to_string_cancel (
157 struct GNUNET_TRANSPORT_AddressToStringContext *alc);
158
159
160/* *********************** Monitoring ************************** */
161
162
163/**
164 * Possible state of a neighbour. Initially, we are
165 * #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
166 *
167 * Then, there are two main paths. If we receive a SYN message, we give
168 * the inbound address to ATS. After the check we ask ATS for a suggestion
169 * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
170 * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
171 * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
172 * (and notify everyone about the new connection). If the operation times out,
173 * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
174 *
175 * The other case is where we transmit a SYN message first. We
176 * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
177 * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
178 * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
179 * (and notify everyone about the new connection and send
180 * back a ACK). If the operation times out, we go to
181 * #GNUNET_TRANSPORT_PS_DISCONNECT.
182 *
183 * If the session is in trouble (i.e. transport-level disconnect or
184 * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a
185 * new address (we don't notify anyone about the disconnect yet). Once we have
186 * a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a SYN
187 * message. If we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
188 * and nobody noticed that we had trouble; we also send a ACK at this time just
189 * in case. If the operation times out, we go to
190 * #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone about the lost
191 * connection).
192 *
193 * If ATS decides to switch addresses while we have a normal
194 * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
195 * and send a SESSION_CONNECT. If we get a ACK back, we switch the
196 * primary connection to the suggested alternative from ATS, go back
197 * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
198 * sure. If the operation times out
199 * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given
200 * alternative address is "invalid").
201 *
202 * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and
203 * then goes to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an
204 * explicit disconnect request, we can go from any state to
205 * #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after generating disconnect
206 * notifications.
207 *
208 * Note that it is quite possible that while we are in any of these
209 * states, we could receive a 'SYN' request from the other peer.
210 * We then enter a 'weird' state where we pursue our own primary state
211 * machine (as described above), but with the 'send_connect_ack' flag
212 * set to 1. If our state machine allows us to send a 'SYN_ACK'
213 * (because we have an acceptable address), we send the 'SYN_ACK'
214 * and set the 'send_connect_ack' to 2. If we then receive a
215 * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
216 * to 0).
217 *
218 */
219enum GNUNET_TRANSPORT_PeerState
220{
221 /**
222 * Fresh peer or completely disconnected
223 */
224 GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
225
226 /**
227 * Asked to initiate connection, trying to get address from ATS
228 */
229 GNUNET_TRANSPORT_PS_INIT_ATS,
230
231 /**
232 * Sent SYN message to other peer, waiting for SYN_ACK
233 */
234 GNUNET_TRANSPORT_PS_SYN_SENT,
235
236 /**
237 * Received a SYN, asking ATS about address suggestions.
238 */
239 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
240
241 /**
242 * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
243 */
244 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
245
246 /**
247 * Got our SYN_ACK/ACK, connection is up.
248 */
249 GNUNET_TRANSPORT_PS_CONNECTED,
250
251 /**
252 * Connection got into trouble, rest of the system still believes
253 * it to be up, but we're getting a new address from ATS.
254 */
255 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
256
257 /**
258 * Sent SYN over new address (either by ATS telling us to switch
259 * addresses or from RECONNECT_ATS); if this fails, we need to tell
260 * the rest of the system about a disconnect.
261 */
262 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
263
264 /**
265 * We have some primary connection, but ATS suggested we switch
266 * to some alternative; we now sent a SYN message for the
267 * alternative session to the other peer and waiting for a
268 * SYN_ACK to make this our primary connection.
269 */
270 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
271
272 /**
273 * Disconnect in progress (we're sending the DISCONNECT message to the
274 * other peer; after that is finished, the state will be cleaned up).
275 */
276 GNUNET_TRANSPORT_PS_DISCONNECT,
277
278 /**
279 * We're finished with the disconnect; and are cleaning up the state
280 * now! We put the struct into this state when we are really in the
281 * task that calls 'free' on it and are about to remove the record
282 * from the map. We should never find a 'struct NeighbourMapEntry'
283 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
284 * in this state virtually always means using memory that has been
285 * freed (the exception being the cleanup code in #free_neighbour()).
286 */
287 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
288};
289
290
291/**
292 * Convert a transport state to a human readable string.
293 *
294 * @param state the state
295 */
296const char *
297GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
298
299
300/**
301 * Check if a state is defined as connected
302 *
303 * @param state the state value
304 * @return #GNUNET_YES or #GNUNET_NO
305 */
306int
307GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
308
309
310/**
311 * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
312 */
313struct GNUNET_TRANSPORT_PeerMonitoringContext;
314
315
316/**
317 * Function to call with information about a peer
318 *
319 * If one_shot was set to #GNUNET_YES to iterate over all peers once,
320 * a final call with NULL for peer and address will follow when done.
321 * In this case state and timeout do not contain valid values.
322 *
323 * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
324 * within this function!
325 *
326 *
327 * @param cls closure
328 * @param peer peer this update is about,
329 * NULL if this is the final last callback for a iteration operation
330 * @param address address, NULL if this is the final callback for iteration op
331 * @param state current state this peer is in
332 * @param state_timeout timeout for the current state of the peer
333 */
334typedef void
335(*GNUNET_TRANSPORT_PeerIterateCallback) (
336 void *cls,
337 const struct GNUNET_PeerIdentity *peer,
338 const struct GNUNET_HELLO_Address *address,
339 enum GNUNET_TRANSPORT_PeerState state,
340 struct GNUNET_TIME_Absolute state_timeout);
341
342
343/**
344 * Return information about a specific peer or all peers currently known to
345 * transport service once or in monitoring mode. To obtain information about
346 * a specific peer, a peer identity can be passed. To obtain information about
347 * all peers currently known to transport service, NULL can be passed as peer
348 * identity.
349 *
350 * For each peer, the callback is called with information about the address used
351 * to communicate with this peer, the state this peer is currently in and the
352 * the current timeout for this state.
353 *
354 * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
355 * more time with `NULL`. After this, the operation must no longer be
356 * explicitly canceled.
357 *
358 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
359 * the peer_callback!
360 *
361 * @param cfg configuration to use
362 * @param peer a specific peer identity to obtain information for,
363 * NULL for all peers
364 * @param one_shot #GNUNET_YES to return the current state and
365 * then end (with NULL+NULL),
366 * #GNUNET_NO to monitor peers continuously
367 * @param peer_callback function to call with the results
368 * @param peer_callback_cls closure for @a peer_callback
369 */
370struct GNUNET_TRANSPORT_PeerMonitoringContext *
371GNUNET_TRANSPORT_monitor_peers (
372 const struct GNUNET_CONFIGURATION_Handle *cfg,
373 const struct GNUNET_PeerIdentity *peer,
374 int one_shot,
375 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
376 void *peer_callback_cls);
377
378
379/**
380 * Cancel request to monitor peers
381 *
382 * @param pic handle for the request to cancel
383 */
384void
385GNUNET_TRANSPORT_monitor_peers_cancel (
386 struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
387
388
389/* *********************** Blacklisting ************************ */
390
391/**
392 * Handle for blacklisting peers.
393 */
394struct GNUNET_TRANSPORT_Blacklist;
395
396
397/**
398 * Function that decides if a connection is acceptable or not.
399 *
400 * @param cls closure
401 * @param pid peer to approve or disapproave
402 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
403 */
404typedef int
405(*GNUNET_TRANSPORT_BlacklistCallback) (
406 void *cls,
407 const struct GNUNET_PeerIdentity *pid);
408
409
410/**
411 * Install a blacklist callback. The service will be queried for all
412 * existing connections as well as any fresh connections to check if
413 * they are permitted. If the blacklisting callback is unregistered,
414 * all hosts that were denied in the past will automatically be
415 * whitelisted again. Cancelling the blacklist handle is also the
416 * only way to re-enable connections from peers that were previously
417 * blacklisted.
418 *
419 * @param cfg configuration to use
420 * @param cb callback to invoke to check if connections are allowed
421 * @param cb_cls closure for @a cb
422 * @return NULL on error, otherwise handle for cancellation
423 */
424struct GNUNET_TRANSPORT_Blacklist *
425GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
426 GNUNET_TRANSPORT_BlacklistCallback cb,
427 void *cb_cls);
428
429
430/**
431 * Abort the blacklist. Note that this function is the only way for
432 * removing a peer from the blacklist.
433 *
434 * @param br handle of the request that is to be cancelled
435 */
436void
437GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
438
439
440/**
441 * Handle for a plugin session state monitor.
442 */
443struct GNUNET_TRANSPORT_PluginMonitor;
444
445/**
446 * Abstract representation of a plugin's session.
447 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
448 */
449struct GNUNET_TRANSPORT_PluginSession;
450
451
452/**
453 * Possible states of a session in a plugin.
454 */
455enum GNUNET_TRANSPORT_SessionState
456{
457 /**
458 * The session was created (first call for each session object).
459 */
460 GNUNET_TRANSPORT_SS_INIT,
461
462 /**
463 * Initial session handshake is in progress.
464 */
465 GNUNET_TRANSPORT_SS_HANDSHAKE,
466
467 /**
468 * Session is fully UP.
469 */
470 GNUNET_TRANSPORT_SS_UP,
471
472 /**
473 * This is just an update about the session,
474 * the state did not change.
475 */
476 GNUNET_TRANSPORT_SS_UPDATE,
477
478 /**
479 * Session is being torn down and about to disappear.
480 * Last call for each session object.
481 */
482 GNUNET_TRANSPORT_SS_DONE
483};
484
485
486/**
487 * Information about a plugin's session.
488 */
489struct GNUNET_TRANSPORT_SessionInfo
490{
491 /**
492 * New state of the session.
493 */
494 enum GNUNET_TRANSPORT_SessionState state;
495
496 /**
497 * #GNUNET_YES if this is an inbound connection,
498 * #GNUNET_NO if this is an outbound connection,
499 * #GNUNET_SYSERR if connections of this plugin
500 * are so fundamentally bidirectional
501 * that they have no 'initiator'
502 */
503 int is_inbound;
504
505 /**
506 * Number of messages pending transmission for this session.
507 */
508 uint32_t num_msg_pending;
509
510 /**
511 * Number of bytes pending transmission for this session.
512 */
513 uint32_t num_bytes_pending;
514
515 /**
516 * Until when does this plugin refuse to receive to manage
517 * staying within the inbound quota? ZERO if receive is
518 * active.
519 */
520 struct GNUNET_TIME_Absolute receive_delay;
521
522 /**
523 * At what time will this session timeout (unless activity
524 * happens)?
525 */
526 struct GNUNET_TIME_Absolute session_timeout;
527
528 /**
529 * Address used by the session. Can be NULL if none is available.
530 */
531 const struct GNUNET_HELLO_Address *address;
532};
533
534
535/**
536 * Function called by the plugin with information about the
537 * current sessions managed by the plugin (for monitoring).
538 *
539 * @param cls closure
540 * @param session session handle this information is about,
541 * NULL to indicate that we are "in sync" (initial
542 * iteration complete)
543 * @param session_ctx storage location where the application
544 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
545 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
546 * @param info information about the state of the session,
547 * NULL if @a session is also NULL and we are
548 * merely signalling that the initial iteration is over;
549 * NULL with @a session being non-NULL if the monitor
550 * was being cancelled while sessions were active
551 */
552typedef void
553(*GNUNET_TRANSPORT_SessionMonitorCallback) (
554 void *cls,
555 struct GNUNET_TRANSPORT_PluginSession *session,
556 void **session_ctx,
557 const struct GNUNET_TRANSPORT_SessionInfo *info);
558
559
560/**
561 * Install a plugin session state monitor callback. The callback
562 * will be notified whenever the session changes.
563 *
564 * @param cfg configuration to use
565 * @param cb callback to invoke on events
566 * @param cb_cls closure for @a cb
567 * @return NULL on error, otherwise handle for cancellation
568 */
569struct GNUNET_TRANSPORT_PluginMonitor *
570GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
571 GNUNET_TRANSPORT_SessionMonitorCallback cb,
572 void *cb_cls);
573
574
575/**
576 * Cancel monitoring the plugin session state. The callback will be
577 * called once for each session that is up with the "info" argument
578 * being NULL (this is just to enable client-side cleanup).
579 *
580 * @param pm handle of the request that is to be cancelled
581 */
582void
583GNUNET_TRANSPORT_monitor_plugins_cancel (
584 struct GNUNET_TRANSPORT_PluginMonitor *pm);
585
586
587/**
588 * Opaque handle to the service.
589 */
590struct GNUNET_TRANSPORT_CoreHandle;
591
592
593/**
594 * Function called to notify transport users that another
595 * peer connected to us.
596 *
597 * @param cls closure
598 * @param peer the identity of the peer that connected; this
599 * pointer will remain valid until the disconnect, hence
600 * applications do not necessarily have to make a copy
601 * of the value if they only need it until disconnect
602 * @param mq message queue to use to transmit to @a peer
603 * @return closure to use in MQ handlers
604 */
605typedef void *
606(*GNUNET_TRANSPORT_NotifyConnect) (
607 void *cls,
608 const struct GNUNET_PeerIdentity *peer,
609 struct GNUNET_MQ_Handle *mq);
610
611
612/**
613 * Function called to notify transport users that another peer
614 * disconnected from us. The message queue that was given to the
615 * connect notification will be destroyed and must not be used
616 * henceforth.
617 *
618 * @param cls closure from #GNUNET_TRANSPORT_core_connect
619 * @param peer the peer that disconnected
620 * @param handlers_cls closure of the handlers, was returned from the
621 * connect notification callback
622 */
623typedef void
624(*GNUNET_TRANSPORT_NotifyDisconnect) (
625 void *cls,
626 const struct GNUNET_PeerIdentity *peer,
627 void *handler_cls);
628
629
630/**
631 * Function called if we have "excess" bandwidth to a peer.
632 * The notification will happen the first time we have excess
633 * bandwidth, and then only again after the client has performed
634 * some transmission to the peer.
635 *
636 * Excess bandwidth is defined as being allowed (by ATS) to send
637 * more data, and us reaching the limit of the capacity build-up
638 * (which, if we go past it, means we don't use available bandwidth).
639 * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
640 *
641 * @param cls the closure
642 * @param neighbour peer that we have excess bandwidth to
643 * @param handlers_cls closure of the handlers, was returned from the
644 * connect notification callback
645 */
646typedef void
647(*GNUNET_TRANSPORT_NotifyExcessBandwidth) (
648 void *cls,
649 const struct GNUNET_PeerIdentity *neighbour,
650 void *handlers_cls);
651
652
653/**
654 * Connect to the transport service. Note that the connection may
655 * complete (or fail) asynchronously.
656 *
657 * @param cfg configuration to use
658 * @param self our own identity (API should check that it matches
659 * the identity found by transport), or NULL (no check)
660 * @param handlers array of message handlers; note that the
661 * closures provided will be ignored and replaced
662 * with the respective return value from @a nc
663 * @param handlers array with handlers to call when we receive messages, or NULL
664 * @param cls closure for the @a nc, @a nd and @a neb callbacks
665 * @param nc function to call on connect events, or NULL
666 * @param nd function to call on disconnect events, or NULL
667 * @param neb function to call if we have excess bandwidth to a peer, or NULL
668 * @return NULL on error
669 */
670struct GNUNET_TRANSPORT_CoreHandle *
671GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
672 const struct GNUNET_PeerIdentity *self,
673 const struct GNUNET_MQ_MessageHandler *handlers,
674 void *cls,
675 GNUNET_TRANSPORT_NotifyConnect nc,
676 GNUNET_TRANSPORT_NotifyDisconnect nd,
677 GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
678
679
680/**
681 * Disconnect from the transport service.
682 *
683 * @param handle handle returned from connect
684 */
685void
686GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
687
688
689/**
690 * Checks if a given peer is connected to us and get the message queue.
691 *
692 * @param handle connection to transport service
693 * @param peer the peer to check
694 * @return NULL if disconnected, otherwise message queue for @a peer
695 */
696struct GNUNET_MQ_Handle *
697GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
698 const struct GNUNET_PeerIdentity *peer);
699
700
701#if 0 /* keep Emacsens' auto-indent happy */
702{
703#endif
704#ifdef __cplusplus
705}
706#endif
707
708/* ifndef GNUNET_TRANSPORT_SERVICE_H */
709#endif
710
711/** @} */ /* end of group */
712
713/** @} */ /* end of group addition */
714
715/* end of gnunet_transport_service.h */
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 17acfe5f8..6c7d2cd42 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -550,6 +550,29 @@ struct GNUNET_TUN_DnsSrvRecord
550 550
551 551
552/** 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/**
553 * Payload of DNS CERT record. 576 * Payload of DNS CERT record.
554 */ 577 */
555struct GNUNET_TUN_DnsCertRecord 578struct GNUNET_TUN_DnsCertRecord
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index ada40a4ca..ee850bc3c 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -77,6 +77,7 @@ extern "C"
77#include "gnunet_helper_lib.h" 77#include "gnunet_helper_lib.h"
78#include "gnunet_mst_lib.h" 78#include "gnunet_mst_lib.h"
79#include "gnunet_mq_lib.h" 79#include "gnunet_mq_lib.h"
80#include "gnunet_nt_lib.h"
80#include "gnunet_nc_lib.h" 81#include "gnunet_nc_lib.h"
81#include "gnunet_op_lib.h" 82#include "gnunet_op_lib.h"
82#include "gnunet_os_lib.h" 83#include "gnunet_os_lib.h"
@@ -93,6 +94,15 @@ extern "C"
93#include "gnunet_child_management_lib.h" 94#include "gnunet_child_management_lib.h"
94#include "gnunet_error_codes.h" 95#include "gnunet_error_codes.h"
95 96
97
98/**
99 * Stringify operator.
100 *
101 * @param a some expression to stringify. Must NOT be a macro.
102 * @return same expression as a constant string.
103 */
104#define GNUNET_S(a) #a
105
96/** 106/**
97 * Try to compress the given block of data using libz. Only returns 107 * Try to compress the given block of data using libz. Only returns
98 * the compressed block if compression worked and the new block is 108 * the compressed block if compression worked and the new block is
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 deca323d1..c04d8d487 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -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 */