aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/.gitignore3
-rw-r--r--src/include/Makefile.am32
-rw-r--r--src/include/block_dns.h6
-rw-r--r--src/include/block_fs.h6
-rw-r--r--src/include/block_regex.h1
-rw-r--r--src/include/gauger.h1
-rw-r--r--src/include/gettext.h1
-rw-r--r--src/include/gnu_name_system_protocols.h96
-rw-r--r--src/include/gnu_name_system_record_types.h68
-rw-r--r--src/include/gnu_name_system_service_ports.h104
-rw-r--r--src/include/gnunet_abd_service.h38
-rw-r--r--src/include/gnunet_abe_lib.h193
-rw-r--r--src/include/gnunet_applications.h5
-rw-r--r--src/include/gnunet_arm_service.h1
-rw-r--r--src/include/gnunet_ats_application_service.h103
-rw-r--r--src/include/gnunet_ats_plugin.h486
-rw-r--r--src/include/gnunet_ats_service.h624
-rw-r--r--src/include/gnunet_ats_transport_service.h240
-rw-r--r--src/include/gnunet_bandwidth_lib.h12
-rw-r--r--src/include/gnunet_bio_lib.h106
-rw-r--r--src/include/gnunet_block_group_lib.h7
-rw-r--r--src/include/gnunet_block_lib.h261
-rw-r--r--src/include/gnunet_block_plugin.h135
-rw-r--r--src/include/gnunet_buffer_lib.h10
-rw-r--r--src/include/gnunet_cadet_service.h9
-rw-r--r--src/include/gnunet_child_management_lib.h13
-rw-r--r--src/include/gnunet_client_lib.h19
-rw-r--r--src/include/gnunet_common.h91
-rw-r--r--src/include/gnunet_config.h.in58
-rw-r--r--src/include/gnunet_configuration_lib.h145
-rw-r--r--src/include/gnunet_consensus_service.h10
-rw-r--r--src/include/gnunet_container_lib.h525
-rw-r--r--src/include/gnunet_conversation_service.h8
-rw-r--r--src/include/gnunet_core_service.h7
-rw-r--r--src/include/gnunet_core_testing_lib.h158
-rw-r--r--src/include/gnunet_crypto_lib.h2230
-rw-r--r--src/include/gnunet_curl_lib.h23
-rw-r--r--src/include/gnunet_datacache_lib.h118
-rw-r--r--src/include/gnunet_datacache_plugin.h81
-rw-r--r--src/include/gnunet_datastore_plugin.h28
-rw-r--r--src/include/gnunet_datastore_service.h6
-rw-r--r--src/include/gnunet_db_lib.h1
-rw-r--r--src/include/gnunet_dht_block_types.h156
-rw-r--r--src/include/gnunet_dht_service.h235
-rw-r--r--src/include/gnunet_dhtu_plugin.h90
-rw-r--r--src/include/gnunet_disk_lib.h14
-rw-r--r--src/include/gnunet_dns_service.h6
-rw-r--r--src/include/gnunet_dnsparser_lib.h98
-rw-r--r--src/include/gnunet_dnsstub_lib.h12
-rw-r--r--src/include/gnunet_error_codes.h242
-rw-r--r--src/include/gnunet_fragmentation_lib.h230
-rw-r--r--src/include/gnunet_friends_lib.h118
-rw-r--r--src/include/gnunet_fs_service.h517
-rw-r--r--src/include/gnunet_getopt_lib.h30
-rw-r--r--src/include/gnunet_gns_service.h17
-rw-r--r--src/include/gnunet_gnsrecord_json_lib.h14
-rw-r--r--src/include/gnunet_gnsrecord_lib.h441
-rw-r--r--src/include/gnunet_gnsrecord_plugin.h22
-rw-r--r--src/include/gnunet_hello_lib.h539
-rw-r--r--src/include/gnunet_hello_uri_lib.h304
-rw-r--r--src/include/gnunet_helper_lib.h25
-rw-r--r--src/include/gnunet_identity_service.h458
-rw-r--r--src/include/gnunet_json_lib.h216
-rw-r--r--src/include/gnunet_load_lib.h6
-rw-r--r--src/include/gnunet_messenger_service.h349
-rw-r--r--src/include/gnunet_mhd_compat.h3
-rw-r--r--src/include/gnunet_microphone_lib.h6
-rw-r--r--src/include/gnunet_mq_lib.h36
-rw-r--r--src/include/gnunet_mst_lib.h23
-rw-r--r--src/include/gnunet_my_lib.h500
-rw-r--r--src/include/gnunet_mysql_lib.h157
-rw-r--r--src/include/gnunet_namecache_plugin.h6
-rw-r--r--src/include/gnunet_namecache_service.h6
-rw-r--r--src/include/gnunet_namestore_plugin.h125
-rw-r--r--src/include/gnunet_namestore_service.h344
-rw-r--r--src/include/gnunet_nat_auto_service.h3
-rw-r--r--src/include/gnunet_nat_service.h20
-rw-r--r--src/include/gnunet_nc_lib.h14
-rw-r--r--src/include/gnunet_network_lib.h25
-rw-r--r--src/include/gnunet_nse_service.h6
-rw-r--r--src/include/gnunet_nt_lib.h12
-rw-r--r--src/include/gnunet_op_lib.h11
-rw-r--r--src/include/gnunet_os_lib.h36
-rw-r--r--src/include/gnunet_peer_lib.h11
-rw-r--r--src/include/gnunet_peerinfo_service.h210
-rw-r--r--src/include/gnunet_peerstore_plugin.h24
-rw-r--r--src/include/gnunet_peerstore_service.h200
-rw-r--r--src/include/gnunet_plugin_lib.h15
-rw-r--r--src/include/gnunet_pq_lib.h766
-rw-r--r--src/include/gnunet_program_lib.h50
-rw-r--r--src/include/gnunet_protocols.h126
-rw-r--r--src/include/gnunet_reclaim_lib.h22
-rw-r--r--src/include/gnunet_reclaim_plugin.h6
-rw-r--r--src/include/gnunet_reclaim_service.h102
-rw-r--r--src/include/gnunet_regex_service.h6
-rw-r--r--src/include/gnunet_resolver_service.h6
-rw-r--r--src/include/gnunet_rest_lib.h6
-rw-r--r--src/include/gnunet_rest_plugin.h27
-rw-r--r--src/include/gnunet_revocation_service.h140
-rw-r--r--src/include/gnunet_rps_service.h5
-rw-r--r--src/include/gnunet_scalarproduct_service.h3
-rw-r--r--src/include/gnunet_scheduler_lib.h7
-rw-r--r--src/include/gnunet_secretsharing_service.h1
-rw-r--r--src/include/gnunet_service_lib.h132
-rw-r--r--src/include/gnunet_set_service.h16
-rw-r--r--src/include/gnunet_seti_service.h6
-rw-r--r--src/include/gnunet_setu_service.h12
-rw-r--r--src/include/gnunet_signal_lib.h10
-rw-r--r--src/include/gnunet_signatures.h194
-rw-r--r--src/include/gnunet_socks.h6
-rw-r--r--src/include/gnunet_speaker_lib.h6
-rw-r--r--src/include/gnunet_sq_lib.h21
-rw-r--r--src/include/gnunet_statistics_service.h6
-rw-r--r--src/include/gnunet_strings_lib.h99
-rw-r--r--src/include/gnunet_testbed_logger_service.h133
-rw-r--r--src/include/gnunet_testbed_service.h1729
-rw-r--r--src/include/gnunet_testing_barrier.h122
-rw-r--r--src/include/gnunet_testing_lib.h29
-rw-r--r--src/include/gnunet_testing_loop_lib.h697
-rw-r--r--src/include/gnunet_testing_netjail_lib.h224
-rw-r--r--src/include/gnunet_testing_ng_lib.h881
-rw-r--r--src/include/gnunet_testing_plugin.h92
-rw-r--r--src/include/gnunet_time_lib.h278
-rw-r--r--src/include/gnunet_transport_application_service.h11
-rw-r--r--src/include/gnunet_transport_communication_service.h16
-rw-r--r--src/include/gnunet_transport_core_service.h8
-rw-r--r--src/include/gnunet_transport_hello_service.h201
-rw-r--r--src/include/gnunet_transport_manipulation_service.h117
-rw-r--r--src/include/gnunet_transport_monitor_service.h9
-rw-r--r--src/include/gnunet_transport_plugin.h727
-rw-r--r--src/include/gnunet_transport_service.h708
-rw-r--r--src/include/gnunet_transport_testing_ng_lib.h211
-rw-r--r--src/include/gnunet_tun_lib.h35
-rw-r--r--src/include/gnunet_util_lib.h59
-rw-r--r--src/include/gnunet_vpn_service.h6
-rw-r--r--src/include/meson.build122
-rw-r--r--src/include/platform.h7
137 files changed, 9796 insertions, 10408 deletions
diff --git a/src/include/.gitignore b/src/include/.gitignore
new file mode 100644
index 000000000..76ca45ab4
--- /dev/null
+++ b/src/include/.gitignore
@@ -0,0 +1,3 @@
1!gnunet_config.h.in
2gnunet_config.h
3gnunet_mysql_compat.h
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index e4b02b8ee..8f39faab6 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -4,23 +4,22 @@ SUBDIRS = .
4gnunetincludedir = $(includedir)/gnunet 4gnunetincludedir = $(includedir)/gnunet
5 5
6EXTRA_DIST = \ 6EXTRA_DIST = \
7 platform.h \
7 gauger.h \ 8 gauger.h \
8 block_fs.h \ 9 block_fs.h \
9 block_dns.h \ 10 block_dns.h \
10 block_regex.h 11 block_regex.h
11 12
12gnunetinclude_HEADERS = \ 13gnunetinclude_HEADERS = \
13 platform.h gettext.h \ 14 gnunet_config.h \
15 gettext.h \
14 compat.h \ 16 compat.h \
15 gnunet_abd_service.h \ 17 gnunet_abd_service.h \
16 gnunet_applications.h \ 18 gnunet_applications.h \
17 gnunet_arm_service.h \ 19 gnunet_arm_service.h \
18 gnunet_ats_service.h \
19 gnunet_ats_application_service.h \
20 gnunet_ats_transport_service.h \
21 gnunet_ats_plugin.h \
22 gnunet_bandwidth_lib.h \ 20 gnunet_bandwidth_lib.h \
23 gnunet_bio_lib.h \ 21 gnunet_bio_lib.h \
22 gnunet_dht_block_types.h \
24 gnunet_block_lib.h \ 23 gnunet_block_lib.h \
25 gnunet_block_group_lib.h \ 24 gnunet_block_group_lib.h \
26 gnunet_block_plugin.h \ 25 gnunet_block_plugin.h \
@@ -34,6 +33,7 @@ gnunetinclude_HEADERS = \
34 gnunet_container_lib.h \ 33 gnunet_container_lib.h \
35 gnunet_conversation_service.h \ 34 gnunet_conversation_service.h \
36 gnunet_core_service.h \ 35 gnunet_core_service.h \
36 gnunet_core_testing_lib.h \
37 gnunet_crypto_lib.h \ 37 gnunet_crypto_lib.h \
38 gnunet_curl_lib.h \ 38 gnunet_curl_lib.h \
39 gnunet_datacache_lib.h \ 39 gnunet_datacache_lib.h \
@@ -47,8 +47,7 @@ gnunetinclude_HEADERS = \
47 gnunet_dnsparser_lib.h \ 47 gnunet_dnsparser_lib.h \
48 gnunet_dnsstub_lib.h \ 48 gnunet_dnsstub_lib.h \
49 gnunet_dns_service.h \ 49 gnunet_dns_service.h \
50 gnunet_fragmentation_lib.h \ 50 gnunet_error_codes.h \
51 gnunet_friends_lib.h \
52 gnunet_fs_service.h \ 51 gnunet_fs_service.h \
53 gnunet_getopt_lib.h \ 52 gnunet_getopt_lib.h \
54 gnunet_gns_service.h \ 53 gnunet_gns_service.h \
@@ -56,10 +55,11 @@ gnunetinclude_HEADERS = \
56 gnunet_gnsrecord_json_lib.h \ 55 gnunet_gnsrecord_json_lib.h \
57 gnunet_gnsrecord_plugin.h \ 56 gnunet_gnsrecord_plugin.h \
58 gnu_name_system_record_types.h \ 57 gnu_name_system_record_types.h \
59 gnunet_hello_lib.h \ 58 gnu_name_system_protocols.h \
59 gnu_name_system_service_ports.h \
60 gnunet_hello_uri_lib.h \
60 gnunet_helper_lib.h \ 61 gnunet_helper_lib.h \
61 gnunet_identity_service.h \ 62 gnunet_identity_service.h \
62 gnunet_abe_lib.h \
63 gnunet_reclaim_lib.h \ 63 gnunet_reclaim_lib.h \
64 gnunet_reclaim_plugin.h \ 64 gnunet_reclaim_plugin.h \
65 gnunet_reclaim_service.h \ 65 gnunet_reclaim_service.h \
@@ -71,8 +71,6 @@ gnunetinclude_HEADERS = \
71 gnunet_microphone_lib.h \ 71 gnunet_microphone_lib.h \
72 gnunet_mst_lib.h \ 72 gnunet_mst_lib.h \
73 gnunet_mq_lib.h \ 73 gnunet_mq_lib.h \
74 gnunet_my_lib.h \
75 gnunet_mysql_lib.h \
76 gnunet_namecache_plugin.h \ 74 gnunet_namecache_plugin.h \
77 gnunet_namecache_service.h \ 75 gnunet_namecache_service.h \
78 gnunet_namestore_plugin.h \ 76 gnunet_namestore_plugin.h \
@@ -86,7 +84,6 @@ gnunetinclude_HEADERS = \
86 gnunet_op_lib.h \ 84 gnunet_op_lib.h \
87 gnunet_os_lib.h \ 85 gnunet_os_lib.h \
88 gnunet_peer_lib.h \ 86 gnunet_peer_lib.h \
89 gnunet_peerinfo_service.h \
90 gnunet_peerstore_plugin.h \ 87 gnunet_peerstore_plugin.h \
91 gnunet_peerstore_service.h \ 88 gnunet_peerstore_service.h \
92 gnunet_plugin_lib.h \ 89 gnunet_plugin_lib.h \
@@ -113,21 +110,18 @@ gnunetinclude_HEADERS = \
113 gnunet_sq_lib.h \ 110 gnunet_sq_lib.h \
114 gnunet_statistics_service.h \ 111 gnunet_statistics_service.h \
115 gnunet_strings_lib.h \ 112 gnunet_strings_lib.h \
116 gnunet_testbed_service.h \ 113 gnunet_testing_barrier.h \
117 gnunet_testbed_logger_service.h \
118 gnunet_testing_lib.h \ 114 gnunet_testing_lib.h \
119 gnunet_testing_plugin.h \ 115 gnunet_testing_plugin.h \
120 gnunet_testing_ng_lib.h \ 116 gnunet_testing_ng_lib.h \
117 gnunet_testing_loop_lib.h \
121 gnunet_testing_netjail_lib.h \ 118 gnunet_testing_netjail_lib.h \
122 gnunet_time_lib.h \ 119 gnunet_time_lib.h \
123 gnunet_transport_service.h \
124 gnunet_transport_application_service.h \ 120 gnunet_transport_application_service.h \
125 gnunet_transport_communication_service.h \ 121 gnunet_transport_communication_service.h \
126 gnunet_transport_core_service.h \
127 gnunet_transport_hello_service.h \
128 gnunet_transport_manipulation_service.h \
129 gnunet_transport_monitor_service.h \ 122 gnunet_transport_monitor_service.h \
130 gnunet_transport_plugin.h \ 123 gnunet_transport_core_service.h \
124 gnunet_transport_testing_ng_lib.h \
131 gnunet_tun_lib.h \ 125 gnunet_tun_lib.h \
132 gnunet_uri_lib.h \ 126 gnunet_uri_lib.h \
133 gnunet_util_lib.h \ 127 gnunet_util_lib.h \
diff --git a/src/include/block_dns.h b/src/include/block_dns.h
index 2186cb1a1..4ac6d0250 100644
--- a/src/include/block_dns.h
+++ b/src/include/block_dns.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -30,6 +33,7 @@
30#ifndef BLOCK_DNS_H 33#ifndef BLOCK_DNS_H
31#define BLOCK_DNS_H 34#define BLOCK_DNS_H
32 35
36
33#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
34 38
35GNUNET_NETWORK_STRUCT_BEGIN 39GNUNET_NETWORK_STRUCT_BEGIN
@@ -65,3 +69,5 @@ GNUNET_NETWORK_STRUCT_END
65#endif 69#endif
66 70
67/** @} */ /* end of group */ 71/** @} */ /* end of group */
72
73/** @} */ /* end of group addition to vpn_suite */
diff --git a/src/include/block_fs.h b/src/include/block_fs.h
index e4caf6e50..b64a83f39 100644
--- a/src/include/block_fs.h
+++ b/src/include/block_fs.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef BLOCK_FS_H 34#ifndef BLOCK_FS_H
32#define BLOCK_FS_H 35#define BLOCK_FS_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_fs_service.h" 39#include "gnunet_fs_service.h"
36 40
@@ -98,3 +102,5 @@ GNUNET_NETWORK_STRUCT_END
98#endif 102#endif
99 103
100/** @} */ /* end of group */ 104/** @} */ /* end of group */
105
106/** @} */ /* end of group addition to fs_l2 */
diff --git a/src/include/block_regex.h b/src/include/block_regex.h
index cc78f2c32..fea19e335 100644
--- a/src/include/block_regex.h
+++ b/src/include/block_regex.h
@@ -36,6 +36,7 @@ extern "C"
36#endif 36#endif
37#endif 37#endif
38 38
39
39#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
40#include <stdint.h> 41#include <stdint.h>
41 42
diff --git a/src/include/gauger.h b/src/include/gauger.h
index 716ce9cb1..f811b335c 100644
--- a/src/include/gauger.h
+++ b/src/include/gauger.h
@@ -11,6 +11,7 @@
11#ifndef __GAUGER_H__ 11#ifndef __GAUGER_H__
12#define __GAUGER_H__ 12#define __GAUGER_H__
13 13
14
14#include <unistd.h> 15#include <unistd.h>
15#include <stdio.h> 16#include <stdio.h>
16#include <sys/wait.h> 17#include <sys/wait.h>
diff --git a/src/include/gettext.h b/src/include/gettext.h
index 458512657..6e98f197a 100644
--- a/src/include/gettext.h
+++ b/src/include/gettext.h
@@ -23,6 +23,7 @@
23#if ENABLE_NLS 23#if ENABLE_NLS
24 24
25/* Get declarations of GNU message catalog functions. */ 25/* Get declarations of GNU message catalog functions. */
26
26#include <libintl.h> 27#include <libintl.h>
27 28
28#else 29#else
diff --git a/src/include/gnu_name_system_protocols.h b/src/include/gnu_name_system_protocols.h
new file mode 100644
index 000000000..c10eef468
--- /dev/null
+++ b/src/include/gnu_name_system_protocols.h
@@ -0,0 +1,96 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2023 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_GNS_PROTOCOLS_H
21#define GNUNET_GNS_PROTOCOLS_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add GNS service ports, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39struct GNUNET_GNS_Protocol
40{
41 const char *name;
42
43 uint16_t number;
44};
45
46struct GNUNET_GNS_Protocol GNUNET_GNS_Protocols[] = {
47 /**
48 * LIGHTest trust policy scheme
49 */
50 {
51 .name = "trust",
52 .number = 49152
53 },
54
55 {
56 .name = NULL,
57 .number = 0
58 }
59};
60
61uint16_t
62GNUNET_GNS_protocol_name_to_number (const char *name)
63{
64 int i = 0;
65 while (NULL != GNUNET_GNS_Protocols[i].name)
66 {
67 if (0 == strcmp (name, GNUNET_GNS_Protocols[i].name))
68 return GNUNET_GNS_Protocols[i].number;
69 i++;
70 }
71 return 0;
72}
73
74
75const char*
76GNUNET_GNS_protocol_number_to_name (uint16_t number)
77{
78 int i = 0;
79 while (NULL != GNUNET_GNS_Protocols[i].name)
80 {
81 if (number == GNUNET_GNS_Protocols[i].number)
82 return GNUNET_GNS_Protocols[i].name;
83 i++;
84 }
85 return NULL;
86}
87
88
89#if 0 /* keep Emacsens' auto-indent happy */
90{
91#endif
92#ifdef __cplusplus
93}
94#endif
95
96#endif
diff --git a/src/include/gnu_name_system_record_types.h b/src/include/gnu_name_system_record_types.h
index 22b2c472e..8a62cac11 100644
--- a/src/include/gnu_name_system_record_types.h
+++ b/src/include/gnu_name_system_record_types.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012-2021 GNUnet e.V. 3 Copyright (C) 2012-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -38,106 +38,162 @@ extern "C" {
38 38
39 39
40/** 40/**
41 * GNS zone transfer 41 * GNS zone delegation (PKEY)
42 */ 42 */
43#define GNUNET_GNSRECORD_TYPE_PKEY 65536 43#define GNUNET_GNSRECORD_TYPE_PKEY 65536
44 44
45
45/** 46/**
46 * GNS nick names 47 * GNS zone nickname
47 */ 48 */
48#define GNUNET_GNSRECORD_TYPE_NICK 65537 49#define GNUNET_GNSRECORD_TYPE_NICK 65537
49 50
51
50/** 52/**
51 * legacy hostnames 53 * GNS legacy hostname
52 */ 54 */
53#define GNUNET_GNSRECORD_TYPE_LEHO 65538 55#define GNUNET_GNSRECORD_TYPE_LEHO 65538
54 56
57
55/** 58/**
56 * VPN resolution 59 * VPN resolution
57 */ 60 */
58#define GNUNET_GNSRECORD_TYPE_VPN 65539 61#define GNUNET_GNSRECORD_TYPE_VPN 65539
59 62
63
60/** 64/**
61 * Delegation to DNS 65 * Delegation to DNS
62 */ 66 */
63#define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540 67#define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540
64 68
69
65/** 70/**
66 * Boxed records (see TLSA/SRV handling in GNS) 71 * Box record
67 */ 72 */
68#define GNUNET_GNSRECORD_TYPE_BOX 65541 73#define GNUNET_GNSRECORD_TYPE_BOX 65541
69 74
75
70/** 76/**
71 * social place for SecuShare 77 * social place for SecuShare
72 */ 78 */
73#define GNUNET_GNSRECORD_TYPE_PLACE 65542 79#define GNUNET_GNSRECORD_TYPE_PLACE 65542
74 80
81
75/** 82/**
76 * Endpoint for conversation 83 * Endpoint for conversation
77 */ 84 */
78#define GNUNET_GNSRECORD_TYPE_PHONE 65543 85#define GNUNET_GNSRECORD_TYPE_PHONE 65543
79 86
87
80/** 88/**
81 * identity attribute 89 * identity attribute
82 */ 90 */
83#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544 91#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544
84 92
93
85/** 94/**
86 * local ticket reference 95 * local ticket reference
87 */ 96 */
88#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545 97#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545
89 98
99
100/**
101 * SBox record
102 */
103#define GNUNET_GNSRECORD_TYPE_SBOX 65547
104
105
90/** 106/**
91 * For ABD policies 107 * For ABD policies
92 */ 108 */
93#define GNUNET_GNSRECORD_TYPE_DELEGATE 65548 109#define GNUNET_GNSRECORD_TYPE_DELEGATE 65548
94 110
111
95/** 112/**
96 * For ABD reverse lookups 113 * For ABD reverse lookups
97 */ 114 */
98#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549 115#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549
99 116
117
100/** 118/**
101 * for reclaim records 119 * for reclaim records
102 */ 120 */
103#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550 121#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550
104 122
123
124/**
125 * Redirection record
126 */
127#define GNUNET_GNSRECORD_TYPE_REDIRECT 65551
128
129
105/** 130/**
106 * For reclaim OIDC client names. 131 * For reclaim OIDC client names.
107 */ 132 */
108#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552 133#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552
109 134
135
110/** 136/**
111 * Used reclaimID OIDC client redirect URIs. 137 * Used reclaimID OIDC client redirect URIs.
112 */ 138 */
113#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553 139#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553
114 140
141
115/** 142/**
116 * Record type for an attribute attestation (e.g. JWT). 143 * Record type for an attribute attestation (e.g. JWT).
117 */ 144 */
118#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554 145#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554
119 146
147
120/** 148/**
121 * Record type for a presentation of a credential. 149 * Record type for a presentation of a credential.
122 */ 150 */
123#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555 151#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555
124 152
153
125/** 154/**
126 * Record type for EDKEY zone delegations. 155 * GNS zone delegation (EDKEY)
127 */ 156 */
128#define GNUNET_GNSRECORD_TYPE_EDKEY 65556 157#define GNUNET_GNSRECORD_TYPE_EDKEY 65556
129 158
159
130/** 160/**
131 * Encoding for Robust Immutable Storage (ERIS) binary read capability 161 * Encoding for Robust Immutable Storage (ERIS) binary read capability
132 */ 162 */
133#define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557 163#define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557
134 164
165
135/** 166/**
136 * Record type to share an entry of a messenger room 167 * Record type to share an entry of a messenger room
137 */ 168 */
138#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558 169#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558
139 170
140 171
172/**
173 * Record type to indicate a previously delete record (PRIVATE only)
174 */
175#define GNUNET_GNSRECORD_TYPE_TOMBSTONE 65559
176
177
178/**
179 * Record type to store details about a messenger room
180 */
181#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS 65560
182
183
184/**
185 * Record type to store DID Documents
186 */
187#define GNUNET_GNSRECORD_TYPE_DID_DOCUMENT 65561
188
189
190/**
191 * Private metadata for a delegation registration
192 */
193#define GNUNET_GNSRECORD_TYPE_GNS_REGISTRAR_METADATA 4294901760
194
195
196
141#if 0 /* keep Emacsens' auto-indent happy */ 197#if 0 /* keep Emacsens' auto-indent happy */
142{ 198{
143#endif 199#endif
diff --git a/src/include/gnu_name_system_service_ports.h b/src/include/gnu_name_system_service_ports.h
new file mode 100644
index 000000000..040e598b6
--- /dev/null
+++ b/src/include/gnu_name_system_service_ports.h
@@ -0,0 +1,104 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2023 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_GNS_SERVICE_PORTS_H
21#define GNUNET_GNS_SERVICE_PORTS_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add GNS service ports, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39struct GNUNET_GNS_ServicePort
40{
41 const char *name;
42
43 uint16_t port;
44};
45
46struct GNUNET_GNS_ServicePort GNUNET_GNS_ServicePorts[] = {
47 /**
48 * Used by Trust Scheme Authorities to publish information about Trust Schemes (LIGHTest)
49 */
50 {
51 .name = "scheme",
52 .port = 49152
53 },
54
55 /**
56 * Used Trust Translation Authorities to publish information about Trust Translations (LIGHTest)
57 */
58 {
59 .name = "translation",
60 .port = 49153
61 },
62
63 {
64 .name = NULL,
65 .port = 0
66 }
67};
68
69uint16_t
70GNUNET_GNS_service_port_name_to_number (const char *name)
71{
72 int i = 0;
73 while (NULL != GNUNET_GNS_ServicePorts[i].name)
74 {
75 if (0 == strcmp (name, GNUNET_GNS_ServicePorts[i].name))
76 return GNUNET_GNS_ServicePorts[i].port;
77 i++;
78 }
79 return 0;
80}
81
82
83const char*
84GNUNET_GNS_service_port_number_to_name (uint16_t port)
85{
86 int i = 0;
87 while (NULL != GNUNET_GNS_ServicePorts[i].name)
88 {
89 if (port == GNUNET_GNS_ServicePorts[i].port)
90 return GNUNET_GNS_ServicePorts[i].name;
91 i++;
92 }
93 return NULL;
94}
95
96
97#if 0 /* keep Emacsens' auto-indent happy */
98{
99#endif
100#ifdef __cplusplus
101}
102#endif
103
104#endif
diff --git a/src/include/gnunet_abd_service.h b/src/include/gnunet_abd_service.h
index afec880f1..cb6e77256 100644
--- a/src/include/gnunet_abd_service.h
+++ b/src/include/gnunet_abd_service.h
@@ -19,19 +19,23 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * API to the Credential service 28 * API to the Credential service
26 * 29 *
27 * @defgroup abd Credential service 30 * @defgroup abd Credential service
28 * Credentials 31 * Credential service for Attribute-Based Decryption
29 * 32 *
30 * @{ 33 * @{
31 */ 34 */
32#ifndef GNUNET_ABD_SERVICE_H 35#ifndef GNUNET_ABD_SERVICE_H
33#define GNUNET_ABD_SERVICE_H 36#define GNUNET_ABD_SERVICE_H
34 37
38
35#include "gnunet_util_lib.h" 39#include "gnunet_util_lib.h"
36#include "gnunet_gns_service.h" 40#include "gnunet_gns_service.h"
37#include "gnunet_identity_service.h" 41#include "gnunet_identity_service.h"
@@ -103,7 +107,7 @@ struct GNUNET_ABD_DelegationRecordSet
103 /** 107 /**
104 * Public key of the subject this attribute was delegated to 108 * Public key of the subject this attribute was delegated to
105 */ 109 */
106 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 110 struct GNUNET_CRYPTO_PublicKey subject_key;
107 111
108 /** 112 /**
109 * Length of attribute, may be 0 113 * Length of attribute, may be 0
@@ -123,7 +127,7 @@ struct GNUNET_ABD_DelegationSet
123 /** 127 /**
124 * Public key of the subject this attribute was delegated to 128 * Public key of the subject this attribute was delegated to
125 */ 129 */
126 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 130 struct GNUNET_CRYPTO_PublicKey subject_key;
127 131
128 uint32_t subject_attribute_len; 132 uint32_t subject_attribute_len;
129 133
@@ -143,12 +147,12 @@ struct GNUNET_ABD_Delegation
143 /** 147 /**
144 * The issuer of the delegation 148 * The issuer of the delegation
145 */ 149 */
146 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 150 struct GNUNET_CRYPTO_PublicKey issuer_key;
147 151
148 /** 152 /**
149 * Public key of the subject this attribute was delegated to 153 * Public key of the subject this attribute was delegated to
150 */ 154 */
151 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 155 struct GNUNET_CRYPTO_PublicKey subject_key;
152 156
153 /** 157 /**
154 * Length of the attribute 158 * Length of the attribute
@@ -181,17 +185,17 @@ struct GNUNET_ABD_Delegate
181 /** 185 /**
182 * The issuer of the credential 186 * The issuer of the credential
183 */ 187 */
184 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 188 struct GNUNET_CRYPTO_PublicKey issuer_key;
185 189
186 /** 190 /**
187 * Public key of the subject this credential was issued to 191 * Public key of the subject this credential was issued to
188 */ 192 */
189 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 193 struct GNUNET_CRYPTO_PublicKey subject_key;
190 194
191 /** 195 /**
192 * Signature of this credential 196 * Signature of this credential
193 */ 197 */
194 struct GNUNET_CRYPTO_EcdsaSignature signature; 198 struct GNUNET_CRYPTO_Signature signature;
195 199
196 /** 200 /**
197 * Expiration of this credential 201 * Expiration of this credential
@@ -318,9 +322,9 @@ typedef void (*GNUNET_ABD_RemoveDelegateResultProcessor) (void *cls,
318 */ 322 */
319struct GNUNET_ABD_Request* 323struct GNUNET_ABD_Request*
320 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle, 324 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle,
321 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 325 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
322 const char *issuer_attribute, 326 const char *issuer_attribute,
323 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, 327 const struct GNUNET_CRYPTO_PublicKey *subject_key,
324 uint32_t delegate_count, 328 uint32_t delegate_count,
325 const struct GNUNET_ABD_Delegate *delegates, 329 const struct GNUNET_ABD_Delegate *delegates,
326 enum GNUNET_ABD_AlgoDirectionFlags direction, 330 enum GNUNET_ABD_AlgoDirectionFlags direction,
@@ -331,9 +335,9 @@ struct GNUNET_ABD_Request*
331 335
332struct GNUNET_ABD_Request* 336struct GNUNET_ABD_Request*
333 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle, 337 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle,
334 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 338 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
335 const char *issuer_attribute, 339 const char *issuer_attribute,
336 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, 340 const struct GNUNET_CRYPTO_PrivateKey *subject_key,
337 enum GNUNET_ABD_AlgoDirectionFlags direction, 341 enum GNUNET_ABD_AlgoDirectionFlags direction,
338 GNUNET_ABD_CredentialResultProcessor proc, 342 GNUNET_ABD_CredentialResultProcessor proc,
339 void *proc_cls, 343 void *proc_cls,
@@ -356,7 +360,7 @@ struct GNUNET_ABD_Request *
356GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle, 360GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle,
357 struct GNUNET_IDENTITY_Ego *issuer, 361 struct GNUNET_IDENTITY_Ego *issuer,
358 const char *attribute, 362 const char *attribute,
359 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 363 struct GNUNET_CRYPTO_PublicKey *subject,
360 const char *delegated_attribute, 364 const char *delegated_attribute,
361 GNUNET_ABD_DelegateResultProcessor proc, 365 GNUNET_ABD_DelegateResultProcessor proc,
362 void *proc_cls); 366 void *proc_cls);
@@ -384,13 +388,13 @@ GNUNET_ABD_remove_delegation (struct GNUNET_ABD_Handle *handle,
384 * 388 *
385 * @param issuer the ego that should be used to issue the attribute 389 * @param issuer the ego that should be used to issue the attribute
386 * @param subject the subject of the attribute 390 * @param subject the subject of the attribute
387 * @param attribute the name of the attribute 391 * @param iss_attr the name of the attribute
388 * @param expiration the TTL of the credential 392 * @param expiration the TTL of the credential
389 * @return handle to the queued request 393 * @return handle to the queued request
390 */ 394 */
391struct GNUNET_ABD_Delegate* 395struct GNUNET_ABD_Delegate*
392GNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, 396GNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_PrivateKey *issuer,
393 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 397 struct GNUNET_CRYPTO_PublicKey *subject,
394 const char *iss_attr, 398 const char *iss_attr,
395 const char *sub_attr, 399 const char *sub_attr,
396 struct GNUNET_TIME_Absolute *expiration); 400 struct GNUNET_TIME_Absolute *expiration);
@@ -415,3 +419,5 @@ GNUNET_ABD_request_cancel (struct GNUNET_ABD_Request *lr);
415#endif 419#endif
416 420
417/** @} */ /* end of group */ 421/** @} */ /* end of group */
422
423/** @} */ /* end of group addition to reclaim_suite */
diff --git a/src/include/gnunet_abe_lib.h b/src/include/gnunet_abe_lib.h
deleted file mode 100644
index 7aeb3520d..000000000
--- a/src/include/gnunet_abe_lib.h
+++ /dev/null
@@ -1,193 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file include/gnunet_abe_lib.h
23 * @brief Attribute-Based Encryption primitives for GNUnet
24 *
25 * @author Martin Schanzenbach
26 *
27 * @defgroup abe ABE Crypto library: Attribute-Based Encryption operations
28 *
29 */
30#ifndef GNUNET_ABE_LIB_H
31#define GNUNET_ABE_LIB_H
32
33#ifdef __cplusplus
34extern "C"
35{
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41#include "gnunet_common.h"
42#include <gcrypt.h>
43
44/**
45 * @brief type for ABE master keys
46 */
47struct GNUNET_CRYPTO_AbeMasterKey;
48
49/**
50 * @brief type for ABE keys
51 */
52struct GNUNET_CRYPTO_AbeKey;
53
54
55/**
56 * @ingroup abe
57 * Create a new CP-ABE master key. Caller must free return value.
58 *
59 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
60 */
61struct GNUNET_ABE_AbeMasterKey *
62GNUNET_ABE_cpabe_create_master_key (void);
63
64/**
65 * @ingroup abe
66 * Delete a CP-ABE master key.
67 *
68 * @param key the master key
69 * @return fresh private key; free using #GNUNET_free
70 */
71void
72GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key);
73
74/**
75 * @ingroup abe
76 * Create a new CP-ABE key. Caller must free return value.
77 *
78 * @param key the master key
79 * @param attrs the attributes to append to the key
80 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
81 */
82struct GNUNET_ABE_AbeKey *
83GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
84 char **attrs);
85
86/**
87 * @ingroup abe
88 * Delete a CP-ABE key.
89 *
90 * @param key the key to delete
91 * @param delete_pub GNUNET_YES if the public key should also be freed (bug in gabe)
92 * @return fresh private key; free using #GNUNET_free
93 */
94void
95GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
96 int delete_pub);
97
98
99/**
100 * @ingroup abe
101 * Encrypt a block using sessionkey.
102 *
103 * @param block the block to encrypt
104 * @param size the size of the @a block
105 * @param policy the ABE policy
106 * @param key the key used to encrypt
107 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
108 * @return the size of the encrypted block, -1 for errors
109 */
110ssize_t
111GNUNET_ABE_cpabe_encrypt (const void *block,
112 size_t size,
113 const char *policy,
114 const struct GNUNET_ABE_AbeMasterKey *key,
115 void **result);
116
117/**
118 * @ingroup abe
119 * Decrypt a block using the ABE key.
120 *
121 * @param block the block to encrypt
122 * @param size the size of the @a block
123 * @param key the key used to decrypt
124 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
125 * @return the size of the encrypted block, -1 for errors
126 */
127ssize_t
128GNUNET_ABE_cpabe_decrypt (const void *block,
129 size_t size,
130 const struct GNUNET_ABE_AbeKey *key,
131 void **result);
132
133/**
134 * @ingroup abe
135 * Serialize an ABE key.
136 *
137 * @param key the key to serialize
138 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
139 * @return the size of the encrypted block, -1 for errors
140 */
141ssize_t
142GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
143 void **result);
144
145/**
146 * @ingroup abe
147 * Deserialize a serialized ABE key.
148 *
149 * @param data the data to deserialize
150 * @param len the length of the data.
151 * @return the ABE key. NULL of unsuccessful
152 */
153struct GNUNET_ABE_AbeKey*
154GNUNET_ABE_cpabe_deserialize_key (const void *data,
155 size_t len);
156
157/**
158 * @ingroup abe
159 * Serialize an ABE master key.
160 *
161 * @param key the key to serialize
162 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
163 * @return the size of the encrypted block, -1 for errors
164 */
165ssize_t
166GNUNET_ABE_cpabe_serialize_master_key (const struct
167 GNUNET_ABE_AbeMasterKey *key,
168 void **result);
169
170/**
171 * @ingroup abe
172 * Deserialize an ABE master key.
173 *
174 * @param data the data to deserialize
175 * @param len the length of the data.
176 * @return the ABE key. NULL of unsuccessful
177 */
178struct GNUNET_ABE_AbeMasterKey*
179GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
180 size_t len);
181
182
183#if 0 /* keep Emacsens' auto-indent happy */
184{
185#endif
186#ifdef __cplusplus
187}
188#endif
189
190
191/* ifndef GNUNET_ABE_LIB_H */
192#endif
193/* end of gnunet_abe_lib.h */
diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h
index 1e2ac59f7..489dc7050 100644
--- a/src/include/gnunet_applications.h
+++ b/src/include/gnunet_applications.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -133,4 +136,6 @@ extern "C"
133 136
134/** @} */ /* end of group */ 137/** @} */ /* end of group */
135 138
139/** @} */ /* end of group addition to Backbone */
140
136/* end of gnunet_applications.h */ 141/* end of gnunet_applications.h */
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 9615f8c9d..639e723c5 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -43,6 +43,7 @@ extern "C"
43#endif 43#endif
44#endif 44#endif
45 45
46
46#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
47 48
48/** 49/**
diff --git a/src/include/gnunet_ats_application_service.h b/src/include/gnunet_ats_application_service.h
deleted file mode 100644
index a48dba825..000000000
--- a/src/include/gnunet_ats_application_service.h
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Bandwidth allocation API for applications to interact with
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Bandwidth allocation
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_APPLICATION_SERVICE_H
35#define GNUNET_ATS_APPLICATION_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39
40/**
41 * Handle to the ATS subsystem for making suggestions about
42 * connections the peer would like to have.
43 */
44struct GNUNET_ATS_ApplicationHandle;
45
46
47/**
48 * Initialize the ATS application client handle.
49 *
50 * @param cfg configuration to use
51 * @return ats application handle, NULL on error
52 */
53struct GNUNET_ATS_ApplicationHandle *
54GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
55
56
57/**
58 * Shutdown ATS application client.
59 *
60 * @param ch handle to destroy
61 */
62void
63GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch);
64
65
66/**
67 * Handle for suggestion requests.
68 */
69struct GNUNET_ATS_ApplicationSuggestHandle;
70
71
72/**
73 * An application would like to communicate with a peer. ATS should
74 * allocate bandwidth using a suitable address for requiremetns @a pk
75 * to transport.
76 *
77 * @param ch handle
78 * @param peer identity of the peer we need an address for
79 * @param pk what kind of application will the application require (can be
80 * #GNUNET_MQ_PREFERENCE_NONE, we will still try to connect)
81 * @param bw desired bandwidth, can be zero (we will still try to connect)
82 * @return suggestion handle, NULL if request is already pending
83 */
84struct GNUNET_ATS_ApplicationSuggestHandle *
85GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
86 const struct GNUNET_PeerIdentity *peer,
87 enum GNUNET_MQ_PreferenceKind pk,
88 struct GNUNET_BANDWIDTH_Value32NBO bw);
89
90
91/**
92 * We no longer care about communicating with a peer.
93 *
94 * @param sh handle
95 */
96void
97GNUNET_ATS_application_suggest_cancel (struct
98 GNUNET_ATS_ApplicationSuggestHandle *sh);
99
100/** @} */ /* end of group */
101
102#endif
103/* end of file gnunet_ats_application_service.h */
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h
deleted file mode 100644
index c0662673c..000000000
--- a/src/include/gnunet_ats_plugin.h
+++ /dev/null
@@ -1,486 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * API for the ATS solvers.
26 *
27 * @defgroup ats-plugin ATS service plugin API
28 * Plugin API for the ATS service.
29 *
30 * Specifies the struct that is given to the plugin's entry method and the other
31 * struct that must be returned. Note that the destructors of ATS plugins will
32 * be given the value returned by the constructor and is expected to return a
33 * NULL pointer.
34 *
35 * @{
36 */
37#ifndef PLUGIN_ATS_H
38#define PLUGIN_ATS_H
39
40#include "gnunet_ats_service.h"
41#include "gnunet_statistics_service.h"
42
43/**
44 * Representation of an address the plugin can choose from.
45 */
46struct ATS_Address;
47
48/**
49 * Change the preference for a peer
50 *
51 * @param handle the solver handle
52 * @param client the client sending this request
53 * @param peer the peer id
54 * @param kind the preference kind to change
55 * @param score the new preference score
56 * @param pref_rel the normalized preference value for this kind over all clients
57 */
58typedef void
59(*GAS_solver_address_change_preference) (void *solver,
60 const struct GNUNET_PeerIdentity *peer,
61 enum GNUNET_ATS_PreferenceKind kind,
62 double pref_rel);
63
64
65/**
66 * Give feedback about the current assignment
67 *
68 * @param handle the solver handle
69 * @param application the application sending this request
70 * @param peer the peer id
71 * @param scope the time interval for this feedback: [now - scope .. now]
72 * @param kind the preference kind for this feedback
73 * @param score the feedback score
74 */
75typedef void
76(*GAS_solver_address_feedback_preference) (void *solver,
77 struct GNUNET_SERVICE_Client *
78 application,
79 const struct
80 GNUNET_PeerIdentity *peer,
81 const struct GNUNET_TIME_Relative
82 scope,
83 enum GNUNET_ATS_PreferenceKind kind,
84 double score);
85
86/**
87 * Notify the solver about a bulk operation changing possibly a lot of values
88 * Solver will not resolve until all bulk operations are marked as done
89 *
90 * @param solver the solver
91 */
92typedef void
93(*GAS_solver_bulk_start) (void *solver);
94
95
96/**
97 * Mark a bulk operation as done
98 * Solver will resolve if values have changed
99 *
100 * @param solver the solver
101 */
102typedef void
103(*GAS_solver_bulk_stop) (void *solver);
104
105
106/**
107 * Add a single address within a network to the solver
108 *
109 * @param solver the solver Handle
110 * @param address the address to add
111 * @param network network type of this address
112 */
113typedef void
114(*GAS_solver_address_add) (void *solver,
115 struct ATS_Address *address,
116 uint32_t network);
117
118
119/**
120 * Delete an address or just the session from the solver
121 *
122 * @param solver the solver Handle
123 * @param address the address to delete
124 */
125typedef void
126(*GAS_solver_address_delete) (void *solver,
127 struct ATS_Address *address);
128
129
130/**
131 * Transport properties for this address have changed
132 *
133 * @param solver solver handle
134 * @param address the address
135 */
136typedef void
137(*GAS_solver_address_property_changed) (void *solver,
138 struct ATS_Address *address);
139
140
141/**
142 * Get the preferred address for a peer from solver
143 *
144 * @param solver the solver to use
145 * @param peer the peer
146 */
147typedef void
148(*GAS_solver_get_preferred_address) (void *solver,
149 const struct GNUNET_PeerIdentity *peer);
150
151
152/**
153 * Stop getting the preferred address for a peer from solver
154 *
155 * @param solver the solver to use
156 * @param peer the peer
157 */
158typedef void
159(*GAS_solver_stop_get_preferred_address) (void *solver,
160 const struct
161 GNUNET_PeerIdentity *peer);
162
163
164/**
165 * Solver functions.
166 *
167 * Each solver is required to set up and return an instance
168 * of this struct during initialization.
169 */
170struct GNUNET_ATS_SolverFunctions
171{
172 /**
173 * Closure to pass to all solver functions in this struct.
174 */
175 void *cls;
176
177 /**
178 * Add a new address for a peer to the solver
179 *
180 * The address is already contained in the addresses hashmap!
181 */
182 GAS_solver_address_add s_add;
183
184 /**
185 * Update the properties of an address in the solver
186 */
187 GAS_solver_address_property_changed s_address_update_property;
188
189 /**
190 * Tell solver to notify ATS if the address to use changes for a specific
191 * peer using the bandwidth changed callback
192 *
193 * The solver must only notify about changes for peers with pending address
194 * requests!
195 */
196 GAS_solver_get_preferred_address s_get;
197
198 /**
199 * Tell solver stop notifying ATS about changes for this peers
200 *
201 * The solver must only notify about changes for peers with pending address
202 * requests!
203 */
204 GAS_solver_stop_get_preferred_address s_get_stop;
205
206 /**
207 * Delete an address in the solver
208 *
209 * The address is not contained in the address hashmap anymore!
210 */
211 GAS_solver_address_delete s_del;
212
213 /**
214 * Change relative preference for quality in solver
215 */
216 GAS_solver_address_change_preference s_pref;
217
218 /**
219 * Give feedback about the current assignment
220 */
221 GAS_solver_address_feedback_preference s_feedback;
222
223 /**
224 * Start a bulk operation
225 *
226 * Used if many values have to be updated at the same time.
227 * When a bulk operation is pending the solver does not have to resolve
228 * the problem since more updates will follow anyway
229 *
230 * For each call to bulk_start, a call to bulk_stop is required!
231 */
232 GAS_solver_bulk_start s_bulk_start;
233
234 /**
235 * Bulk operation done
236 *
237 * If no more bulk operations are pending, the solver can solve the problem
238 * with the updated values
239 */
240 GAS_solver_bulk_stop s_bulk_stop;
241};
242
243
244/**
245 * Operation codes for solver information callback
246 *
247 * Order of calls is expected to be:
248 * #GAS_OP_SOLVE_START
249 * #GAS_OP_SOLVE_STOP
250 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
251 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
252 *
253 */
254enum GAS_Solver_Operation
255{
256 /**
257 * A solution iteration has been started
258 */
259 GAS_OP_SOLVE_START,
260
261 /**
262 * A solution iteration has been finished
263 */
264 GAS_OP_SOLVE_STOP,
265
266 /**
267 * The setup of the problem as a preparation to solve it was started
268 */
269 GAS_OP_SOLVE_SETUP_START,
270
271 /**
272 * The setup of the problem as a preparation to solve is finished
273 */
274 GAS_OP_SOLVE_SETUP_STOP,
275
276 /**
277 * Solving of the LP problem was started
278 * MLP solver only
279 */
280 GAS_OP_SOLVE_MLP_LP_START,
281
282 /**
283 * Solving of the LP problem is done
284 * MLP solver only
285 */
286 GAS_OP_SOLVE_MLP_LP_STOP,
287
288 /**
289 * Solving of the MLP problem was started
290 * MLP solver only
291 */
292 GAS_OP_SOLVE_MLP_MLP_START,
293
294 /**
295 * Solving of the MLP problem is done
296 * MLP solver only
297 */
298 GAS_OP_SOLVE_MLP_MLP_STOP,
299
300 /**
301 * After the problem was finished, start notifications about changes
302 * to addresses
303 */
304 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
305
306 /**
307 * After the problem was finished, notifications about changes to addresses
308 * are done
309 */
310 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
311};
312
313
314/**
315 * Status of a GAS_Solver_Operation operation
316 */
317enum GAS_Solver_Status
318{
319 /**
320 * Success
321 */
322 GAS_STAT_SUCCESS,
323
324 /**
325 * Failure
326 */
327 GAS_STAT_FAIL
328};
329
330
331/**
332 * Status of the operation
333 */
334enum GAS_Solver_Additional_Information
335{
336 /**
337 * No more specific information
338 */
339 GAS_INFO_NONE,
340
341 /**
342 * A full solution process is performed
343 * Quite specific to the MLP solver
344 */
345 GAS_INFO_FULL,
346
347 /**
348 * An existing solution was reused
349 * Quite specific to the MLP solver
350 */
351 GAS_INFO_UPDATED,
352
353 /**
354 * The proportional solver had to recalculate for a single network
355 */
356 GAS_INFO_PROP_SINGLE,
357
358 /**
359 * The proportional solver had to recalculate for all networks
360 */
361 GAS_INFO_PROP_ALL
362};
363
364
365/**
366 * Callback to call with additional information
367 * Used for measurement
368 *
369 * @param cls the closure
370 * @param op the operation
371 */
372typedef void
373(*GAS_solver_information_callback) (void *cls,
374 enum GAS_Solver_Operation op,
375 enum GAS_Solver_Status stat,
376 enum GAS_Solver_Additional_Information);
377
378
379/**
380 * Callback to call from solver when bandwidth for address has changed
381 *
382 * @param address the with changed bandwidth assigned
383 */
384typedef void
385(*GAS_bandwidth_changed_cb) (void *cls,
386 struct ATS_Address *address);
387
388
389/**
390 * Callback to call from solver to obtain application preference
391 * values for a peer.
392 *
393 * @param cls the cls
394 * @param id the peer id
395 * @return carry of double values containing the preferences with
396 * GNUNET_ATS_PreferenceCount elements
397 */
398typedef const double *
399(*GAS_get_preferences) (void *cls,
400 const struct GNUNET_PeerIdentity *id);
401
402
403/**
404 * Callback to call from solver to obtain application connectivity
405 * preferences for a peer.
406 *
407 * @param cls the cls
408 * @param id the peer id
409 * @return 0 if connectivity is not desired, non-null if address
410 * suggestions are requested
411 */
412typedef unsigned int
413(*GAS_get_connectivity) (void *cls,
414 const struct GNUNET_PeerIdentity *id);
415
416
417/**
418 * The ATS plugin will pass a pointer to a struct
419 * of this type as to the initialization function
420 * of the ATS plugins.
421 */
422struct GNUNET_ATS_PluginEnvironment
423{
424 /**
425 * Configuration handle to be used by the solver
426 */
427 const struct GNUNET_CONFIGURATION_Handle *cfg;
428
429 /**
430 * Statistics handle to be used by the solver
431 */
432 struct GNUNET_STATISTICS_Handle *stats;
433
434 /**
435 * Closure to pass to all callbacks in this struct.
436 */
437 void *cls;
438
439 /**
440 * Hashmap containing all addresses available
441 */
442 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
443
444 /**
445 * ATS addresses callback to be notified about bandwidth assignment changes
446 */
447 GAS_bandwidth_changed_cb bandwidth_changed_cb;
448
449 /**
450 * ATS addresses function to obtain preference values
451 */
452 GAS_get_preferences get_preferences;
453
454 /**
455 * ATS addresses function to obtain preference values
456 */
457 GAS_get_connectivity get_connectivity;
458
459 /**
460 * Callback for solver to call with status information,
461 * can be NULL
462 */
463 GAS_solver_information_callback info_cb;
464
465 /**
466 * Number of networks available, size of the @e out_quota
467 * and @e in_quota arrays.
468 */
469 unsigned int network_count;
470
471 /**
472 * Array of configured outbound quotas
473 * Order according to networks in network array
474 */
475 unsigned long long out_quota[GNUNET_NT_COUNT];
476
477 /**
478 * Array of configured inbound quotas
479 * Order according to networks in network array
480 */
481 unsigned long long in_quota[GNUNET_NT_COUNT];
482};
483
484#endif
485
486/** @} */ /* end of group */
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h
deleted file mode 100644
index 68ba8e6b2..000000000
--- a/src/include/gnunet_ats_service.h
+++ /dev/null
@@ -1,624 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Automatic transport selection and outbound bandwidth determination
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Automatic Transport Selection and outbound bandwidth determination
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_SERVICE_H
35#define GNUNET_ATS_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39#include "gnunet_hello_lib.h"
40
41
42/**
43 * Default bandwidth assigned to a network : 64 KB/s
44 */
45#define GNUNET_ATS_DefaultBandwidth 65536
46
47/**
48 * Undefined value for an `enum GNUNET_ATS_Property`
49 */
50#define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
51
52/**
53 * String representation for GNUNET_ATS_VALUE_UNDEFINED
54 */
55#define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
56
57/**
58 * Maximum bandwidth assigned to a network : 4095 MB/s
59 */
60#define GNUNET_ATS_MaxBandwidth UINT32_MAX
61
62/**
63 * Textual equivalent for GNUNET_ATS_MaxBandwidth
64 */
65#define GNUNET_ATS_MaxBandwidthString "unlimited"
66
67
68/**
69 * ATS performance characteristics for an address.
70 */
71struct GNUNET_ATS_Properties
72{
73 /**
74 * Delay. Time between when the time packet is sent and the packet
75 * arrives. FOREVER if we did not measure yet.
76 */
77 struct GNUNET_TIME_Relative delay;
78
79 /**
80 * Actual traffic on this connection from this peer to the other peer.
81 * Includes transport overhead.
82 *
83 * Unit: [bytes/second]
84 */
85 uint32_t utilization_out;
86
87 /**
88 * Actual traffic on this connection from the other peer to this peer.
89 * Includes transport overhead.
90 *
91 * Unit: [bytes/second]
92 */
93 uint32_t utilization_in;
94
95 /**
96 * Distance on network layer (required for distance-vector routing)
97 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
98 */
99 unsigned int distance;
100
101 /**
102 * Which network scope does the respective address belong to?
103 * This property does not change.
104 */
105 enum GNUNET_NetworkType scope;
106};
107
108
109/**
110 * ATS performance characteristics for an address in
111 * network byte order (for IPC).
112 */
113struct GNUNET_ATS_PropertiesNBO
114{
115 /**
116 * Actual traffic on this connection from this peer to the other peer.
117 * Includes transport overhead.
118 *
119 * Unit: [bytes/second]
120 */
121 uint32_t utilization_out GNUNET_PACKED;
122
123 /**
124 * Actual traffic on this connection from the other peer to this peer.
125 * Includes transport overhead.
126 *
127 * Unit: [bytes/second]
128 */
129 uint32_t utilization_in GNUNET_PACKED;
130
131 /**
132 * Which network scope does the respective address belong to?
133 * This property does not change.
134 */
135 uint32_t scope GNUNET_PACKED;
136
137 /**
138 * Distance on network layer (required for distance-vector routing)
139 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
140 */
141 uint32_t distance GNUNET_PACKED;
142
143 /**
144 * Delay. Time between when the time packet is sent and the packet
145 * arrives. FOREVER if we did not measure yet.
146 */
147 struct GNUNET_TIME_RelativeNBO delay;
148};
149
150
151/* ********************* LAN Characterization library ************************ */
152/* Note: these functions do not really communicate with the ATS service */
153
154
155/**
156 * Convert ATS properties from host to network byte order.
157 *
158 * @param nbo[OUT] value written
159 * @param hbo value read
160 */
161void
162GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
163 const struct GNUNET_ATS_Properties *hbo);
164
165
166/**
167 * Convert ATS properties from network to host byte order.
168 *
169 * @param hbo[OUT] value written
170 * @param nbo value read
171 */
172void
173GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
174 const struct GNUNET_ATS_PropertiesNBO *nbo);
175
176
177/* ********************Connection Suggestion API ***************************** */
178
179/**
180 * Handle to the ATS subsystem for making suggestions about
181 * connections the peer would like to have.
182 */
183struct GNUNET_ATS_ConnectivityHandle;
184
185/**
186 * Handle for address suggestion requests.
187 */
188struct GNUNET_ATS_ConnectivitySuggestHandle;
189
190
191/**
192 * Initialize the ATS connectivity suggestion client handle.
193 *
194 * @param cfg configuration to use
195 * @return ats connectivity handle, NULL on error
196 */
197struct GNUNET_ATS_ConnectivityHandle *
198GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
199
200
201/**
202 * Shutdown ATS connectivity suggestion client.
203 *
204 * @param ch handle to destroy
205 */
206void
207GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
208
209
210/**
211 * We would like to establish a new connection with a peer. ATS
212 * should suggest a good address to begin with.
213 *
214 * @param ch handle
215 * @param peer identity of the peer we need an address for
216 * @param strength how urgent is the need for such a suggestion
217 * @return suggestion handle, NULL if request is already pending
218 */
219struct GNUNET_ATS_ConnectivitySuggestHandle *
220GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
221 const struct GNUNET_PeerIdentity *peer,
222 uint32_t strength);
223
224
225/**
226 * We no longer care about being connected to a peer.
227 *
228 * @param sh handle
229 */
230void
231GNUNET_ATS_connectivity_suggest_cancel (struct
232 GNUNET_ATS_ConnectivitySuggestHandle *sh);
233
234
235/* ******************************** Scheduling API ***************************** */
236
237/**
238 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
239 */
240struct GNUNET_ATS_SchedulingHandle;
241
242/**
243 * Opaque session handle, defined by plugins. Contents not known to ATS.
244 */
245struct GNUNET_ATS_Session;
246
247
248/**
249 * Signature of a function called by ATS with the current bandwidth
250 * and address preferences as determined by ATS. If our connection
251 * to ATS dies and thus all suggestions become invalid, this function
252 * is called ONCE with all arguments (except @a cls) being NULL/0.
253 *
254 * @param cls closure
255 * @param peer for which we suggest an address, NULL if ATS connection died
256 * @param address suggested address (including peer identity of the peer),
257 * may be NULL to signal disconnect from peer
258 * @param session session to use, NULL to establish a new outgoing session
259 * @param bandwidth_out assigned outbound bandwidth for the connection,
260 * 0 to signal disconnect
261 * @param bandwidth_in assigned inbound bandwidth for the connection,
262 * 0 to signal disconnect
263 */
264typedef void
265(*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
266 const struct GNUNET_PeerIdentity *peer,
267 const struct
268 GNUNET_HELLO_Address *address,
269 struct GNUNET_ATS_Session *session,
270 struct GNUNET_BANDWIDTH_Value32NBO
271 bandwidth_out,
272 struct GNUNET_BANDWIDTH_Value32NBO
273 bandwidth_in);
274
275
276/**
277 * Initialize the ATS scheduling subsystem.
278 *
279 * @param cfg configuration to use
280 * @param suggest_cb notification to call whenever the suggestation changed
281 * @param suggest_cb_cls closure for @a suggest_cb
282 * @return ats context
283 */
284struct GNUNET_ATS_SchedulingHandle *
285GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
286 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
287 void *suggest_cb_cls);
288
289
290/**
291 * Client is done with ATS scheduling, release resources.
292 *
293 * @param sh handle to release
294 */
295void
296GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
297
298
299/**
300 * Handle used within ATS to track an address.
301 */
302struct GNUNET_ATS_AddressRecord;
303
304
305/**
306 * We have a new address ATS should know. Addresses have to be added with this
307 * function before they can be: updated, set in use and destroyed
308 *
309 * @param sh handle
310 * @param address the address
311 * @param session session handle (if available, e.g for incoming connections)
312 * @param prop performance data for the address
313 * @return handle to the address representation inside ATS, NULL
314 * on error (i.e. ATS knows this exact address already, or
315 * address is invalid)
316 */
317struct GNUNET_ATS_AddressRecord *
318GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
319 const struct GNUNET_HELLO_Address *address,
320 struct GNUNET_ATS_Session *session,
321 const struct GNUNET_ATS_Properties *prop);
322
323
324/**
325 * An address was used to initiate a session.
326 *
327 * @param ar address record to update information for
328 * @param session session handle
329 */
330void
331GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
332 struct GNUNET_ATS_Session *session);
333
334
335/**
336 * A @a session was destroyed, disassociate it from the given address
337 * record. If this was an incoming address, destroys the address as
338 * well.
339 *
340 * @param ar address record to update information for
341 * @param session session handle
342 * @return #GNUNET_YES if the @a ar was destroyed because
343 * it was an incoming address,
344 * #GNUNET_NO if the @ar was kept because we can
345 * use it still to establish a new session
346 */
347int
348GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
349 struct GNUNET_ATS_Session *session);
350
351
352/**
353 * We have updated performance statistics for a given address. Note
354 * that this function can be called for addresses that are currently
355 * in use as well as addresses that are valid but not actively in use.
356 * Furthermore, the peer may not even be connected to us right now (@a
357 * session value of NULL used to signal disconnect, or somehow we
358 * otherwise got updated on @a ats information). Based on the
359 * information provided, ATS may update bandwidth assignments and
360 * suggest to switch addresses.
361 *
362 * @param ar address record to update information for
363 * @param prop performance data for the address
364 */
365void
366GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
367 const struct GNUNET_ATS_Properties *prop);
368
369
370/**
371 * An address got destroyed, stop using it as a valid address.
372 *
373 * @param ar address record to destroy, it's validation has
374 * expired and ATS may no longer use it
375 */
376void
377GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
378
379
380/* ******************************** Performance API ***************************** */
381
382/**
383 * ATS Handle to obtain and/or modify performance information.
384 */
385struct GNUNET_ATS_PerformanceHandle;
386
387/**
388 * Signature of a function that is called with QoS information about an address.
389 *
390 * @param cls closure
391 * @param address the address, NULL if ATS service was disconnected or
392 * when the iteration is completed in the case of
393 * #GNUNET_ATS_performance_list_addresses()
394 * @param address_active #GNUNET_YES if this address is actively used
395 * to maintain a connection to a peer;
396 * #GNUNET_NO if the address is not actively used;
397 * #GNUNET_SYSERR if this address is no longer available for ATS
398 * @param bandwidth_out assigned outbound bandwidth for the connection
399 * @param bandwidth_in assigned inbound bandwidth for the connection
400 * @param prop performance data for the address
401 */
402typedef void
403(*GNUNET_ATS_AddressInformationCallback) (void *cls,
404 const struct
405 GNUNET_HELLO_Address *address,
406 int address_active,
407 struct GNUNET_BANDWIDTH_Value32NBO
408 bandwidth_out,
409 struct GNUNET_BANDWIDTH_Value32NBO
410 bandwidth_in,
411 const struct
412 GNUNET_ATS_Properties *prop);
413
414
415/**
416 * Handle for an address listing operation
417 */
418struct GNUNET_ATS_AddressListHandle;
419
420
421/**
422 * Get handle to access performance API of the ATS subsystem.
423 *
424 * @param cfg configuration to use
425 * @param addr_info_cb callback called when performance characteristics for
426 * an address change
427 * @param addr_info_cb_cls closure for @a addr_info_cb
428 * @return ats performance context
429 */
430struct GNUNET_ATS_PerformanceHandle *
431GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
432 GNUNET_ATS_AddressInformationCallback addr_info_cb,
433 void *addr_info_cb_cls);
434
435
436/**
437 * Get information about addresses known to the ATS subsystem.
438 *
439 * @param ph the performance handle to use
440 * @param peer peer idm can be NULL for all peers
441 * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO to
442 * get only address currently used
443 * @param infocb callback to call with the addresses,
444 * will callback with address == NULL when done
445 * @param infocb_cls closure for @a infocb
446 * @return handle to abort the operation
447 */
448struct GNUNET_ATS_AddressListHandle *
449GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph,
450 const struct GNUNET_PeerIdentity *peer,
451 int all,
452 GNUNET_ATS_AddressInformationCallback
453 infocb,
454 void *infocb_cls);
455
456
457/**
458 * Cancel a pending address listing operation
459 *
460 * @param alh the `struct GNUNET_ATS_AddressListHandle` handle to cancel
461 */
462void
463GNUNET_ATS_performance_list_addresses_cancel (struct
464 GNUNET_ATS_AddressListHandle *alh);
465
466
467/**
468 * Client is done using the ATS performance subsystem, release resources.
469 *
470 * @param ph handle
471 */
472void
473GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
474
475
476/**
477 * Function called with reservation result.
478 *
479 * @param cls closure
480 * @param peer identifies the peer
481 * @param amount set to the amount that was actually reserved or unreserved;
482 * either the full requested amount or zero (no partial reservations)
483 * @param res_delay if the reservation could not be satisfied (amount was 0), how
484 * long should the client wait until re-trying?
485 */
486typedef void
487(*GNUNET_ATS_ReservationCallback) (void *cls,
488 const struct GNUNET_PeerIdentity *peer,
489 int32_t amount,
490 struct GNUNET_TIME_Relative res_delay);
491
492
493/**
494 * Context that can be used to cancel a peer information request.
495 */
496struct GNUNET_ATS_ReservationContext;
497
498
499/**
500 * Reserve inbound bandwidth from the given peer. ATS will look at
501 * the current amount of traffic we receive from the peer and ensure
502 * that the peer could add 'amount' of data to its stream.
503 *
504 * @param ph performance handle
505 * @param peer identifies the peer
506 * @param amount reserve N bytes for receiving, negative
507 * amounts can be used to undo a (recent) reservation;
508 * @param rcb function to call with the resulting reservation information
509 * @param rcb_cls closure for @a rcb
510 * @return NULL on error
511 * @deprecated will be replaced soon
512 */
513struct GNUNET_ATS_ReservationContext *
514GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
515 const struct GNUNET_PeerIdentity *peer,
516 int32_t amount,
517 GNUNET_ATS_ReservationCallback rcb,
518 void *rcb_cls);
519
520
521/**
522 * Cancel request for reserving bandwidth.
523 *
524 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
525 */
526void
527GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
528
529
530/**
531 * ATS preference types as array initializer
532 */
533#define GNUNET_ATS_PreferenceType { GNUNET_ATS_PREFERENCE_BANDWIDTH, \
534 GNUNET_ATS_PREFERENCE_LATENCY, \
535 GNUNET_ATS_PREFERENCE_END }
536
537/**
538 * ATS preference types as string array initializer
539 */
540#define GNUNET_ATS_PreferenceTypeString { "BANDWIDTH", "LATENCY", "END" }
541
542/**
543 * Enum defining all known preference categories.
544 */
545enum GNUNET_ATS_PreferenceKind
546{
547 /**
548 * Change the peer's bandwidth value (value per byte of bandwidth in
549 * the goal function) to the given amount. The argument is followed
550 * by a double value giving the desired value (can be negative).
551 * Preference changes are forgotten if peers disconnect.
552 */
553 GNUNET_ATS_PREFERENCE_BANDWIDTH = 0,
554
555 /**
556 * Change the peer's latency value to the given amount. The
557 * argument is followed by a double value giving the desired value
558 * (can be negative). The absolute score in the goal function is
559 * the inverse of the latency in microseconds (minimum: 1
560 * microsecond) multiplied by the latency preferences.
561 */
562 GNUNET_ATS_PREFERENCE_LATENCY = 1,
563
564 /**
565 * End of preference list.
566 */
567 GNUNET_ATS_PREFERENCE_END = 2
568};
569
570
571/**
572 * Convert a GNUNET_ATS_PreferenceType to a string
573 *
574 * @param type the preference type
575 * @return a string or NULL if invalid
576 */
577const char *
578GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type);
579
580
581/**
582 * Change preferences for the given peer. Preference changes are forgotten if peers
583 * disconnect.
584 *
585 * @param ph performance handle @param peer identifies the peer
586 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the
587 * desired changes
588 */
589void
590GNUNET_ATS_performance_change_preference (struct
591 GNUNET_ATS_PerformanceHandle *ph,
592 const struct
593 GNUNET_PeerIdentity *peer,
594 ...);
595
596
597/**
598 * Application feedback on how good preference requirements are fulfilled
599 * for the preferences included in the given time scope [now - scope .. now]
600 *
601 * An application notifies ATS if (and only if) it has feedback information
602 * for specific properties. This values are valid until the feedback scores are
603 * updated by the application.
604 *
605 * If the application has no feedback for this preference kind the application
606 * will not explicitly call for this property and will not include it in this
607 * function call.
608 *
609 * @param ph performance handle
610 * @param scope the time interval this valid for: [now - scope .. now]
611 * @param peer identifies the peer
612 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
613 */
614void
615GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
616 const struct GNUNET_PeerIdentity *peer,
617 const struct GNUNET_TIME_Relative scope,
618 ...);
619
620#endif
621
622/** @} */ /* end of group */
623
624/* end of file gnunet-service-transport_ats.h */
diff --git a/src/include/gnunet_ats_transport_service.h b/src/include/gnunet_ats_transport_service.h
deleted file mode 100644
index fd821baef..000000000
--- a/src/include/gnunet_ats_transport_service.h
+++ /dev/null
@@ -1,240 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Bandwidth allocation API for the transport service
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Bandwidth allocation for transport service
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_TRANSPORT_SERVICE_H
35#define GNUNET_ATS_TRANSPORT_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39#include "gnunet_nt_lib.h"
40#include "gnunet_transport_communication_service.h"
41
42
43/**
44 * ATS performance characteristics for a session.
45 */
46struct GNUNET_ATS_Properties
47{
48 /**
49 * Delay. Time between when the time packet is sent and the packet
50 * arrives. FOREVER if we did not (successfully) measure yet.
51 */
52 struct GNUNET_TIME_Relative delay;
53
54 /**
55 * Confirmed successful payload on this connection from this peer to
56 * the other peer.
57 *
58 * Unit: [bytes/second]
59 */
60 uint32_t goodput_out;
61
62 /**
63 * Confirmed useful payload on this connection to this peer from
64 * the other peer.
65 *
66 * Unit: [bytes/second]
67 */
68 uint32_t goodput_in;
69
70 /**
71 * Actual traffic on this connection from this peer to the other peer.
72 * Includes transport overhead.
73 *
74 * Unit: [bytes/second]
75 */
76 uint32_t utilization_out;
77
78 /**
79 * Actual traffic on this connection from the other peer to this peer.
80 * Includes transport overhead.
81 *
82 * Unit: [bytes/second]
83 */
84 uint32_t utilization_in;
85
86 /**
87 * Distance on network layer (required for distance-vector routing)
88 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
89 */
90 uint32_t distance;
91
92 /**
93 * MTU of the network layer, UINT32_MAX for no MTU (stream).
94 *
95 * Unit: [bytes]
96 */
97 uint32_t mtu;
98
99 /**
100 * Which network scope does the respective address belong to?
101 */
102 enum GNUNET_NetworkType nt;
103
104 /**
105 * What characteristics does this communicator have?
106 */
107 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
108};
109
110
111/* ******************************** Transport API ***************************** */
112
113/**
114 * Handle to the ATS subsystem for bandwidth/transport transport information.
115 */
116struct GNUNET_ATS_TransportHandle;
117
118/**
119 * Opaque session handle, to be defined by transport. Contents not known to ATS.
120 */
121struct GNUNET_ATS_Session;
122
123
124/**
125 * Signature of a function called by ATS with the current bandwidth
126 * allocation to be used as determined by ATS.
127 *
128 * @param cls closure
129 * @param session session this is about
130 * @param bandwidth_out assigned outbound bandwidth for the connection,
131 * 0 to signal disconnect
132 * @param bandwidth_in assigned inbound bandwidth for the connection,
133 * 0 to signal disconnect
134 */
135typedef void
136(*GNUNET_ATS_AllocationCallback) (void *cls,
137 struct GNUNET_ATS_Session *session,
138 struct GNUNET_BANDWIDTH_Value32NBO
139 bandwidth_out,
140 struct GNUNET_BANDWIDTH_Value32NBO
141 bandwidth_in);
142
143
144/**
145 * Signature of a function called by ATS suggesting transport to
146 * try connecting with a particular address.
147 *
148 * @param cls closure
149 * @param pid target peer
150 * @param address the address to try
151 */
152typedef void
153(*GNUNET_ATS_SuggestionCallback) (void *cls,
154 const struct GNUNET_PeerIdentity *pid,
155 const char *address);
156
157
158/**
159 * Initialize the ATS transport subsystem.
160 *
161 * @param cfg configuration to use
162 * @param alloc_cb notification to call whenever the allocation changed
163 * @param alloc_cb_cls closure for @a alloc_cb
164 * @param suggest_cb notification to call whenever the suggestation is made
165 * @param suggest_cb_cls closure for @a suggest_cb
166 * @return ats context
167 */
168struct GNUNET_ATS_TransportHandle *
169GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
170 GNUNET_ATS_AllocationCallback alloc_cb,
171 void *alloc_cb_cls,
172 GNUNET_ATS_SuggestionCallback suggest_cb,
173 void *suggest_cb_cls);
174
175
176/**
177 * Client is done with ATS transport, release resources.
178 *
179 * @param ath handle to release
180 */
181void
182GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath);
183
184
185/**
186 * Handle used within ATS to track an session.
187 */
188struct GNUNET_ATS_SessionRecord;
189
190
191/**
192 * We have a new session ATS should know. Sessiones have to be added with this
193 * function before they can be: updated, set in use and destroyed
194 *
195 * @param ath handle
196 * @param pid peer we connected to
197 * @param address the address (human readable version),
198 * @param session transport-internal handle for the session/queue, NULL if
199 * the session is inbound-only
200 * @param prop performance data for the session
201 * @return handle to the session representation inside ATS, NULL
202 * on error (i.e. ATS knows this exact session already, or
203 * session is invalid)
204 */
205struct GNUNET_ATS_SessionRecord *
206GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
207 const struct GNUNET_PeerIdentity *pid,
208 const char *address,
209 struct GNUNET_ATS_Session *session,
210 const struct GNUNET_ATS_Properties *prop);
211
212
213/**
214 * We have updated performance statistics for a given session. Based
215 * on the information provided, ATS may update bandwidth assignments.
216 *
217 * @param ar session record to update information for
218 * @param prop performance data for the session
219 */
220void
221GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
222 const struct GNUNET_ATS_Properties *prop);
223
224
225/**
226 * A session was destroyed, ATS should now schedule and
227 * allocate under the assumption that this @a ar is no
228 * longer in use.
229 *
230 * @param ar session record to drop
231 */
232void
233GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar);
234
235
236#endif
237
238/** @} */ /* end of group */
239
240/* end of file gnunet-service-transport_ats.h */
diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h
index 9130ff57e..00a7d6c5d 100644
--- a/src/include/gnunet_bandwidth_lib.h
+++ b/src/include/gnunet_bandwidth_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,6 +33,10 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif
39
32#ifndef GNUNET_BANDWIDTH_LIB_H 40#ifndef GNUNET_BANDWIDTH_LIB_H
33#define GNUNET_BANDWIDTH_LIB_H 41#define GNUNET_BANDWIDTH_LIB_H
34 42
@@ -39,7 +47,7 @@ extern "C" {
39#endif 47#endif
40#endif 48#endif
41 49
42#include "gnunet_common.h" 50
43#include "gnunet_time_lib.h" 51#include "gnunet_time_lib.h"
44 52
45GNUNET_NETWORK_STRUCT_BEGIN 53GNUNET_NETWORK_STRUCT_BEGIN
@@ -351,4 +359,6 @@ GNUNET_BANDWIDTH_tracker_update_quota (
351 359
352/** @} */ /* end of group */ 360/** @} */ /* end of group */
353 361
362/** @} */ /* end of group addition */
363
354/* end of gnunet_bandwidth_lib.h */ 364/* end of gnunet_bandwidth_lib.h */
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 142f1b088..73550db7e 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,9 +33,15 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#include "gnunet_common.h"
37#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
38#error "Only <gnunet_util_lib.h> can be included directly."
39#endif
40
32#ifndef GNUNET_BIO_LIB_H 41#ifndef GNUNET_BIO_LIB_H
33#define GNUNET_BIO_LIB_H 42#define GNUNET_BIO_LIB_H
34 43
44
35#include "gnunet_container_lib.h" 45#include "gnunet_container_lib.h"
36 46
37#ifdef __cplusplus 47#ifdef __cplusplus
@@ -79,9 +89,18 @@ GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
79 * @param emsg set to the error message 89 * @param emsg set to the error message
80 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
81 */ 91 */
82int 92enum GNUNET_GenericReturnValue
83GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); 93GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
84 94
95/**
96 * Set read error to handle
97 *
98 * @param h the handle
99 * @param emsg the message
100 */
101void
102GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg);
103
85 104
86/** 105/**
87 * Read some contents into a buffer. 106 * Read some contents into a buffer.
@@ -92,7 +111,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
92 * @param len the number of bytes to read 111 * @param len the number of bytes to read
93 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 112 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
94 */ 113 */
95int 114enum GNUNET_GenericReturnValue
96GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 115GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
97 const char *what, 116 const char *what,
98 void *result, 117 void *result,
@@ -109,26 +128,13 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
109 * @param max_length maximum allowed length for the string 128 * @param max_length maximum allowed length for the string
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
111 */ 130 */
112int 131enum GNUNET_GenericReturnValue
113GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 132GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
114 const char *what, 133 const char *what,
115 char **result, 134 char **result,
116 size_t max_length); 135 size_t max_length);
117 136
118 137
119/**
120 * Read a metadata container.
121 *
122 * @param h handle to an open file
123 * @param what describes what is being read (for error message creation)
124 * @param result the buffer to store a pointer to the (allocated) metadata
125 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
126 */
127int
128GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
129 const char *what,
130 struct GNUNET_CONTAINER_MetaData **result);
131
132 138
133/** 139/**
134 * Read a float. 140 * Read a float.
@@ -137,7 +143,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
137 * @param what describes what is being read (for error message creation) 143 * @param what describes what is being read (for error message creation)
138 * @param f address of float to read 144 * @param f address of float to read
139 */ 145 */
140int 146enum GNUNET_GenericReturnValue
141GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, 147GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
142 const char *what, 148 const char *what,
143 float *f); 149 float *f);
@@ -150,7 +156,7 @@ GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
150 * @param what describes what is being read (for error message creation) 156 * @param what describes what is being read (for error message creation)
151 * @param f address of double to read 157 * @param f address of double to read
152 */ 158 */
153int 159enum GNUNET_GenericReturnValue
154GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, 160GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
155 const char *what, 161 const char *what,
156 double *f); 162 double *f);
@@ -164,7 +170,7 @@ GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
164 * @param i where to store the data 170 * @param i where to store the data
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 171 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
166 */ 172 */
167int 173enum GNUNET_GenericReturnValue
168GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, 174GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
169 const char *what, 175 const char *what,
170 int32_t *i); 176 int32_t *i);
@@ -178,7 +184,7 @@ GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
178 * @param i where to store the data 184 * @param i where to store the data
179 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
180 */ 186 */
181int 187enum GNUNET_GenericReturnValue
182GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, 188GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
183 const char *what, 189 const char *what,
184 int64_t *i); 190 int64_t *i);
@@ -219,7 +225,7 @@ GNUNET_BIO_write_open_buffer (void);
219 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned 225 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
220 * and the file is closed 226 * and the file is closed
221 */ 227 */
222int 228enum GNUNET_GenericReturnValue
223GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); 229GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
224 230
225 231
@@ -235,7 +241,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
235 * @param size where to store the size of @e contents 241 * @param size where to store the size of @e contents
236 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 242 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
237 */ 243 */
238int 244enum GNUNET_GenericReturnValue
239GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 245GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
240 char **emsg, 246 char **emsg,
241 void **contents, 247 void **contents,
@@ -251,7 +257,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
251 * if the handle has an error message, the return value is #GNUNET_SYSERR 257 * if the handle has an error message, the return value is #GNUNET_SYSERR
252 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 258 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
253 */ 259 */
254int 260enum GNUNET_GenericReturnValue
255GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); 261GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
256 262
257 263
@@ -264,7 +270,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
264 * @param n number of bytes to write 270 * @param n number of bytes to write
265 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 271 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
266 */ 272 */
267int 273enum GNUNET_GenericReturnValue
268GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 274GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
269 const char *what, 275 const char *what,
270 const void *buffer, 276 const void *buffer,
@@ -279,25 +285,12 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
279 * @param s string to write (can be NULL) 285 * @param s string to write (can be NULL)
280 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 286 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 */ 287 */
282int 288enum GNUNET_GenericReturnValue
283GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 289GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
284 const char *what, 290 const char *what,
285 const char *s); 291 const char *s);
286 292
287 293
288/**
289 * Write a metadata container.
290 *
291 * @param h the IO handle to write to
292 * @param what what is being written (for error message creation)
293 * @param m metadata to write
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
295 */
296int
297GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
298 const char *what,
299 const struct GNUNET_CONTAINER_MetaData *m);
300
301 294
302/** 295/**
303 * Write a float. 296 * Write a float.
@@ -306,7 +299,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
306 * @param what what is being written (for error message creation) 299 * @param what what is being written (for error message creation)
307 * @param f float to write (must be a variable) 300 * @param f float to write (must be a variable)
308 */ 301 */
309int 302enum GNUNET_GenericReturnValue
310GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, 303GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
311 const char *what, 304 const char *what,
312 float f); 305 float f);
@@ -318,7 +311,7 @@ GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
318 * @param what what is being written (for error message creation) 311 * @param what what is being written (for error message creation)
319 * @param f double to write (must be a variable) 312 * @param f double to write (must be a variable)
320 */ 313 */
321int 314enum GNUNET_GenericReturnValue
322GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, 315GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
323 const char *what, 316 const char *what,
324 double f); 317 double f);
@@ -332,7 +325,7 @@ GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
332 * @param i 32-bit integer to write 325 * @param i 32-bit integer to write
333 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
334 */ 327 */
335int 328enum GNUNET_GenericReturnValue
336GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 329GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
337 const char *what, 330 const char *what,
338 int32_t i); 331 int32_t i);
@@ -346,7 +339,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
346 * @param i 64-bit integer to write 339 * @param i 64-bit integer to write
347 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 340 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
348 */ 341 */
349int 342enum GNUNET_GenericReturnValue
350GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 343GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
351 const char *what, 344 const char *what,
352 int64_t i); 345 int64_t i);
@@ -444,17 +437,6 @@ GNUNET_BIO_read_spec_string (const char *what,
444 size_t max_length); 437 size_t max_length);
445 438
446 439
447/**
448 * Create the specification to read a metadata container.
449 *
450 * @param what describes what is being read (for error message creation)
451 * @param result the buffer to store a pointer to the (allocated) metadata
452 * @return the read spec
453 */
454struct GNUNET_BIO_ReadSpec
455GNUNET_BIO_read_spec_meta_data (const char *what,
456 struct GNUNET_CONTAINER_MetaData **result);
457
458 440
459/** 441/**
460 * Create the specification to read an (u)int32_t. 442 * Create the specification to read an (u)int32_t.
@@ -508,7 +490,7 @@ GNUNET_BIO_read_spec_double (const char *what, double *f);
508 * the last element must be #GNUNET_BIO_read_spec_end 490 * the last element must be #GNUNET_BIO_read_spec_end
509 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 491 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
510 */ 492 */
511int 493enum GNUNET_GenericReturnValue
512GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, 494GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
513 struct GNUNET_BIO_ReadSpec *rs); 495 struct GNUNET_BIO_ReadSpec *rs);
514 496
@@ -601,18 +583,6 @@ GNUNET_BIO_write_spec_string (const char *what,
601 583
602 584
603/** 585/**
604 * Create the specification to write a metadata container.
605 *
606 * @param what what is being written (for error message creation)
607 * @param m metadata to write
608 * @return the write spec
609 */
610struct GNUNET_BIO_WriteSpec
611GNUNET_BIO_write_spec_meta_data (const char *what,
612 const struct GNUNET_CONTAINER_MetaData *m);
613
614
615/**
616 * Create the specification to write an (u)int32_t. 586 * Create the specification to write an (u)int32_t.
617 * 587 *
618 * @param what describes what is being written (for error message creation) 588 * @param what describes what is being written (for error message creation)
@@ -666,7 +636,7 @@ GNUNET_BIO_write_spec_double (const char *what, double *f);
666 * the last element must be #GNUNET_BIO_write_spec_end 636 * the last element must be #GNUNET_BIO_write_spec_end
667 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 637 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
668 */ 638 */
669int 639enum GNUNET_GenericReturnValue
670GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, 640GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
671 struct GNUNET_BIO_WriteSpec *ws); 641 struct GNUNET_BIO_WriteSpec *ws);
672 642
@@ -683,4 +653,6 @@ GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
683 653
684/** @} */ /* end of group bio */ 654/** @} */ /* end of group bio */
685 655
656/** @} */ /* end of group addition */
657
686/* end of gnunet_bio_lib.h */ 658/* end of gnunet_bio_lib.h */
diff --git a/src/include/gnunet_block_group_lib.h b/src/include/gnunet_block_group_lib.h
index 6cb601757..b1f59899e 100644
--- a/src/include/gnunet_block_group_lib.h
+++ b/src/include/gnunet_block_group_lib.h
@@ -31,6 +31,7 @@
31#ifndef GNUNET_BLOCK_GROUP_LIB_H 31#ifndef GNUNET_BLOCK_GROUP_LIB_H
32#define GNUNET_BLOCK_GROUP_LIB_H 32#define GNUNET_BLOCK_GROUP_LIB_H
33 33
34
34#include "gnunet_util_lib.h" 35#include "gnunet_util_lib.h"
35#include "gnunet_block_lib.h" 36#include "gnunet_block_lib.h"
36 37
@@ -68,7 +69,6 @@ GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count,
68 * @param bf_size size of the Bloom filter 69 * @param bf_size size of the Bloom filter
69 * @param bf_k K-value for the Bloom filter 70 * @param bf_k K-value for the Bloom filter
70 * @param type block type 71 * @param type block type
71 * @param nonce random value used to seed the group creation
72 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 72 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
73 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 73 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
74 * @return block group handle, NULL if block groups are not supported 74 * @return block group handle, NULL if block groups are not supported
@@ -79,7 +79,6 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
79 size_t bf_size, 79 size_t bf_size,
80 unsigned int bf_k, 80 unsigned int bf_k,
81 enum GNUNET_BLOCK_Type type, 81 enum GNUNET_BLOCK_Type type,
82 uint32_t nonce,
83 const void *raw_data, 82 const void *raw_data,
84 size_t raw_data_size); 83 size_t raw_data_size);
85 84
@@ -92,9 +91,9 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
92 * @param bg block group to use for testing 91 * @param bg block group to use for testing
93 * @param hc hash of element to evaluate 92 * @param hc hash of element to evaluate
94 * @return #GNUNET_YES if @a hc is (likely) a duplicate 93 * @return #GNUNET_YES if @a hc is (likely) a duplicate
95 * #GNUNET_NO if @a hc was definitively not in @bg (but now is) 94 * #GNUNET_NO if @a hc was definitively not in @a bg (but now is)
96 */ 95 */
97int 96enum GNUNET_GenericReturnValue
98GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, 97GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
99 const struct GNUNET_HashCode *hc); 98 const struct GNUNET_HashCode *hc);
100 99
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 73b51252e..fdccbab78 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,7 +34,10 @@
31#ifndef GNUNET_BLOCK_LIB_H 34#ifndef GNUNET_BLOCK_LIB_H
32#define GNUNET_BLOCK_LIB_H 35#define GNUNET_BLOCK_LIB_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
39#include "gnunet_dht_block_types.h"
40
35#ifdef __cplusplus 41#ifdef __cplusplus
36extern "C" 42extern "C"
37{ 43{
@@ -42,181 +48,36 @@ extern "C"
42 48
43 49
44/** 50/**
45 * Blocks in the datastore and the datacache must have a unique type.
46 */
47enum GNUNET_BLOCK_Type
48{
49 /**
50 * Any type of block, used as a wildcard when searching. Should
51 * never be attached to a specific block.
52 */
53 GNUNET_BLOCK_TYPE_ANY = 0,
54
55 /**
56 * Data block (leaf) in the CHK tree.
57 */
58 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
59
60 /**
61 * Inner block in the CHK tree.
62 */
63 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
64
65 /**
66 * Legacy type, no longer in use.
67 */
68 GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
69
70 /**
71 * Legacy type, no longer in use.
72 */
73 GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
74
75 /**
76 * Legacy type, no longer in use.
77 */
78 GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
79
80 /**
81 * Type of a block representing a block to be encoded on demand from disk.
82 * Should never appear on the network directly.
83 */
84 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
85
86 /**
87 * Type of a block that contains a HELLO for a peer (for
88 * DHT and CADET find-peer operations).
89 */
90 GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
91
92 /**
93 * Block for testing.
94 */
95 GNUNET_BLOCK_TYPE_TEST = 8,
96
97 /**
98 * Type of a block representing any type of search result
99 * (universal). Implemented in the context of #2564, replaces
100 * SBLOCKS, KBLOCKS and NBLOCKS.
101 */
102 GNUNET_BLOCK_TYPE_FS_UBLOCK = 9,
103
104 /**
105 * Block for storing DNS exit service advertisements.
106 */
107 GNUNET_BLOCK_TYPE_DNS = 10,
108
109 /**
110 * Block for storing record data
111 */
112 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
113
114 /**
115 * Block type for a revocation message by which a key is revoked.
116 */
117 GNUNET_BLOCK_TYPE_REVOCATION = 12,
118
119 /**
120 * Block to store a cadet regex state
121 */
122 GNUNET_BLOCK_TYPE_REGEX = 22,
123
124 /**
125 * Block to store a cadet regex accepting state
126 */
127 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23,
128
129 /**
130 * Block for testing set/consensus. If first byte of the block
131 * is non-zero, the block is considered invalid.
132 */
133 GNUNET_BLOCK_TYPE_SET_TEST = 24,
134
135 /**
136 * Block type for consensus elements.
137 * Contains either special marker elements or a nested block.
138 */
139 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25,
140
141 /**
142 * Block for testing set intersection. If first byte of the block
143 * is non-zero, the block is considered invalid.
144 */
145 GNUNET_BLOCK_TYPE_SETI_TEST = 24,
146
147 /**
148 * Block for testing set union. If first byte of the block
149 * is non-zero, the block is considered invalid.
150 */
151 GNUNET_BLOCK_TYPE_SETU_TEST = 24,
152
153};
154
155
156/**
157 * Flags that can be set to control the evaluation.
158 */
159enum GNUNET_BLOCK_EvaluationOptions
160{
161 /**
162 * Default behavior.
163 */
164 GNUNET_BLOCK_EO_NONE = 0,
165
166 /**
167 * The block is obtained from the local database, skip cryptographic
168 * checks.
169 */
170 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO = 1
171};
172
173
174/**
175 * Possible ways for how a block may relate to a query. 51 * Possible ways for how a block may relate to a query.
176 */ 52 */
177enum GNUNET_BLOCK_EvaluationResult 53enum GNUNET_BLOCK_ReplyEvaluationResult
178{ 54{
179 /**
180 * Valid result, and there may be more.
181 */
182 GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
183 55
184 /** 56 /**
185 * Last possible valid result. 57 * Specified block type not supported by any plugin.
186 */ 58 */
187 GNUNET_BLOCK_EVALUATION_OK_LAST = 1, 59 GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1,
188 60
189 /** 61 /**
190 * Valid result, but suppressed because it is a duplicate. 62 * Valid result, but suppressed because it is a duplicate.
191 */ 63 */
192 GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2, 64 GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0,
193
194 /**
195 * Block does not match query (invalid result)
196 */
197 GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
198 65
199 /** 66 /**
200 * Block does not match xquery (valid result, not relevant for the request) 67 * Block does not match xquery (valid result, not relevant for the request)
201 */ 68 */
202 GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT = 4, 69 GNUNET_BLOCK_REPLY_IRRELEVANT = 1,
203 70
204 /** 71 /**
205 * Query is valid, no reply given. 72 * Valid result, and there may be more.
206 */ 73 */
207 GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 10, 74 GNUNET_BLOCK_REPLY_OK_MORE = 2,
208 75
209 /** 76 /**
210 * Query format does not match block type (invalid query). For 77 * Last possible valid result.
211 * example, xquery not given or xquery_size not appropriate for
212 * type.
213 */ 78 */
214 GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 11, 79 GNUNET_BLOCK_REPLY_OK_LAST = 3
215 80
216 /**
217 * Specified block type not supported by this plugin.
218 */
219 GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 20
220}; 81};
221 82
222 83
@@ -271,7 +132,6 @@ struct GNUNET_BLOCK_Group;
271 * 132 *
272 * @param ctx block context in which the block group is created 133 * @param ctx block context in which the block group is created
273 * @param type type of the block for which we are creating the group 134 * @param type type of the block for which we are creating the group
274 * @param nonce random value used to seed the group creation
275 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 135 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
276 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 136 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
277 * @param ... type-specific additional data, can be empty 137 * @param ... type-specific additional data, can be empty
@@ -281,7 +141,6 @@ struct GNUNET_BLOCK_Group;
281struct GNUNET_BLOCK_Group * 141struct GNUNET_BLOCK_Group *
282GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, 142GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
283 enum GNUNET_BLOCK_Type type, 143 enum GNUNET_BLOCK_Type type,
284 uint32_t nonce,
285 const void *raw_data, 144 const void *raw_data,
286 size_t raw_data_size, 145 size_t raw_data_size,
287 ...); 146 ...);
@@ -291,15 +150,13 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
291 * Serialize state of a block group. 150 * Serialize state of a block group.
292 * 151 *
293 * @param bg group to serialize 152 * @param bg group to serialize
294 * @param[out] nonce set to the nonce of the @a bg
295 * @param[out] raw_data set to the serialized state 153 * @param[out] raw_data set to the serialized state
296 * @param[out] raw_data_size set to the number of bytes in @a raw_data 154 * @param[out] raw_data_size set to the number of bytes in @a raw_data
297 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not 155 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
298 * supported, #GNUNET_SYSERR on error 156 * supported, #GNUNET_SYSERR on error
299 */ 157 */
300int 158enum GNUNET_GenericReturnValue
301GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, 159GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
302 uint32_t *nonce,
303 void **raw_data, 160 void **raw_data,
304 size_t *raw_data_size); 161 size_t *raw_data_size);
305 162
@@ -314,16 +171,12 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
314 171
315 172
316/** 173/**
317 * Function called to validate a reply or a request. For 174 * Function called to validate if a reply is good for a
318 * request evaluation, simply pass "NULL" for the @a reply_block. 175 * particular query.
319 * Note that it is assumed that the reply has already been
320 * matched to the key (and signatures checked) as it would
321 * be done with the #GNUNET_BLOCK_get_key() function.
322 * 176 *
323 * @param ctx block contxt 177 * @param ctx block contxt
324 * @param type block type 178 * @param type block type
325 * @param group block group to use for evaluation 179 * @param[in,out] group block group to use for evaluation
326 * @param eo evaluation options to control evaluation
327 * @param query original query (hash) 180 * @param query original query (hash)
328 * @param xquery extrended query data (can be NULL, depending on type) 181 * @param xquery extrended query data (can be NULL, depending on type)
329 * @param xquery_size number of bytes in @a xquery 182 * @param xquery_size number of bytes in @a xquery
@@ -331,20 +184,57 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
331 * @param reply_block_size number of bytes in @a reply_block 184 * @param reply_block_size number of bytes in @a reply_block
332 * @return characterization of result 185 * @return characterization of result
333 */ 186 */
334enum GNUNET_BLOCK_EvaluationResult 187enum GNUNET_BLOCK_ReplyEvaluationResult
335GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, 188GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx,
336 enum GNUNET_BLOCK_Type type, 189 enum GNUNET_BLOCK_Type type,
337 struct GNUNET_BLOCK_Group *group, 190 struct GNUNET_BLOCK_Group *group,
338 enum GNUNET_BLOCK_EvaluationOptions eo, 191 const struct GNUNET_HashCode *query,
339 const struct GNUNET_HashCode *query, 192 const void *xquery,
340 const void *xquery, 193 size_t xquery_size,
341 size_t xquery_size, 194 const void *reply_block,
342 const void *reply_block, 195 size_t reply_block_size);
343 size_t reply_block_size);
344 196
345 197
346/** 198/**
347 * Function called to obtain the key for a block. 199 * Function called to validate a request.
200 *
201 * @param ctx block contxt
202 * @param type block type
203 * @param query original query (hash)
204 * @param xquery extrended query data (can be NULL, depending on type)
205 * @param xquery_size number of bytes in @a xquery
206 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not,
207 * #GNUNET_SYSERR if @a type is not supported
208 */
209enum GNUNET_GenericReturnValue
210GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx,
211 enum GNUNET_BLOCK_Type type,
212 const struct GNUNET_HashCode *query,
213 const void *xquery,
214 size_t xquery_size);
215
216
217/**
218 * Function called to validate a block.
219 *
220 * @param ctx block contxt
221 * @param type block type
222 * @param block payload to put
223 * @param block_size number of bytes in @a block
224 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not,
225 * #GNUNET_SYSERR if @a type is not supported
226 */
227enum GNUNET_GenericReturnValue
228GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
229 enum GNUNET_BLOCK_Type type,
230 const void *block,
231 size_t block_size);
232
233
234/**
235 * Function called to obtain the @a key for a @a block.
236 * If the @a block is malformed, the function should
237 * zero-out @a key and return #GNUNET_OK.
348 * 238 *
349 * @param ctx block context 239 * @param ctx block context
350 * @param type block type 240 * @param type block type
@@ -352,11 +242,10 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
352 * @param block_size number of bytes in @a block 242 * @param block_size number of bytes in @a block
353 * @param key set to the key (query) for the given block 243 * @param key set to the key (query) for the given block
354 * @return #GNUNET_YES on success, 244 * @return #GNUNET_YES on success,
355 * #GNUNET_NO if the block is malformed 245 * #GNUNET_NO if extracting a key from a block of this @a type does not work
356 * #GNUNET_SYSERR if type not supported 246 * #GNUNET_SYSERR if @a type not supported
357 * (or if extracting a key from a block of this type does not work)
358 */ 247 */
359int 248enum GNUNET_GenericReturnValue
360GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 249GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
361 enum GNUNET_BLOCK_Type type, 250 enum GNUNET_BLOCK_Type type,
362 const void *block, 251 const void *block,
@@ -375,7 +264,7 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
375 * @param seen_results_count number of entries in @a seen_results 264 * @param seen_results_count number of entries in @a seen_results
376 * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success 265 * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success
377 */ 266 */
378int 267enum GNUNET_GenericReturnValue
379GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, 268GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
380 const struct GNUNET_HashCode *seen_results, 269 const struct GNUNET_HashCode *seen_results,
381 unsigned int seen_results_count); 270 unsigned int seen_results_count);
@@ -383,7 +272,7 @@ GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
383 272
384/** 273/**
385 * Try merging two block groups. Afterwards, @a bg1 should remain 274 * Try merging two block groups. Afterwards, @a bg1 should remain
386 * valid and contain the rules from both @a bg1 and @bg2, and 275 * valid and contain the rules from both @a bg1 and @a bg2, and
387 * @a bg2 should be destroyed (as part of this call). The latter 276 * @a bg2 should be destroyed (as part of this call). The latter
388 * should happen even if merging is not supported. 277 * should happen even if merging is not supported.
389 * 278 *
@@ -393,7 +282,7 @@ GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
393 * #GNUNET_NO if merge failed due to different nonce 282 * #GNUNET_NO if merge failed due to different nonce
394 * #GNUNET_SYSERR if merging is not supported 283 * #GNUNET_SYSERR if merging is not supported
395 */ 284 */
396int 285enum GNUNET_GenericReturnValue
397GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, 286GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
398 struct GNUNET_BLOCK_Group *bg2); 287 struct GNUNET_BLOCK_Group *bg2);
399 288
@@ -410,4 +299,6 @@ GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
410 299
411/** @} */ /* end of group */ 300/** @} */ /* end of group */
412 301
302/** @} */ /* end of group addition */
303
413/* end of gnunet_block_lib.h */ 304/* end of gnunet_block_lib.h */
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h
index ee237ac03..16e93c780 100644
--- a/src/include/gnunet_block_plugin.h
+++ b/src/include/gnunet_block_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010,2013,2017 GNUnet e.V. 3 Copyright (C) 2010, 2013, 2017, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -35,6 +38,7 @@
35#ifndef PLUGIN_BLOCK_H 38#ifndef PLUGIN_BLOCK_H
36#define PLUGIN_BLOCK_H 39#define PLUGIN_BLOCK_H
37 40
41
38#include "gnunet_util_lib.h" 42#include "gnunet_util_lib.h"
39#include "gnunet_block_lib.h" 43#include "gnunet_block_lib.h"
40 44
@@ -48,10 +52,10 @@
48 * @param seen_results_count number of entries in @a seen_results 52 * @param seen_results_count number of entries in @a seen_results
49 */ 53 */
50typedef void 54typedef void
51(*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg, 55(*GNUNET_BLOCK_GroupMarkSeenFunction)(
52 const struct 56 struct GNUNET_BLOCK_Group *bg,
53 GNUNET_HashCode *seen_results, 57 const struct GNUNET_HashCode *seen_results,
54 unsigned int seen_results_count); 58 unsigned int seen_results_count);
55 59
56 60
57/** 61/**
@@ -63,7 +67,7 @@ typedef void
63 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus 67 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus
64 * we failed. 68 * we failed.
65 */ 69 */
66typedef int 70typedef enum GNUNET_GenericReturnValue
67(*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1, 71(*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1,
68 const struct GNUNET_BLOCK_Group *bg2); 72 const struct GNUNET_BLOCK_Group *bg2);
69 73
@@ -72,15 +76,13 @@ typedef int
72 * Serialize state of a block group. 76 * Serialize state of a block group.
73 * 77 *
74 * @param bg group to serialize 78 * @param bg group to serialize
75 * @param[out] nonce set to the nonce of the @a bg
76 * @param[out] raw_data set to the serialized state 79 * @param[out] raw_data set to the serialized state
77 * @param[out] raw_data_size set to the number of bytes in @a raw_data 80 * @param[out] raw_data_size set to the number of bytes in @a raw_data
78 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not 81 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
79 * supported, #GNUNET_SYSERR on error 82 * supported, #GNUNET_SYSERR on error
80 */ 83 */
81typedef int 84typedef enum GNUNET_GenericReturnValue
82(*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, 85(*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
83 uint32_t *nonce,
84 void **raw_data, 86 void **raw_data,
85 size_t *raw_data_size); 87 size_t *raw_data_size);
86 88
@@ -156,24 +158,54 @@ struct GNUNET_BLOCK_Group
156typedef struct GNUNET_BLOCK_Group * 158typedef struct GNUNET_BLOCK_Group *
157(*GNUNET_BLOCK_GroupCreateFunction)(void *cls, 159(*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
158 enum GNUNET_BLOCK_Type type, 160 enum GNUNET_BLOCK_Type type,
159 uint32_t nonce,
160 const void *raw_data, 161 const void *raw_data,
161 size_t raw_data_size, 162 size_t raw_data_size,
162 va_list va); 163 va_list va);
163 164
164 165
165/** 166/**
166 * Function called to validate a reply or a request. For 167 * Function called to validate a query.
167 * request evaluation, simply pass "NULL" for the @a reply_block. 168 *
168 * Note that it is assumed that the reply has already been 169 * @param cls closure
169 * matched to the key (and signatures checked) as it would 170 * @param type block type
170 * be done with the "get_key" function. 171 * @param query original query (hash)
172 * @param xquery extrended query data (can be NULL, depending on type)
173 * @param xquery_size number of bytes in @a xquery
174 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
175 */
176typedef enum GNUNET_GenericReturnValue
177(*GNUNET_BLOCK_QueryEvaluationFunction)(void *cls,
178 enum GNUNET_BLOCK_Type type,
179 const struct GNUNET_HashCode *query,
180 const void *xquery,
181 size_t xquery_size);
182
183
184/**
185 * Function called to validate a @a block for storage.
186 *
187 * @param cls closure
188 * @param type block type
189 * @param block block data to validate
190 * @param block_size number of bytes in @a block
191 * @return #GNUNET_OK if the @a block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if the @a type is not supported
192 */
193typedef enum GNUNET_GenericReturnValue
194(*GNUNET_BLOCK_BlockEvaluationFunction)(void *cls,
195 enum GNUNET_BLOCK_Type type,
196 const void *block,
197 size_t block_size);
198
199
200/**
201 * Function called to validate a reply to a request. Note that it is assumed
202 * that the reply has already been matched to the key (and signatures checked)
203 * as it would be done with the GetKeyFunction and the
204 * BlockEvaluationFunction.
171 * 205 *
172 * @param cls closure 206 * @param cls closure
173 * @param ctx block context
174 * @param type block type 207 * @param type block type
175 * @param group which block group to use for evaluation 208 * @param group which block group to use for evaluation
176 * @param eo evaluation options to control evaluation
177 * @param query original query (hash) 209 * @param query original query (hash)
178 * @param xquery extrended query data (can be NULL, depending on type) 210 * @param xquery extrended query data (can be NULL, depending on type)
179 * @param xquery_size number of bytes in @a xquery 211 * @param xquery_size number of bytes in @a xquery
@@ -181,38 +213,37 @@ typedef struct GNUNET_BLOCK_Group *
181 * @param reply_block_size number of bytes in @a reply_block 213 * @param reply_block_size number of bytes in @a reply_block
182 * @return characterization of result 214 * @return characterization of result
183 */ 215 */
184typedef enum GNUNET_BLOCK_EvaluationResult 216typedef enum GNUNET_BLOCK_ReplyEvaluationResult
185(*GNUNET_BLOCK_EvaluationFunction)(void *cls, 217(*GNUNET_BLOCK_ReplyEvaluationFunction)(void *cls,
186 struct GNUNET_BLOCK_Context *ctx, 218 enum GNUNET_BLOCK_Type type,
187 enum GNUNET_BLOCK_Type type, 219 struct GNUNET_BLOCK_Group *group,
188 struct GNUNET_BLOCK_Group *group, 220 const struct GNUNET_HashCode *query,
189 enum GNUNET_BLOCK_EvaluationOptions eo, 221 const void *xquery,
190 const struct GNUNET_HashCode *query, 222 size_t xquery_size,
191 const void *xquery, 223 const void *reply_block,
192 size_t xquery_size, 224 size_t reply_block_size);
193 const void *reply_block,
194 size_t reply_block_size);
195 225
196 226
197/** 227/**
198 * Function called to obtain the key for a block. 228 * Function called to obtain the @a key for a block.
229 * If the @a block is malformed, the function should
230 * zero-out @a key and return #GNUNET_OK.
199 * 231 *
200 * @param cls closure 232 * @param cls closure
201 * @param type block type 233 * @param type block type
202 * @param block block to get the key for 234 * @param block block to get the @a key for
203 * @param block_size number of bytes in @a block 235 * @param block_size number of bytes in @a block
204 * @param key set to the key (query) for the given block 236 * @param[out] key set to the key (query) for the given block
205 * @return #GNUNET_YES on success, 237 * @return #GNUNET_YES on success,
206 * #GNUNET_NO if the block is malformed 238 * #GNUNET_NO if extracting a key for this @a type does not work
207 * #GNUNET_SYSERR if type not supported 239 * #GNUNET_SYSERR if @a type not supported
208 * (or if extracting a key from a block of this type does not work)
209 */ 240 */
210typedef int 241typedef enum GNUNET_GenericReturnValue
211(*GNUNET_BLOCK_GetKeyFunction) (void *cls, 242(*GNUNET_BLOCK_GetKeyFunction)(void *cls,
212 enum GNUNET_BLOCK_Type type, 243 enum GNUNET_BLOCK_Type type,
213 const void *block, 244 const void *block,
214 size_t block_size, 245 size_t block_size,
215 struct GNUNET_HashCode *key); 246 struct GNUNET_HashCode *key);
216 247
217 248
218/** 249/**
@@ -232,12 +263,6 @@ struct GNUNET_BLOCK_PluginFunctions
232 const enum GNUNET_BLOCK_Type *types; 263 const enum GNUNET_BLOCK_Type *types;
233 264
234 /** 265 /**
235 * Main function of a block plugin. Allows us to check if a
236 * block matches a query.
237 */
238 GNUNET_BLOCK_EvaluationFunction evaluate;
239
240 /**
241 * Obtain the key for a given block (if possible). 266 * Obtain the key for a given block (if possible).
242 */ 267 */
243 GNUNET_BLOCK_GetKeyFunction get_key; 268 GNUNET_BLOCK_GetKeyFunction get_key;
@@ -247,8 +272,26 @@ struct GNUNET_BLOCK_PluginFunctions
247 * context (i.e. to detect duplicates). 272 * context (i.e. to detect duplicates).
248 */ 273 */
249 GNUNET_BLOCK_GroupCreateFunction create_group; 274 GNUNET_BLOCK_GroupCreateFunction create_group;
275
276 /**
277 * Check that a query is well-formed.
278 */
279 GNUNET_BLOCK_QueryEvaluationFunction check_query;
280
281 /**
282 * Check that a block is well-formed.
283 */
284 GNUNET_BLOCK_BlockEvaluationFunction check_block;
285
286 /**
287 * Check that a reply block matches a query.
288 */
289 GNUNET_BLOCK_ReplyEvaluationFunction check_reply;
290
250}; 291};
251 292
252#endif 293#endif
253 294
254/** @} */ /* end of group */ 295/** @} */ /* end of group */
296
297/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h
index 7239eccfb..e65981206 100644
--- a/src/include/gnunet_buffer_lib.h
+++ b/src/include/gnunet_buffer_lib.h
@@ -19,11 +19,19 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * Common buffer management functions. 26 * Common buffer management functions.
23 * 27 *
24 * @author Florian Dold 28 * @author Florian Dold
25 */ 29 */
26 30
31#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
32#error "Only <gnunet_util_lib.h> can be included directly."
33#endif
34
27#ifndef GNUNET_BUFFER_LIB_H 35#ifndef GNUNET_BUFFER_LIB_H
28#define GNUNET_BUFFER_LIB_H 36#define GNUNET_BUFFER_LIB_H
29 37
@@ -203,3 +211,5 @@ GNUNET_buffer_clear (struct GNUNET_Buffer *buf);
203 211
204 212
205#endif 213#endif
214
215/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index f08c1572a..ab53d2bd8 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * @author Bart Polot 25 * @author Bart Polot
23 * 26 *
@@ -42,8 +45,8 @@ extern "C" {
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_transport_service.h"
47 50
48/** 51/**
49 * Version number of GNUnet-cadet API. 52 * Version number of GNUnet-cadet API.
@@ -309,7 +312,9 @@ union GNUNET_CADET_ChannelInfo
309 * Get information about a channel. 312 * Get information about a channel.
310 * 313 *
311 * @param channel Channel handle. 314 * @param channel Channel handle.
315 * @param option Query (GNUNET_CADET_OPTION_*)
312 * @param ... dependent on option, currently not used 316 * @param ... dependent on option, currently not used
317 *
313 * @return Union with an answer to the query. 318 * @return Union with an answer to the query.
314 */ 319 */
315const union GNUNET_CADET_ChannelInfo * 320const union GNUNET_CADET_ChannelInfo *
@@ -627,4 +632,6 @@ GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt);
627 632
628/** @} */ /* end of group */ 633/** @} */ /* end of group */
629 634
635/** @} */ /* end of group addition */
636
630/* end of gnunet_cadet_service.h */ 637/* end of gnunet_cadet_service.h */
diff --git a/src/include/gnunet_child_management_lib.h b/src/include/gnunet_child_management_lib.h
index a35b37865..ab0ab93eb 100644
--- a/src/include/gnunet_child_management_lib.h
+++ b/src/include/gnunet_child_management_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @file include/gnunet_child_management_lib.h 30 * @file include/gnunet_child_management_lib.h
23 * @brief GNUnet child management api 31 * @brief GNUnet child management api
24 * @author Christian Grothoff 32 * @author Christian Grothoff
@@ -41,8 +49,7 @@ struct GNUNET_ChildWaitHandle;
41 * @param cls handle for the callback 49 * @param cls handle for the callback
42 * @param type type of the process 50 * @param type type of the process
43 * @param exit_code status code of the process 51 * @param exit_code status code of the process
44 * 52 */
45*/
46typedef void 53typedef void
47(*GNUNET_ChildCompletedCallback)(void *cls, 54(*GNUNET_ChildCompletedCallback)(void *cls,
48 enum GNUNET_OS_ProcessStatusType type, 55 enum GNUNET_OS_ProcessStatusType type,
@@ -70,3 +77,5 @@ void
70GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh); 77GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh);
71 78
72#endif 79#endif
80
81/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index 2ecd38b04..ab4c7d088 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -19,6 +19,13 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -32,6 +39,10 @@
32 * @{ 39 * @{
33 */ 40 */
34 41
42#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
43#error "Only <gnunet_util_lib.h> can be included directly."
44#endif
45
35#ifndef GNUNET_CLIENT_LIB_H 46#ifndef GNUNET_CLIENT_LIB_H
36#define GNUNET_CLIENT_LIB_H 47#define GNUNET_CLIENT_LIB_H
37 48
@@ -43,6 +54,7 @@ extern "C"
43#endif 54#endif
44#endif 55#endif
45 56
57
46#include "gnunet_mq_lib.h" 58#include "gnunet_mq_lib.h"
47 59
48 60
@@ -67,7 +79,8 @@ GNUNET_CLIENT_test (const struct GNUNET_CONFIGURATION_Handle *cfg,
67 * Create a message queue to connect to a GNUnet service. 79 * Create a message queue to connect to a GNUnet service.
68 * If handlers are specified, receive messages from the connection. 80 * If handlers are specified, receive messages from the connection.
69 * 81 *
70 * @param connection the client connection 82 * @param cfg our configuration
83 * @param service_name name of the service to connect to
71 * @param handlers handlers for receiving messages, can be NULL 84 * @param handlers handlers for receiving messages, can be NULL
72 * @param error_handler error handler 85 * @param error_handler error handler
73 * @param error_handler_cls closure for the @a error_handler 86 * @param error_handler_cls closure for the @a error_handler
@@ -93,4 +106,8 @@ GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
93 106
94/** @} */ /* end of group client */ 107/** @} */ /* end of group client */
95 108
109/** @} */ /* end of group addition */
110
111/** @} */ /* end of group addition */
112
96/* end of gnunet_client_lib.h */ 113/* end of gnunet_client_lib.h */
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 4472d3ee8..9fa3de37d 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2021 GNUnet e.V. 3 Copyright (C) 2006-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @file include/gnunet_common.h 26 * @file include/gnunet_common.h
23 * @brief commonly used definitions; globals in this file 27 * @brief commonly used definitions; globals in this file
24 * are exempt from the rule that the module name ("common") 28 * are exempt from the rule that the module name ("common")
@@ -36,28 +40,38 @@
36#ifndef GNUNET_COMMON_H 40#ifndef GNUNET_COMMON_H
37#define GNUNET_COMMON_H 41#define GNUNET_COMMON_H
38 42
43#include "gnunet_config.h"
44
45#include <stdbool.h>
39#include <stdlib.h> 46#include <stdlib.h>
40#if HAVE_SYS_SOCKET_H
41#include <sys/socket.h> 47#include <sys/socket.h>
42#endif 48#include <sys/un.h>
43#if HAVE_NETINET_IN_H
44#include <netinet/in.h> 49#include <netinet/in.h>
45#endif 50#include <arpa/inet.h>
46#ifdef HAVE_STDINT_H
47#include <stdint.h> 51#include <stdint.h>
48#endif
49#ifdef HAVE_STDARG_H
50#include <stdarg.h> 52#include <stdarg.h>
51#endif
52#ifdef HAVE_SYS_TYPES_H
53#include <sys/types.h> 53#include <sys/types.h>
54#endif
55#ifdef HAVE_SYS_SOCKET_H
56#include <sys/socket.h>
57#endif
58 54
55#if defined(__FreeBSD__)
59 56
60#ifdef HAVE_BYTESWAP_H 57#include <sys/endian.h>
58#define bswap_32(x) bswap32(x)
59#define bswap_64(x) bswap64(x)
60
61#elif defined(__OpenBSD__)
62
63#define bswap_32(x) swap32(x)
64#define bswap_64(x) swap64(x)
65
66#elif defined(__NetBSD__)
67
68#include <machine/bswap.h>
69#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
70#define bswap_32(x) bswap32(x)
71#define bswap_64(x) bswap64(x)
72#endif
73
74#elif defined(__linux__) || defined(GNU)
61#include <byteswap.h> 75#include <byteswap.h>
62#endif 76#endif
63 77
@@ -132,12 +146,6 @@ enum GNUNET_GenericReturnValue
132#endif 146#endif
133 147
134/** 148/**
135 * wrap va_arg for enums
136 */
137#define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
138
139
140/**
141 * @ingroup logging 149 * @ingroup logging
142 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source 150 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source
143 * tree where gnunet_config.h is unavailable 151 * tree where gnunet_config.h is unavailable
@@ -150,8 +158,7 @@ enum GNUNET_GenericReturnValue
150 * Endian operations 158 * Endian operations
151 */ 159 */
152 160
153#if __BYTE_ORDER == __LITTLE_ENDIAN 161#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
154#ifdef HAVE_BYTESWAP_H
155#define BYTE_SWAP_16(x) bswap_16 (x) 162#define BYTE_SWAP_16(x) bswap_16 (x)
156#define BYTE_SWAP_32(x) bswap_32 (x) 163#define BYTE_SWAP_32(x) bswap_32 (x)
157#define BYTE_SWAP_64(x) bswap_64 (x) 164#define BYTE_SWAP_64(x) bswap_64 (x)
@@ -170,6 +177,7 @@ enum GNUNET_GenericReturnValue
170 56)) 177 56))
171#endif 178#endif
172 179
180#if __BYTE_ORDER == __LITTLE_ENDIAN
173#define GNUNET_htobe16(x) BYTE_SWAP_16 (x) 181#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
174#define GNUNET_htole16(x) (x) 182#define GNUNET_htole16(x) (x)
175#define GNUNET_be16toh(x) BYTE_SWAP_16 (x) 183#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
@@ -623,6 +631,31 @@ GNUNET_abort_ (void) GNUNET_NORETURN;
623 631
624 632
625/** 633/**
634 * Convert a buffer to an 8-character string
635 * representative of the contents. This is used
636 * for logging binary data when debugging.
637 *
638 * @param buf buffer to log
639 * @param buf_size number of bytes in @a buf
640 * @return text representation of buf, valid until next
641 * call to this function
642 */
643const char *
644GNUNET_b2s (const void *buf,
645 size_t buf_size);
646
647
648/**
649 * Convert a fixed-sized object to a string using
650 * #GNUNET_b2s().
651 *
652 * @param obj address of object to convert
653 * @return string representing the binary obj buffer
654 */
655#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
656
657
658/**
626 * @ingroup logging 659 * @ingroup logging
627 * Ignore the next @a n calls to the log function. 660 * Ignore the next @a n calls to the log function.
628 * 661 *
@@ -642,7 +675,7 @@ GNUNET_log_skip (int n, int check_reset);
642 * @param logfile change logging to logfile (use NULL to keep stderr) 675 * @param logfile change logging to logfile (use NULL to keep stderr)
643 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened 676 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened
644 */ 677 */
645int 678enum GNUNET_GenericReturnValue
646GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); 679GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
647 680
648 681
@@ -955,7 +988,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
955 } while (0) 988 } while (0)
956 989
957 990
958#if HAVE_STATIC_ASSERT 991#ifdef _Static_assert
959/** 992/**
960 * Assertion to be checked (if supported by C compiler) at 993 * Assertion to be checked (if supported by C compiler) at
961 * compile time, otherwise checked at runtime and resulting 994 * compile time, otherwise checked at runtime and resulting
@@ -1240,7 +1273,7 @@ GNUNET_is_zero_ (const void *a,
1240 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1273 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise
1241 */ 1274 */
1242#define GNUNET_is_zero(a) \ 1275#define GNUNET_is_zero(a) \
1243 GNUNET_is_zero_ (a, sizeof (*a)) 1276 GNUNET_is_zero_ ((a), sizeof (*(a)))
1244 1277
1245 1278
1246/** 1279/**
@@ -1481,7 +1514,7 @@ GNUNET_is_zero_ (const void *a,
1481 * will be updated to reflect the new address. The TYPE of 1514 * will be updated to reflect the new address. The TYPE of
1482 * arr is important since size is the number of elements and 1515 * arr is important since size is the number of elements and
1483 * not the size in bytes 1516 * not the size in bytes
1484 * @param len the number of elements in the existing vector (number 1517 * @param len2 the number of elements in the existing vector (number
1485 * of elements to copy over), will be updated with the new 1518 * of elements to copy over), will be updated with the new
1486 * array size 1519 * array size
1487 1520
@@ -1714,7 +1747,7 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg);
1714 * Set the async scope for the current thread. 1747 * Set the async scope for the current thread.
1715 * 1748 *
1716 * @param aid the async scope identifier 1749 * @param aid the async scope identifier
1717 * @param old_scope[out] location to save the old scope 1750 * @param[out] old_scope location to save the old scope
1718 */ 1751 */
1719void 1752void
1720GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, 1753GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid,
@@ -1836,3 +1869,5 @@ enum GNUNET_SCHEDULER_Priority
1836#endif 1869#endif
1837 1870
1838#endif /* GNUNET_COMMON_H */ 1871#endif /* GNUNET_COMMON_H */
1872
1873/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_config.h.in b/src/include/gnunet_config.h.in
new file mode 100644
index 000000000..5dff759ae
--- /dev/null
+++ b/src/include/gnunet_config.h.in
@@ -0,0 +1,58 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21#ifndef GNUNET_CONFIG_H
22#define GNUNET_CONFIG_H
23
24/**
25 * @author Martin Schanzenbach
26 *
27 * @file
28 * Convenience header including public (!) information on the
29 * installed GNUnet configuration.
30 *
31 */
32
33/* The version of GNUnet */
34#define GNUNET_VERSION "@gnunet_version@"
35
36/* Major version */
37#define GNUNET_MAJOR_VERSION @gnunet_major_version@
38
39/* Micro version */
40#define GNUNET_MINOR_VERSION @gnunet_minor_version@
41
42/* Mico version */
43#define GNUNET_MICRO_VERSION @gnunet_micro_version@
44
45/* Set to 1 is this is an experimental build */
46#define GNUNET_EXPERIMENTAL @enable_experimental@
47
48/* Set to 1 if GnuTLS has DANE support */
49#define GNUNET_CURL_GNUTLS @curl_gnutls@
50
51/**
52 * Set to 1 if file-sharing meta data parsing is built with
53 * libextractor, which means that callers to the API must use also use
54 * libextractor.
55 */
56#define GNUNET_FS_EXTRACTOR_ENABLED @extractor@
57
58#endif
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 570546b68..3b9be5849 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -31,6 +35,7 @@
31#ifndef GNUNET_CONFIGURATION_LIB_H 35#ifndef GNUNET_CONFIGURATION_LIB_H
32#define GNUNET_CONFIGURATION_LIB_H 36#define GNUNET_CONFIGURATION_LIB_H
33 37
38
34#include "gnunet_time_lib.h" 39#include "gnunet_time_lib.h"
35 40
36#ifdef __cplusplus 41#ifdef __cplusplus
@@ -160,8 +165,8 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
160 * present. This memory should be freed by the caller 165 * present. This memory should be freed by the caller
161 */ 166 */
162char * 167char *
163GNUNET_CONFIGURATION_serialize_diagnostics (const struct 168GNUNET_CONFIGURATION_serialize_diagnostics (
164 GNUNET_CONFIGURATION_Handle *cfg); 169 const struct GNUNET_CONFIGURATION_Handle *cfg);
165 170
166/** 171/**
167 * De-serializes configuration 172 * De-serializes configuration
@@ -170,7 +175,7 @@ GNUNET_CONFIGURATION_serialize_diagnostics (const struct
170 * @param mem the memory block of serialized configuration 175 * @param mem the memory block of serialized configuration
171 * @param size the size of the memory block 176 * @param size the size of the memory block
172 * @param source_filename source filename, will be used 177 * @param source_filename source filename, will be used
173 * to resolve relative @INLINE@ statements 178 * to resolve relative \@INLINE\@ statements
174 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 179 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
175 */ 180 */
176enum GNUNET_GenericReturnValue 181enum GNUNET_GenericReturnValue
@@ -266,8 +271,8 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
266 * @param cfg configuration handle 271 * @param cfg configuration handle
267 */ 272 */
268void 273void
269GNUNET_CONFIGURATION_enable_diagnostics (struct 274GNUNET_CONFIGURATION_enable_diagnostics (
270 GNUNET_CONFIGURATION_Handle *cfg); 275 struct GNUNET_CONFIGURATION_Handle *cfg);
271 276
272 277
273/** 278/**
@@ -292,8 +297,8 @@ typedef void
292 * @param section name of the section 297 * @param section name of the section
293 */ 298 */
294typedef void 299typedef void
295(*GNUNET_CONFIGURATION_Section_Iterator) (void *cls, 300(*GNUNET_CONFIGURATION_SectionIterator) (void *cls,
296 const char *section); 301 const char *section);
297 302
298 303
299/** 304/**
@@ -317,11 +322,10 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
317 * @param iter_cls closure for @a iter 322 * @param iter_cls closure for @a iter
318 */ 323 */
319void 324void
320GNUNET_CONFIGURATION_iterate_sections (const struct 325GNUNET_CONFIGURATION_iterate_sections (
321 GNUNET_CONFIGURATION_Handle *cfg, 326 const struct GNUNET_CONFIGURATION_Handle *cfg,
322 GNUNET_CONFIGURATION_Section_Iterator 327 GNUNET_CONFIGURATION_SectionIterator iter,
323 iter, 328 void *iter_cls);
324 void *iter_cls);
325 329
326 330
327/** 331/**
@@ -345,11 +349,11 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
345 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 349 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
346 */ 350 */
347enum GNUNET_GenericReturnValue 351enum GNUNET_GenericReturnValue
348GNUNET_CONFIGURATION_get_value_number (const struct 352GNUNET_CONFIGURATION_get_value_number (
349 GNUNET_CONFIGURATION_Handle *cfg, 353 const struct GNUNET_CONFIGURATION_Handle *cfg,
350 const char *section, 354 const char *section,
351 const char *option, 355 const char *option,
352 unsigned long long *number); 356 unsigned long long *number);
353 357
354 358
355/** 359/**
@@ -362,11 +366,11 @@ GNUNET_CONFIGURATION_get_value_number (const struct
362 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 366 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
363 */ 367 */
364enum GNUNET_GenericReturnValue 368enum GNUNET_GenericReturnValue
365GNUNET_CONFIGURATION_get_value_float (const struct 369GNUNET_CONFIGURATION_get_value_float (
366 GNUNET_CONFIGURATION_Handle *cfg, 370 const struct GNUNET_CONFIGURATION_Handle *cfg,
367 const char *section, 371 const char *section,
368 const char *option, 372 const char *option,
369 float *number); 373 float *number);
370 374
371 375
372/** 376/**
@@ -379,11 +383,11 @@ GNUNET_CONFIGURATION_get_value_float (const struct
379 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 383 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
380 */ 384 */
381enum GNUNET_GenericReturnValue 385enum GNUNET_GenericReturnValue
382GNUNET_CONFIGURATION_get_value_time (const struct 386GNUNET_CONFIGURATION_get_value_time (
383 GNUNET_CONFIGURATION_Handle *cfg, 387 const struct GNUNET_CONFIGURATION_Handle *cfg,
384 const char *section, 388 const char *section,
385 const char *option, 389 const char *option,
386 struct GNUNET_TIME_Relative *time); 390 struct GNUNET_TIME_Relative *time);
387 391
388 392
389/** 393/**
@@ -396,11 +400,11 @@ GNUNET_CONFIGURATION_get_value_time (const struct
396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 400 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
397 */ 401 */
398enum GNUNET_GenericReturnValue 402enum GNUNET_GenericReturnValue
399GNUNET_CONFIGURATION_get_value_size (const struct 403GNUNET_CONFIGURATION_get_value_size (
400 GNUNET_CONFIGURATION_Handle *cfg, 404 const struct GNUNET_CONFIGURATION_Handle *cfg,
401 const char *section, 405 const char *section,
402 const char *option, 406 const char *option,
403 unsigned long long *size); 407 unsigned long long *size);
404 408
405 409
406/** 410/**
@@ -447,11 +451,11 @@ GNUNET_CONFIGURATION_get_value_string (
447 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 451 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
448 */ 452 */
449enum GNUNET_GenericReturnValue 453enum GNUNET_GenericReturnValue
450GNUNET_CONFIGURATION_get_value_filename (const struct 454GNUNET_CONFIGURATION_get_value_filename (
451 GNUNET_CONFIGURATION_Handle *cfg, 455 const struct GNUNET_CONFIGURATION_Handle *cfg,
452 const char *section, 456 const char *section,
453 const char *option, 457 const char *option,
454 char **value); 458 char **value);
455 459
456 460
457/** 461/**
@@ -465,12 +469,13 @@ GNUNET_CONFIGURATION_get_value_filename (const struct
465 * @return number of filenames iterated over, -1 on error 469 * @return number of filenames iterated over, -1 on error
466 */ 470 */
467int 471int
468GNUNET_CONFIGURATION_iterate_value_filenames (const struct 472GNUNET_CONFIGURATION_iterate_value_filenames (
469 GNUNET_CONFIGURATION_Handle *cfg, 473 const struct GNUNET_CONFIGURATION_Handle *cfg,
470 const char *section, 474 const char *section,
471 const char *option, 475 const char *option,
472 GNUNET_FileNameCallback cb, 476 GNUNET_FileNameCallback cb,
473 void *cb_cls); 477 void *cb_cls);
478
474 479
475/** 480/**
476 * Iterate over values of a section in the configuration. 481 * Iterate over values of a section in the configuration.
@@ -481,11 +486,12 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct
481 * @param iter_cls closure for @a iter 486 * @param iter_cls closure for @a iter
482 */ 487 */
483void 488void
484GNUNET_CONFIGURATION_iterate_section_values (const struct 489GNUNET_CONFIGURATION_iterate_section_values (
485 GNUNET_CONFIGURATION_Handle *cfg, 490 const struct GNUNET_CONFIGURATION_Handle *cfg,
486 const char *section, 491 const char *section,
487 GNUNET_CONFIGURATION_Iterator iter, 492 GNUNET_CONFIGURATION_Iterator iter,
488 void *iter_cls); 493 void *iter_cls);
494
489 495
490/** 496/**
491 * Get a configuration value that should be in a set of 497 * Get a configuration value that should be in a set of
@@ -500,12 +506,13 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
500 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 506 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
501 */ 507 */
502enum GNUNET_GenericReturnValue 508enum GNUNET_GenericReturnValue
503GNUNET_CONFIGURATION_get_value_choice (const struct 509GNUNET_CONFIGURATION_get_value_choice (
504 GNUNET_CONFIGURATION_Handle *cfg, 510 const struct GNUNET_CONFIGURATION_Handle *cfg,
505 const char *section, 511 const char *section,
506 const char *option, 512 const char *option,
507 const char *const *choices, 513 const char *const *choices,
508 const char **value); 514 const char **value);
515
509 516
510/** 517/**
511 * Get a configuration value that should be in a set of 518 * Get a configuration value that should be in a set of
@@ -517,10 +524,10 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
517 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR 524 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
518 */ 525 */
519enum GNUNET_GenericReturnValue 526enum GNUNET_GenericReturnValue
520GNUNET_CONFIGURATION_get_value_yesno (const struct 527GNUNET_CONFIGURATION_get_value_yesno (
521 GNUNET_CONFIGURATION_Handle *cfg, 528 const struct GNUNET_CONFIGURATION_Handle *cfg,
522 const char *section, 529 const char *section,
523 const char *option); 530 const char *option);
524 531
525 532
526/** 533/**
@@ -607,11 +614,11 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
607 * #GNUNET_SYSERR if the filename is not in the list 614 * #GNUNET_SYSERR if the filename is not in the list
608 */ 615 */
609enum GNUNET_GenericReturnValue 616enum GNUNET_GenericReturnValue
610GNUNET_CONFIGURATION_remove_value_filename (struct 617GNUNET_CONFIGURATION_remove_value_filename (
611 GNUNET_CONFIGURATION_Handle *cfg, 618 struct GNUNET_CONFIGURATION_Handle *cfg,
612 const char *section, 619 const char *section,
613 const char *option, 620 const char *option,
614 const char *value); 621 const char *value);
615 622
616 623
617/** 624/**
@@ -626,11 +633,11 @@ GNUNET_CONFIGURATION_remove_value_filename (struct
626 * #GNUNET_SYSERR if the filename already in the list 633 * #GNUNET_SYSERR if the filename already in the list
627 */ 634 */
628enum GNUNET_GenericReturnValue 635enum GNUNET_GenericReturnValue
629GNUNET_CONFIGURATION_append_value_filename (struct 636GNUNET_CONFIGURATION_append_value_filename (
630 GNUNET_CONFIGURATION_Handle *cfg, 637 struct GNUNET_CONFIGURATION_Handle *cfg,
631 const char *section, 638 const char *section,
632 const char *option, 639 const char *option,
633 const char *value); 640 const char *value);
634 641
635 642
636/** 643/**
@@ -793,3 +800,5 @@ GNUNET_CONFIGURATION_config_tool_run (
793#endif 800#endif
794 801
795/** @} */ /* end of group configuration */ 802/** @} */ /* end of group configuration */
803
804/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_consensus_service.h b/src/include/gnunet_consensus_service.h
index 9387aa095..47a928d9c 100644
--- a/src/include/gnunet_consensus_service.h
+++ b/src/include/gnunet_consensus_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Sets
23 * @{
24 *
22 * @author Florian Dold 25 * @author Florian Dold
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 48#include "gnunet_time_lib.h"
45#include "gnunet_configuration_lib.h" 49#include "gnunet_configuration_lib.h"
@@ -78,8 +82,8 @@ struct GNUNET_CONSENSUS_Handle;
78 * Create a consensus session. The set being reconciled is initially 82 * Create a consensus session. The set being reconciled is initially
79 * empty. 83 * empty.
80 * 84 *
81 * @param cfg 85 * @param cfg configuration to use for connecting to the consensus service
82 * @param num_peers 86 * @param num_peers number of peers in the peers array
83 * @param peers array of peers participating in this consensus session 87 * @param peers array of peers participating in this consensus session
84 * Inclusion of the local peer is optional. 88 * Inclusion of the local peer is optional.
85 * @param session_id session identifier 89 * @param session_id session identifier
@@ -180,3 +184,5 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
180#endif 184#endif
181 185
182/** @} */ /* end of group */ 186/** @} */ /* end of group */
187
188/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 3eb80595c..8f36f1c61 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -19,35 +19,57 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * @author Nils Durner 27 * @author Nils Durner
24 * 28 *
25 * @file 29 * @file
26 * Container classes for GNUnet 30 * Container classes for GNUnet
27 * 31 *
28 * @defgroup hashmap Container library: MultiHashMap 32 * @addtogroup container
33 * Common data structures in GNUnet programs
34 * @{
35 *
36 * @defgroup hashmap MultiHashMap
29 * Hash map with multiple values per key. 37 * Hash map with multiple values per key.
30 * 38 *
31 * @see [Documentation](https://gnunet.org/util_multihashmap) 39 * @see [Documentation](https://gnunet.org/util_multihashmap)
32 * 40 *
33 * @defgroup heap Container library: Heap 41 * @defgroup heap Heap
34 * Min- or max-heap with arbitrary element removal 42 * Min- or max-heap with arbitrary element removal
35 * 43 *
36 * @defgroup bloomfilter Container library: Bloom filter 44 * @defgroup bloomfilter Bloom filter
37 * Probabilistic set tests 45 * Probabilistic set tests
38 * 46 *
39 * @defgroup dll Container library: Doubly-linked list 47 * @defgroup dll Doubly-linked list
40 * 48 *
41 * @see [Documentation](https://gnunet.org/mdll-api) 49 * @see [Documentation](https://gnunet.org/mdll-api)
42 * 50 *
43 * @defgroup metadata Container library: Metadata 51 *
44 * GNU libextractor key-value pairs 52 * @}
45 */ 53 */
46 54
55#include "gnunet_common.h"
56#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
57#error "Only <gnunet_util_lib.h> can be included directly."
58#endif
59
47#ifndef GNUNET_CONTAINER_LIB_H 60#ifndef GNUNET_CONTAINER_LIB_H
48#define GNUNET_CONTAINER_LIB_H 61#define GNUNET_CONTAINER_LIB_H
49 62
63#ifdef __cplusplus
64extern "C" {
65#if 0 /* keep Emacsens' auto-indent happy */
66}
67#endif
68#endif
69
70
50/* add error and config prototypes */ 71/* add error and config prototypes */
72
51#include "gnunet_crypto_lib.h" 73#include "gnunet_crypto_lib.h"
52 74
53 75
@@ -87,114 +109,6 @@ char *
87GNUNET_decompress (const char *input, size_t input_size, size_t output_size); 109GNUNET_decompress (const char *input, size_t input_size, size_t output_size);
88 110
89 111
90#if HAVE_EXTRACTOR_H
91
92#include <extractor.h>
93
94#else
95
96/* definitions from extractor.h we need for the build */
97
98/**
99 * Enumeration defining various sources of keywords. See also
100 * http://dublincore.org/documents/1998/09/dces/
101 */
102enum EXTRACTOR_MetaType
103{
104 EXTRACTOR_METATYPE_RESERVED = 0,
105 EXTRACTOR_METATYPE_MIMETYPE = 1,
106 EXTRACTOR_METATYPE_FILENAME = 2,
107 EXTRACTOR_METATYPE_COMMENT = 3,
108 EXTRACTOR_METATYPE_TITLE = 4,
109 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
110 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
111 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
112 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
113 EXTRACTOR_METATYPE_URL = 29,
114 EXTRACTOR_METATYPE_URI = 30,
115 EXTRACTOR_METATYPE_ISRC = 31,
116 EXTRACTOR_METATYPE_UNKNOWN = 45,
117 EXTRACTOR_METATYPE_DESCRIPTION = 46,
118 EXTRACTOR_METATYPE_KEYWORDS = 49,
119 EXTRACTOR_METATYPE_SUBJECT = 52,
120 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
121 EXTRACTOR_METATYPE_THUMBNAIL = 114,
122 EXTRACTOR_METATYPE_ALBUM = 129,
123 EXTRACTOR_METATYPE_ARTIST = 130,
124 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
125 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
126 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
127};
128
129/**
130 * Format in which the extracted meta data is presented.
131 */
132enum EXTRACTOR_MetaFormat
133{
134 /**
135 * Format is unknown.
136 */
137 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
138
139 /**
140 * 0-terminated, UTF-8 encoded string. "data_len"
141 * is strlen(data)+1.
142 */
143 EXTRACTOR_METAFORMAT_UTF8 = 1,
144
145 /**
146 * Some kind of binary format, see given Mime type.
147 */
148 EXTRACTOR_METAFORMAT_BINARY = 2,
149
150 /**
151 * 0-terminated string. The specific encoding is unknown.
152 * "data_len" is strlen (data)+1.
153 */
154 EXTRACTOR_METAFORMAT_C_STRING = 3
155};
156
157
158/**
159 * Type of a function that libextractor calls for each
160 * meta data item found.
161 *
162 * @param cls closure (user-defined)
163 * @param plugin_name name of the plugin that produced this value;
164 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
165 * used in the main libextractor library and yielding
166 * meta data).
167 * @param type libextractor-type describing the meta data
168 * @param format basic format information about @a data
169 * @param data_mime_type mime-type of @a data (not of the original file);
170 * can be NULL (if mime-type is not known)
171 * @param data actual meta-data found
172 * @param data_len number of bytes in @a data
173 * @return 0 to continue extracting, 1 to abort
174 */
175typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
176 const char *plugin_name,
177 enum EXTRACTOR_MetaType type,
178 enum EXTRACTOR_MetaFormat format,
179 const char *data_mime_type,
180 const char *data,
181 size_t data_len);
182
183#endif
184
185#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
186/* hack for LE < 0.6.3 */
187#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
188#endif
189
190#ifdef __cplusplus
191extern "C" {
192#if 0 /* keep Emacsens' auto-indent happy */
193}
194#endif
195#endif
196
197
198/* ******************* bloomfilter ***************** */ 112/* ******************* bloomfilter ***************** */
199 113
200/** 114/**
@@ -264,7 +178,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data,
264 * @param size the size of the given @a data array 178 * @param size the size of the given @a data array
265 * @return #GNUNET_SYSERR if the data array of the wrong size 179 * @return #GNUNET_SYSERR if the data array of the wrong size
266 */ 180 */
267int 181enum GNUNET_GenericReturnValue
268GNUNET_CONTAINER_bloomfilter_get_raw_data ( 182GNUNET_CONTAINER_bloomfilter_get_raw_data (
269 const struct GNUNET_CONTAINER_BloomFilter *bf, 183 const struct GNUNET_CONTAINER_BloomFilter *bf,
270 char *data, 184 char *data,
@@ -277,9 +191,9 @@ GNUNET_CONTAINER_bloomfilter_get_raw_data (
277 * 191 *
278 * @param e the element 192 * @param e the element
279 * @param bf the filter 193 * @param bf the filter
280 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not 194 * @return true if the element is in the filter, false if not
281 */ 195 */
282int 196bool
283GNUNET_CONTAINER_bloomfilter_test ( 197GNUNET_CONTAINER_bloomfilter_test (
284 const struct GNUNET_CONTAINER_BloomFilter *bf, 198 const struct GNUNET_CONTAINER_BloomFilter *bf,
285 const struct GNUNET_HashCode *e); 199 const struct GNUNET_HashCode *e);
@@ -378,7 +292,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
378 * @param size size of @a data 292 * @param size size of @a data
379 * @return #GNUNET_OK on success 293 * @return #GNUNET_OK on success
380 */ 294 */
381int 295enum GNUNET_GenericReturnValue
382GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 296GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
383 const char *data, 297 const char *data,
384 size_t size); 298 size_t size);
@@ -394,7 +308,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
394 * @param to_or the bloomfilter to or-in 308 * @param to_or the bloomfilter to or-in
395 * @return #GNUNET_OK on success 309 * @return #GNUNET_OK on success
396 */ 310 */
397int 311enum GNUNET_GenericReturnValue
398GNUNET_CONTAINER_bloomfilter_or2 ( 312GNUNET_CONTAINER_bloomfilter_or2 (
399 struct GNUNET_CONTAINER_BloomFilter *bf, 313 struct GNUNET_CONTAINER_BloomFilter *bf,
400 const struct GNUNET_CONTAINER_BloomFilter *to_or); 314 const struct GNUNET_CONTAINER_BloomFilter *to_or);
@@ -420,285 +334,6 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
420 unsigned int k); 334 unsigned int k);
421 335
422 336
423/* ****************** metadata ******************* */
424
425/**
426 * @ingroup metadata
427 * Meta data to associate with a file, directory or namespace.
428 */
429struct GNUNET_CONTAINER_MetaData;
430
431
432/**
433 * @ingroup metadata
434 * Create a fresh meta data container.
435 *
436 * @return empty meta-data container
437 */
438struct GNUNET_CONTAINER_MetaData *
439GNUNET_CONTAINER_meta_data_create (void);
440
441
442/**
443 * @ingroup metadata
444 * Duplicate a MetaData token.
445 *
446 * @param md what to duplicate
447 * @return duplicate meta-data container
448 */
449struct GNUNET_CONTAINER_MetaData *
450GNUNET_CONTAINER_meta_data_duplicate (
451 const struct GNUNET_CONTAINER_MetaData *md);
452
453
454/**
455 * @ingroup metadata
456 * Free meta data.
457 *
458 * @param md what to free
459 */
460void
461GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
462
463
464/**
465 * @ingroup metadata
466 * Test if two MDs are equal. We consider them equal if
467 * the meta types, formats and content match (we do not
468 * include the mime types and plugins names in this
469 * consideration).
470 *
471 * @param md1 first value to check
472 * @param md2 other value to check
473 * @return #GNUNET_YES if they are equal
474 */
475int
476GNUNET_CONTAINER_meta_data_test_equal (
477 const struct GNUNET_CONTAINER_MetaData *md1,
478 const struct GNUNET_CONTAINER_MetaData *md2);
479
480
481/**
482 * @ingroup metadata
483 * Extend metadata.
484 *
485 * @param md metadata to extend
486 * @param plugin_name name of the plugin that produced this value;
487 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
488 * used in the main libextractor library and yielding
489 * meta data).
490 * @param type libextractor-type describing the meta data
491 * @param format basic format information about data
492 * @param data_mime_type mime-type of data (not of the original file);
493 * can be NULL (if mime-type is not known)
494 * @param data actual meta-data found
495 * @param data_size number of bytes in data
496 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
497 * data_mime_type and plugin_name are not considered for "exists" checks
498 */
499int
500GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
501 const char *plugin_name,
502 enum EXTRACTOR_MetaType type,
503 enum EXTRACTOR_MetaFormat format,
504 const char *data_mime_type,
505 const char *data,
506 size_t data_size);
507
508
509/**
510 * @ingroup metadata
511 * Extend metadata. Merges the meta data from the second argument
512 * into the first, discarding duplicate key-value pairs.
513 *
514 * @param md metadata to extend
515 * @param in metadata to merge
516 */
517void
518GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
519 const struct GNUNET_CONTAINER_MetaData *in);
520
521
522/**
523 * @ingroup metadata
524 * Remove an item.
525 *
526 * @param md metadata to manipulate
527 * @param type type of the item to remove
528 * @param data specific value to remove, NULL to remove all
529 * entries of the given type
530 * @param data_size number of bytes in data
531 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
532 */
533int
534GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
535 enum EXTRACTOR_MetaType type,
536 const char *data,
537 size_t data_size);
538
539
540/**
541 * @ingroup metadata
542 * Remove all items in the container.
543 *
544 * @param md metadata to manipulate
545 */
546void
547GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
548
549
550/**
551 * @ingroup metadata
552 * Add the current time as the publication date
553 * to the meta-data.
554 *
555 * @param md metadata to modify
556 */
557void
558GNUNET_CONTAINER_meta_data_add_publication_date (
559 struct GNUNET_CONTAINER_MetaData *md);
560
561
562/**
563 * @ingroup metadata
564 * Iterate over MD entries.
565 *
566 * @param md metadata to inspect
567 * @param iter function to call on each entry, return 0 to continue to iterate
568 * and 1 to abort iteration in this function (GNU libextractor API!)
569 * @param iter_cls closure for @a iter
570 * @return number of entries
571 */
572int
573GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
574 EXTRACTOR_MetaDataProcessor iter,
575 void *iter_cls);
576
577
578/**
579 * @ingroup metadata
580 * Get the first MD entry of the given type. Caller
581 * is responsible for freeing the return value.
582 * Also, only meta data items that are strings (0-terminated)
583 * are returned by this function.
584 *
585 * @param md metadata to inspect
586 * @param type type to look for
587 * @return NULL if no entry was found
588 */
589char *
590GNUNET_CONTAINER_meta_data_get_by_type (
591 const struct GNUNET_CONTAINER_MetaData *md,
592 enum EXTRACTOR_MetaType type);
593
594
595/**
596 * @ingroup metadata
597 * Get the first matching MD entry of the given types. Caller is
598 * responsible for freeing the return value. Also, only meta data
599 * items that are strings (0-terminated) are returned by this
600 * function.
601 *
602 * @param md metadata to inspect
603 * @param ... -1-terminated list of types
604 * @return NULL if we do not have any such entry,
605 * otherwise client is responsible for freeing the value!
606 */
607char *
608GNUNET_CONTAINER_meta_data_get_first_by_types (
609 const struct GNUNET_CONTAINER_MetaData *md,
610 ...);
611
612/**
613 * @ingroup metadata
614 * Get a thumbnail from the meta-data (if present). Only matches meta
615 * data with mime type "image" and binary format.
616 *
617 * @param md metadata to inspect
618 * @param thumb will be set to the thumbnail data. Must be
619 * freed by the caller!
620 * @return number of bytes in thumbnail, 0 if not available
621 */
622size_t
623GNUNET_CONTAINER_meta_data_get_thumbnail (
624 const struct GNUNET_CONTAINER_MetaData *md,
625 unsigned char **thumb);
626
627
628/**
629 * @ingroup metadata
630 * Options for metadata serialization.
631 */
632enum GNUNET_CONTAINER_MetaDataSerializationOptions
633{
634 /**
635 * @ingroup metadata
636 * Serialize all of the data.
637 */
638 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
639
640 /**
641 * @ingroup metadata
642 * If not enough space is available, it is acceptable
643 * to only serialize some of the metadata.
644 */
645 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
646
647 /**
648 * @ingroup metadata
649 * Speed is of the essence, do not allow compression.
650 */
651 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
652};
653
654
655/**
656 * @ingroup metadata
657 * Serialize meta-data to target.
658 *
659 * @param md metadata to serialize
660 * @param target where to write the serialized metadata;
661 * *target can be NULL, in which case memory is allocated
662 * @param max maximum number of bytes available
663 * @param opt is it ok to just write SOME of the
664 * meta-data to match the size constraint,
665 * possibly discarding some data?
666 * @return number of bytes written on success,
667 * -1 on error (typically: not enough
668 * space)
669 */
670ssize_t
671GNUNET_CONTAINER_meta_data_serialize (
672 const struct GNUNET_CONTAINER_MetaData *md,
673 char **target,
674 size_t max,
675 enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
676
677
678/**
679 * @ingroup metadata
680 * Get the size of the full meta-data in serialized form.
681 *
682 * @param md metadata to inspect
683 * @return number of bytes needed for serialization, -1 on error
684 */
685ssize_t
686GNUNET_CONTAINER_meta_data_get_serialized_size (
687 const struct GNUNET_CONTAINER_MetaData *md);
688
689
690/**
691 * @ingroup metadata
692 * Deserialize meta-data. Initializes md.
693 *
694 * @param input serialized meta-data.
695 * @param size number of bytes available
696 * @return MD on success, NULL on error (e.g.
697 * bad format)
698 */
699struct GNUNET_CONTAINER_MetaData *
700GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
701
702 337
703/* ******************************* HashMap **************************** */ 338/* ******************************* HashMap **************************** */
704 339
@@ -766,7 +401,8 @@ enum GNUNET_CONTAINER_MultiHashMapOption
766 * iterate, 401 * iterate,
767 * #GNUNET_NO if not. 402 * #GNUNET_NO if not.
768 */ 403 */
769typedef int (*GNUNET_CONTAINER_MulitHashMapIteratorCallback) ( 404typedef enum GNUNET_GenericReturnValue
405(*GNUNET_CONTAINER_MultiHashMapIteratorCallback)(
770 void *cls, 406 void *cls,
771 const struct GNUNET_HashCode *key, 407 const struct GNUNET_HashCode *key,
772 void *value); 408 void *value);
@@ -834,7 +470,7 @@ GNUNET_CONTAINER_multihashmap_get (
834 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 470 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
835 * is not in the map 471 * is not in the map
836 */ 472 */
837int 473enum GNUNET_GenericReturnValue
838GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, 474GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
839 const struct GNUNET_HashCode *key, 475 const struct GNUNET_HashCode *key,
840 const void *value); 476 const void *value);
@@ -876,7 +512,7 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map);
876 * @return #GNUNET_YES if such a value exists, 512 * @return #GNUNET_YES if such a value exists,
877 * #GNUNET_NO if not 513 * #GNUNET_NO if not
878 */ 514 */
879int 515enum GNUNET_GenericReturnValue
880GNUNET_CONTAINER_multihashmap_contains ( 516GNUNET_CONTAINER_multihashmap_contains (
881 const struct GNUNET_CONTAINER_MultiHashMap *map, 517 const struct GNUNET_CONTAINER_MultiHashMap *map,
882 const struct GNUNET_HashCode *key); 518 const struct GNUNET_HashCode *key);
@@ -893,7 +529,7 @@ GNUNET_CONTAINER_multihashmap_contains (
893 * @return #GNUNET_YES if such a value exists, 529 * @return #GNUNET_YES if such a value exists,
894 * #GNUNET_NO if not 530 * #GNUNET_NO if not
895 */ 531 */
896int 532enum GNUNET_GenericReturnValue
897GNUNET_CONTAINER_multihashmap_contains_value ( 533GNUNET_CONTAINER_multihashmap_contains_value (
898 const struct GNUNET_CONTAINER_MultiHashMap *map, 534 const struct GNUNET_CONTAINER_MultiHashMap *map,
899 const struct GNUNET_HashCode *key, 535 const struct GNUNET_HashCode *key,
@@ -913,7 +549,7 @@ GNUNET_CONTAINER_multihashmap_contains_value (
913 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 549 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
914 * value already exists 550 * value already exists
915 */ 551 */
916int 552enum GNUNET_GenericReturnValue
917GNUNET_CONTAINER_multihashmap_put ( 553GNUNET_CONTAINER_multihashmap_put (
918 struct GNUNET_CONTAINER_MultiHashMap *map, 554 struct GNUNET_CONTAINER_MultiHashMap *map,
919 const struct GNUNET_HashCode *key, 555 const struct GNUNET_HashCode *key,
@@ -945,7 +581,7 @@ GNUNET_CONTAINER_multihashmap_size (
945int 581int
946GNUNET_CONTAINER_multihashmap_iterate ( 582GNUNET_CONTAINER_multihashmap_iterate (
947 struct GNUNET_CONTAINER_MultiHashMap *map, 583 struct GNUNET_CONTAINER_MultiHashMap *map,
948 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 584 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
949 void *it_cls); 585 void *it_cls);
950 586
951 587
@@ -982,7 +618,7 @@ GNUNET_CONTAINER_multihashmap_iterator_create (
982 * @return #GNUNET_YES we returned an element, 618 * @return #GNUNET_YES we returned an element,
983 * #GNUNET_NO if we are out of elements 619 * #GNUNET_NO if we are out of elements
984 */ 620 */
985int 621enum GNUNET_GenericReturnValue
986GNUNET_CONTAINER_multihashmap_iterator_next ( 622GNUNET_CONTAINER_multihashmap_iterator_next (
987 struct GNUNET_CONTAINER_MultiHashMapIterator *iter, 623 struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
988 struct GNUNET_HashCode *key, 624 struct GNUNET_HashCode *key,
@@ -1011,11 +647,11 @@ GNUNET_CONTAINER_multihashmap_iterator_destroy (
1011 * @return the number of key value pairs processed, 647 * @return the number of key value pairs processed,
1012 * #GNUNET_SYSERR if it aborted iteration 648 * #GNUNET_SYSERR if it aborted iteration
1013 */ 649 */
1014int 650enum GNUNET_GenericReturnValue
1015GNUNET_CONTAINER_multihashmap_get_multiple ( 651GNUNET_CONTAINER_multihashmap_get_multiple (
1016 struct GNUNET_CONTAINER_MultiHashMap *map, 652 struct GNUNET_CONTAINER_MultiHashMap *map,
1017 const struct GNUNET_HashCode *key, 653 const struct GNUNET_HashCode *key,
1018 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 654 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
1019 void *it_cls); 655 void *it_cls);
1020 656
1021 657
@@ -1033,7 +669,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (
1033unsigned int 669unsigned int
1034GNUNET_CONTAINER_multihashmap_get_random ( 670GNUNET_CONTAINER_multihashmap_get_random (
1035 const struct GNUNET_CONTAINER_MultiHashMap *map, 671 const struct GNUNET_CONTAINER_MultiHashMap *map,
1036 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 672 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
1037 void *it_cls); 673 void *it_cls);
1038 674
1039 675
@@ -1050,7 +686,8 @@ GNUNET_CONTAINER_multihashmap_get_random (
1050 * iterate, 686 * iterate,
1051 * #GNUNET_NO if not. 687 * #GNUNET_NO if not.
1052 */ 688 */
1053typedef int (*GNUNET_CONTAINER_PeerMapIterator) ( 689typedef enum GNUNET_GenericReturnValue
690(*GNUNET_CONTAINER_PeerMapIterator)(
1054 void *cls, 691 void *cls,
1055 const struct GNUNET_PeerIdentity *key, 692 const struct GNUNET_PeerIdentity *key,
1056 void *value); 693 void *value);
@@ -1123,7 +760,7 @@ GNUNET_CONTAINER_multipeermap_get (
1123 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 760 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1124 * is not in the map 761 * is not in the map
1125 */ 762 */
1126int 763enum GNUNET_GenericReturnValue
1127GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, 764GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
1128 const struct GNUNET_PeerIdentity *key, 765 const struct GNUNET_PeerIdentity *key,
1129 const void *value); 766 const void *value);
@@ -1153,7 +790,7 @@ GNUNET_CONTAINER_multipeermap_remove_all (
1153 * @return #GNUNET_YES if such a value exists, 790 * @return #GNUNET_YES if such a value exists,
1154 * #GNUNET_NO if not 791 * #GNUNET_NO if not
1155 */ 792 */
1156int 793enum GNUNET_GenericReturnValue
1157GNUNET_CONTAINER_multipeermap_contains ( 794GNUNET_CONTAINER_multipeermap_contains (
1158 const struct GNUNET_CONTAINER_MultiPeerMap *map, 795 const struct GNUNET_CONTAINER_MultiPeerMap *map,
1159 const struct GNUNET_PeerIdentity *key); 796 const struct GNUNET_PeerIdentity *key);
@@ -1170,7 +807,7 @@ GNUNET_CONTAINER_multipeermap_contains (
1170 * @return #GNUNET_YES if such a value exists, 807 * @return #GNUNET_YES if such a value exists,
1171 * #GNUNET_NO if not 808 * #GNUNET_NO if not
1172 */ 809 */
1173int 810enum GNUNET_GenericReturnValue
1174GNUNET_CONTAINER_multipeermap_contains_value ( 811GNUNET_CONTAINER_multipeermap_contains_value (
1175 const struct GNUNET_CONTAINER_MultiPeerMap *map, 812 const struct GNUNET_CONTAINER_MultiPeerMap *map,
1176 const struct GNUNET_PeerIdentity *key, 813 const struct GNUNET_PeerIdentity *key,
@@ -1250,9 +887,12 @@ GNUNET_CONTAINER_multipeermap_iterator_create (
1250 * @ingroup hashmap 887 * @ingroup hashmap
1251 * Retrieve the next element from the hash map at the iterator's 888 * Retrieve the next element from the hash map at the iterator's
1252 * position. If there are no elements left, #GNUNET_NO is returned, 889 * position. If there are no elements left, #GNUNET_NO is returned,
1253 * and @a key and @a value are not modified. This operation is only 890 * and @a key and @a value are not modified.
1254 * allowed if no elements have been removed from the multihashmap 891 *
1255 * since the creation of @a iter, and the map has not been destroyed. 892 * This operation is only allowed if no elements have been removed
893 * from the multihashmap since the creation of @a iter, and the map
894 * has not been destroyed.
895 *
1256 * Adding elements may result in repeating or skipping elements. 896 * Adding elements may result in repeating or skipping elements.
1257 * 897 *
1258 * @param iter the iterator to get the next element from 898 * @param iter the iterator to get the next element from
@@ -1261,7 +901,7 @@ GNUNET_CONTAINER_multipeermap_iterator_create (
1261 * @return #GNUNET_YES we returned an element, 901 * @return #GNUNET_YES we returned an element,
1262 * #GNUNET_NO if we are out of elements 902 * #GNUNET_NO if we are out of elements
1263 */ 903 */
1264int 904enum GNUNET_GenericReturnValue
1265GNUNET_CONTAINER_multipeermap_iterator_next ( 905GNUNET_CONTAINER_multipeermap_iterator_next (
1266 struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, 906 struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
1267 struct GNUNET_PeerIdentity *key, 907 struct GNUNET_PeerIdentity *key,
@@ -1329,7 +969,8 @@ GNUNET_CONTAINER_multipeermap_get_random (
1329 * iterate, 969 * iterate,
1330 * #GNUNET_NO if not. 970 * #GNUNET_NO if not.
1331 */ 971 */
1332typedef int (*GNUNET_CONTAINER_ShortmapIterator) ( 972typedef enum GNUNET_GenericReturnValue
973(*GNUNET_CONTAINER_ShortmapIterator)(
1333 void *cls, 974 void *cls,
1334 const struct GNUNET_ShortHashCode *key, 975 const struct GNUNET_ShortHashCode *key,
1335 void *value); 976 void *value);
@@ -1470,7 +1111,7 @@ GNUNET_CONTAINER_multishortmap_contains_value (
1470 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1111 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1471 * value already exists 1112 * value already exists
1472 */ 1113 */
1473int 1114enum GNUNET_GenericReturnValue
1474GNUNET_CONTAINER_multishortmap_put ( 1115GNUNET_CONTAINER_multishortmap_put (
1475 struct GNUNET_CONTAINER_MultiShortmap *map, 1116 struct GNUNET_CONTAINER_MultiShortmap *map,
1476 const struct GNUNET_ShortHashCode *key, 1117 const struct GNUNET_ShortHashCode *key,
@@ -1543,7 +1184,7 @@ GNUNET_CONTAINER_multishortmap_iterator_create (
1543 * @return #GNUNET_YES we returned an element, 1184 * @return #GNUNET_YES we returned an element,
1544 * #GNUNET_NO if we are out of elements 1185 * #GNUNET_NO if we are out of elements
1545 */ 1186 */
1546int 1187enum GNUNET_GenericReturnValue
1547GNUNET_CONTAINER_multishortmap_iterator_next ( 1188GNUNET_CONTAINER_multishortmap_iterator_next (
1548 struct GNUNET_CONTAINER_MultiShortmapIterator *iter, 1189 struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
1549 struct GNUNET_ShortHashCode *key, 1190 struct GNUNET_ShortHashCode *key,
@@ -1612,7 +1253,8 @@ GNUNET_CONTAINER_multishortmap_get_random (
1612 * iterate, 1253 * iterate,
1613 * #GNUNET_NO if not. 1254 * #GNUNET_NO if not.
1614 */ 1255 */
1615typedef int (*GNUNET_CONTAINER_MultiUuidmapIteratorCallback) ( 1256typedef enum GNUNET_GenericReturnValue
1257(*GNUNET_CONTAINER_MultiUuidmapIteratorCallback)(
1616 void *cls, 1258 void *cls,
1617 const struct GNUNET_Uuid *key, 1259 const struct GNUNET_Uuid *key,
1618 void *value); 1260 void *value);
@@ -1685,7 +1327,7 @@ GNUNET_CONTAINER_multiuuidmap_get (
1685 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 1327 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1686 * is not in the map 1328 * is not in the map
1687 */ 1329 */
1688int 1330enum GNUNET_GenericReturnValue
1689GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, 1331GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map,
1690 const struct GNUNET_Uuid *key, 1332 const struct GNUNET_Uuid *key,
1691 const void *value); 1333 const void *value);
@@ -1715,7 +1357,7 @@ GNUNET_CONTAINER_multiuuidmap_remove_all (
1715 * @return #GNUNET_YES if such a value exists, 1357 * @return #GNUNET_YES if such a value exists,
1716 * #GNUNET_NO if not 1358 * #GNUNET_NO if not
1717 */ 1359 */
1718int 1360enum GNUNET_GenericReturnValue
1719GNUNET_CONTAINER_multiuuidmap_contains ( 1361GNUNET_CONTAINER_multiuuidmap_contains (
1720 const struct GNUNET_CONTAINER_MultiUuidmap *map, 1362 const struct GNUNET_CONTAINER_MultiUuidmap *map,
1721 const struct GNUNET_Uuid *key); 1363 const struct GNUNET_Uuid *key);
@@ -1732,7 +1374,7 @@ GNUNET_CONTAINER_multiuuidmap_contains (
1732 * @return #GNUNET_YES if such a value exists, 1374 * @return #GNUNET_YES if such a value exists,
1733 * #GNUNET_NO if not 1375 * #GNUNET_NO if not
1734 */ 1376 */
1735int 1377enum GNUNET_GenericReturnValue
1736GNUNET_CONTAINER_multiuuidmap_contains_value ( 1378GNUNET_CONTAINER_multiuuidmap_contains_value (
1737 const struct GNUNET_CONTAINER_MultiUuidmap *map, 1379 const struct GNUNET_CONTAINER_MultiUuidmap *map,
1738 const struct GNUNET_Uuid *key, 1380 const struct GNUNET_Uuid *key,
@@ -1752,7 +1394,7 @@ GNUNET_CONTAINER_multiuuidmap_contains_value (
1752 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1394 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1753 * value already exists 1395 * value already exists
1754 */ 1396 */
1755int 1397enum GNUNET_GenericReturnValue
1756GNUNET_CONTAINER_multiuuidmap_put ( 1398GNUNET_CONTAINER_multiuuidmap_put (
1757 struct GNUNET_CONTAINER_MultiUuidmap *map, 1399 struct GNUNET_CONTAINER_MultiUuidmap *map,
1758 const struct GNUNET_Uuid *key, 1400 const struct GNUNET_Uuid *key,
@@ -1782,7 +1424,7 @@ GNUNET_CONTAINER_multiuuidmap_size (
1782 * @return the number of key value pairs processed, 1424 * @return the number of key value pairs processed,
1783 * #GNUNET_SYSERR if it aborted iteration 1425 * #GNUNET_SYSERR if it aborted iteration
1784 */ 1426 */
1785int 1427enum GNUNET_GenericReturnValue
1786GNUNET_CONTAINER_multiuuidmap_iterate ( 1428GNUNET_CONTAINER_multiuuidmap_iterate (
1787 struct GNUNET_CONTAINER_MultiUuidmap *map, 1429 struct GNUNET_CONTAINER_MultiUuidmap *map,
1788 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, 1430 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
@@ -1825,7 +1467,7 @@ GNUNET_CONTAINER_multiuuidmap_iterator_create (
1825 * @return #GNUNET_YES we returned an element, 1467 * @return #GNUNET_YES we returned an element,
1826 * #GNUNET_NO if we are out of elements 1468 * #GNUNET_NO if we are out of elements
1827 */ 1469 */
1828int 1470enum GNUNET_GenericReturnValue
1829GNUNET_CONTAINER_multiuuidmap_iterator_next ( 1471GNUNET_CONTAINER_multiuuidmap_iterator_next (
1830 struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, 1472 struct GNUNET_CONTAINER_MultiUuidmapIterator *iter,
1831 struct GNUNET_Uuid *key, 1473 struct GNUNET_Uuid *key,
@@ -1908,9 +1550,11 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1908 * iterate, 1550 * iterate,
1909 * #GNUNET_NO if not. 1551 * #GNUNET_NO if not.
1910 */ 1552 */
1911typedef int (*GNUNET_CONTAINER_MulitHashMapIterator32Callback) (void *cls, 1553typedef enum GNUNET_GenericReturnValue
1912 uint32_t key, 1554(*GNUNET_CONTAINER_MultiHashMapIterator32Callback)(
1913 void *value); 1555 void *cls,
1556 uint32_t key,
1557 void *value);
1914 1558
1915 1559
1916/** 1560/**
@@ -1978,7 +1622,7 @@ GNUNET_CONTAINER_multihashmap32_get (
1978int 1622int
1979GNUNET_CONTAINER_multihashmap32_iterate ( 1623GNUNET_CONTAINER_multihashmap32_iterate (
1980 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1624 struct GNUNET_CONTAINER_MultiHashMap32 *map,
1981 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1625 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
1982 void *it_cls); 1626 void *it_cls);
1983 1627
1984 1628
@@ -1994,7 +1638,7 @@ GNUNET_CONTAINER_multihashmap32_iterate (
1994 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 1638 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1995 * is not in the map 1639 * is not in the map
1996 */ 1640 */
1997int 1641enum GNUNET_GenericReturnValue
1998GNUNET_CONTAINER_multihashmap32_remove ( 1642GNUNET_CONTAINER_multihashmap32_remove (
1999 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1643 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2000 uint32_t key, 1644 uint32_t key,
@@ -2026,7 +1670,7 @@ GNUNET_CONTAINER_multihashmap32_remove_all (
2026 * @return #GNUNET_YES if such a value exists, 1670 * @return #GNUNET_YES if such a value exists,
2027 * #GNUNET_NO if not 1671 * #GNUNET_NO if not
2028 */ 1672 */
2029int 1673enum GNUNET_GenericReturnValue
2030GNUNET_CONTAINER_multihashmap32_contains ( 1674GNUNET_CONTAINER_multihashmap32_contains (
2031 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 1675 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
2032 uint32_t key); 1676 uint32_t key);
@@ -2043,7 +1687,7 @@ GNUNET_CONTAINER_multihashmap32_contains (
2043 * @return #GNUNET_YES if such a value exists, 1687 * @return #GNUNET_YES if such a value exists,
2044 * #GNUNET_NO if not 1688 * #GNUNET_NO if not
2045 */ 1689 */
2046int 1690enum GNUNET_GenericReturnValue
2047GNUNET_CONTAINER_multihashmap32_contains_value ( 1691GNUNET_CONTAINER_multihashmap32_contains_value (
2048 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 1692 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
2049 uint32_t key, 1693 uint32_t key,
@@ -2063,7 +1707,7 @@ GNUNET_CONTAINER_multihashmap32_contains_value (
2063 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1707 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
2064 * value already exists 1708 * value already exists
2065 */ 1709 */
2066int 1710enum GNUNET_GenericReturnValue
2067GNUNET_CONTAINER_multihashmap32_put ( 1711GNUNET_CONTAINER_multihashmap32_put (
2068 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1712 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2069 uint32_t key, 1713 uint32_t key,
@@ -2086,7 +1730,7 @@ int
2086GNUNET_CONTAINER_multihashmap32_get_multiple ( 1730GNUNET_CONTAINER_multihashmap32_get_multiple (
2087 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1731 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2088 uint32_t key, 1732 uint32_t key,
2089 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1733 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
2090 void *it_cls); 1734 void *it_cls);
2091 1735
2092 1736
@@ -2121,7 +1765,7 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (
2121 * @return #GNUNET_YES we returned an element, 1765 * @return #GNUNET_YES we returned an element,
2122 * #GNUNET_NO if we are out of elements 1766 * #GNUNET_NO if we are out of elements
2123 */ 1767 */
2124int 1768enum GNUNET_GenericReturnValue
2125GNUNET_CONTAINER_multihashmap32_iterator_next ( 1769GNUNET_CONTAINER_multihashmap32_iterator_next (
2126 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, 1770 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
2127 uint32_t *key, 1771 uint32_t *key,
@@ -2568,7 +2212,7 @@ GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
2568 * @return #GNUNET_YES if an element is returned, 2212 * @return #GNUNET_YES if an element is returned,
2569 * #GNUNET_NO if the heap is empty. 2213 * #GNUNET_NO if the heap is empty.
2570 */ 2214 */
2571int 2215enum GNUNET_GenericReturnValue
2572GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap, 2216GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
2573 void **element, 2217 void **element,
2574 GNUNET_CONTAINER_HeapCostType *cost); 2218 GNUNET_CONTAINER_HeapCostType *cost);
@@ -2608,8 +2252,8 @@ GNUNET_CONTAINER_heap_node_get_cost (
2608 * @return #GNUNET_YES if we should continue to iterate, 2252 * @return #GNUNET_YES if we should continue to iterate,
2609 * #GNUNET_NO if not. 2253 * #GNUNET_NO if not.
2610 */ 2254 */
2611typedef int 2255typedef enum GNUNET_GenericReturnValue
2612(*GNUNET_CONTAINER_HeapIterator) ( 2256(*GNUNET_CONTAINER_HeapIterator)(
2613 void *cls, 2257 void *cls,
2614 struct GNUNET_CONTAINER_HeapNode *node, 2258 struct GNUNET_CONTAINER_HeapNode *node,
2615 void *element, 2259 void *element,
@@ -2704,4 +2348,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
2704 2348
2705/* ifndef GNUNET_CONTAINER_LIB_H */ 2349/* ifndef GNUNET_CONTAINER_LIB_H */
2706#endif 2350#endif
2351
2352/** @} */ /* end of group addition */
2353
2707/* end of gnunet_container_lib.h */ 2354/* end of gnunet_container_lib.h */
diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h
index be5a81cfb..7857a49cf 100644
--- a/src/include/gnunet_conversation_service.h
+++ b/src/include/gnunet_conversation_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -58,6 +61,7 @@ extern "C"
58#endif 61#endif
59#endif 62#endif
60 63
64
61#include "gnunet_util_lib.h" 65#include "gnunet_util_lib.h"
62#include "gnunet_identity_service.h" 66#include "gnunet_identity_service.h"
63#include "gnunet_namestore_service.h" 67#include "gnunet_namestore_service.h"
@@ -147,7 +151,7 @@ typedef void
147 struct GNUNET_CONVERSATION_Caller * 151 struct GNUNET_CONVERSATION_Caller *
148 caller, 152 caller,
149 const struct 153 const struct
150 GNUNET_IDENTITY_PublicKey *caller_id); 154 GNUNET_CRYPTO_PublicKey *caller_id);
151 155
152 156
153/** 157/**
@@ -438,3 +442,5 @@ GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call);
438#endif 442#endif
439 443
440/** @} */ /* end of group */ 444/** @} */ /* end of group */
445
446/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 59d9613f8..c3069be81 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -20,6 +20,9 @@
20/** 20/**
21 * @author Christian Grothoff 21 * @author Christian Grothoff
22 * 22 *
23 * @addtogroup Backbone
24 * @{
25 *
23 * @file include/gnunet_core_service.h 26 * @file include/gnunet_core_service.h
24 * Core service; the main API for encrypted P2P communications 27 * Core service; the main API for encrypted P2P communications
25 * 28 *
@@ -40,8 +43,8 @@ extern "C" {
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
44#include "gnunet_transport_service.h"
45 48
46/** 49/**
47 * Version number of GNUnet-core API. 50 * Version number of GNUnet-core API.
@@ -441,4 +444,6 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
441 444
442/** @} */ /* end of group core */ 445/** @} */ /* end of group core */
443 446
447/** @} */ /* end of backbone addition */
448
444/* end of gnunet_core_service.h */ 449/* end of gnunet_core_service.h */
diff --git a/src/include/gnunet_core_testing_lib.h b/src/include/gnunet_core_testing_lib.h
new file mode 100644
index 000000000..bf6f416d9
--- /dev/null
+++ b/src/include/gnunet_core_testing_lib.h
@@ -0,0 +1,158 @@
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_CORE_TESTING_LIB_H
26#define GNUNET_CORE_TESTING_LIB_H
27
28
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_ng_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 GNUNET_TESTING_ConnectPeersState)
153
154GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_CORE_TESTING)
155
156
157
158#endif
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index edb4bb230..50937324d 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @file include/gnunet_crypto_lib.h 26 * @file include/gnunet_crypto_lib.h
23 * @brief cryptographic primitives for GNUnet 27 * @brief cryptographic primitives for GNUnet
24 * 28 *
@@ -40,6 +44,10 @@
40 * @see [Documentation](https://gnunet.org/crypto-api) 44 * @see [Documentation](https://gnunet.org/crypto-api)
41 */ 45 */
42 46
47#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
48#error "Only <gnunet_util_lib.h> can be included directly."
49#endif
50
43#ifndef GNUNET_CRYPTO_LIB_H 51#ifndef GNUNET_CRYPTO_LIB_H
44#define GNUNET_CRYPTO_LIB_H 52#define GNUNET_CRYPTO_LIB_H
45 53
@@ -50,6 +58,8 @@ extern "C" {
50#endif 58#endif
51#endif 59#endif
52 60
61
62#include <stdbool.h>
53#include <sodium.h> 63#include <sodium.h>
54 64
55/** 65/**
@@ -57,7 +67,6 @@ extern "C" {
57 */ 67 */
58struct GNUNET_PeerIdentity; 68struct GNUNET_PeerIdentity;
59 69
60#include "gnunet_common.h"
61#include <gcrypt.h> 70#include <gcrypt.h>
62 71
63 72
@@ -286,6 +295,170 @@ struct GNUNET_CRYPTO_EddsaPrivateScalar
286 unsigned char s[512 / 8]; 295 unsigned char s[512 / 8];
287}; 296};
288 297
298/**
299 * Private ECC key material encoded for transmission. To be used only for
300 * Edx25519 signatures. An initial key corresponds to data from the key
301 * expansion and clamping in the EdDSA key generation.
302 */
303struct GNUNET_CRYPTO_Edx25519PrivateKey
304{
305 /**
306 * a is a value mod n, where n has at most 256 bits. It is the first half of
307 * the seed-expansion of EdDSA and will be clamped.
308 */
309 unsigned char a[256 / 8];
310
311 /**
312 * b consists of 32 bytes which where originally the lower 32bytes of the key
313 * expansion. Subsequent calls to derive_private will change this value, too.
314 */
315 unsigned char b[256 / 8];
316};
317
318
319/**
320 * Public ECC key (always for curve Ed25519) encoded in a format suitable for
321 * network transmission and Edx25519 (same as EdDSA) signatures. Refer to
322 * section 5.1.3 of rfc8032, for a thorough explanation of how this value maps
323 * to the x- and y-coordinates.
324 */
325struct GNUNET_CRYPTO_Edx25519PublicKey
326{
327 /**
328 * Point Q consists of a y-value mod p (256 bits); the x-value is
329 * always positive. The point is stored in Ed25519 standard
330 * compact format.
331 */
332 unsigned char q_y[256 / 8];
333};
334
335/**
336 * @brief an ECC signature using Edx25519 (same as in EdDSA).
337 */
338struct GNUNET_CRYPTO_Edx25519Signature
339{
340 /**
341 * R value.
342 */
343 unsigned char r[256 / 8];
344
345 /**
346 * S value.
347 */
348 unsigned char s[256 / 8];
349};
350
351/**
352 * Elligator representative (always for Curve25519)
353 */
354struct GNUNET_CRYPTO_ElligatorRepresentative
355{
356 /**
357 * Represents an element of Curve25519 finite field.
358 * Always smaller than 2 ^ 254 - 10 -> Needs to be serialized into a random-looking byte stream before transmission.
359 */
360 unsigned char r[256 / 8];
361};
362
363/**
364 * Key type for the generic public key union
365 */
366enum GNUNET_CRYPTO_KeyType
367{
368 /**
369 * The identity type. The value is the same as the
370 * PKEY record type.
371 */
372 GNUNET_PUBLIC_KEY_TYPE_ECDSA = 65536,
373
374 /**
375 * EDDSA identity. The value is the same as the EDKEY
376 * record type.
377 */
378 GNUNET_PUBLIC_KEY_TYPE_EDDSA = 65556
379};
380
381/**
382 * A private key for an identity as per LSD0001.
383 * Note that these types are NOT packed and MUST NOT be used in RPC
384 * messages. Use the respective serialization functions.
385 */
386struct GNUNET_CRYPTO_PrivateKey
387{
388 /**
389 * Type of public key.
390 * Defined by the GNS zone type value.
391 * In NBO.
392 */
393 uint32_t type;
394
395 union
396 {
397 /**
398 * An ECDSA identity key.
399 */
400 struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key;
401
402 /**
403 * AN EdDSA identtiy key
404 */
405 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key;
406 };
407};
408
409
410/**
411 * An identity key as per LSD0001.
412 */
413struct GNUNET_CRYPTO_PublicKey
414{
415 /**
416 * Type of public key.
417 * Defined by the GNS zone type value.
418 * In NBO.
419 */
420 uint32_t type;
421
422 union
423 {
424 /**
425 * An ECDSA identity key.
426 */
427 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key;
428
429 /**
430 * AN EdDSA identtiy key
431 */
432 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key;
433 };
434};
435
436
437/**
438 * An identity signature as per LSD0001.
439 */
440struct GNUNET_CRYPTO_Signature
441{
442 /**
443 * Type of signature.
444 * Defined by the GNS zone type value.
445 * In NBO.
446 */
447 uint32_t type;
448
449 union
450 {
451 /**
452 * An ECDSA signature
453 */
454 struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature;
455
456 /**
457 * AN EdDSA signature
458 */
459 struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
460 };
461};
289 462
290/** 463/**
291 * @brief type for session keys 464 * @brief type for session keys
@@ -306,7 +479,7 @@ struct GNUNET_CRYPTO_SymmetricSessionKey
306/** 479/**
307 * Type of a nonce used for challenges. 480 * Type of a nonce used for challenges.
308 */ 481 */
309struct ChallengeNonceP 482struct GNUNET_CRYPTO_ChallengeNonceP
310{ 483{
311 /** 484 /**
312 * The value of the nonce. Note that this is NOT a hash. 485 * The value of the nonce. Note that this is NOT a hash.
@@ -392,6 +565,143 @@ struct GNUNET_CRYPTO_PaillierCiphertext
392}; 565};
393 566
394 567
568/**
569 * Curve25519 Scalar
570 */
571struct GNUNET_CRYPTO_Cs25519Scalar
572{
573 /**
574 * 32 byte scalar
575 */
576 unsigned char d[crypto_core_ed25519_SCALARBYTES];
577};
578
579
580/**
581 * Curve25519 point
582 */
583struct GNUNET_CRYPTO_Cs25519Point
584{
585 /**
586 * This is a point on the Curve25519.
587 * The x coordinate can be restored using the y coordinate
588 */
589 unsigned char y[crypto_core_ed25519_BYTES];
590};
591
592
593/**
594 * The private information of an Schnorr key pair.
595 */
596struct GNUNET_CRYPTO_CsPrivateKey
597{
598 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
599};
600
601
602/**
603 * The public information of an Schnorr key pair.
604 */
605struct GNUNET_CRYPTO_CsPublicKey
606{
607 struct GNUNET_CRYPTO_Cs25519Point point;
608};
609
610
611/**
612 * Secret used for blinding (alpha and beta).
613 */
614struct GNUNET_CRYPTO_CsBlindingSecret
615{
616 struct GNUNET_CRYPTO_Cs25519Scalar alpha;
617 struct GNUNET_CRYPTO_Cs25519Scalar beta;
618};
619
620
621/**
622 * the private r used in the signature
623 */
624struct GNUNET_CRYPTO_CsRSecret
625{
626 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
627};
628
629
630/**
631 * the public R (derived from r) used in c
632 */
633struct GNUNET_CRYPTO_CsRPublic
634{
635 struct GNUNET_CRYPTO_Cs25519Point point;
636};
637
638
639/**
640 * Schnorr c to be signed
641 */
642struct GNUNET_CRYPTO_CsC
643{
644 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
645};
646
647
648/**
649 * s in the signature
650 */
651struct GNUNET_CRYPTO_CsS
652{
653 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
654};
655
656
657/**
658 * blinded s in the signature
659 */
660struct GNUNET_CRYPTO_CsBlindS
661{
662 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
663};
664
665
666/**
667 * CS Signtature containing scalar s and point R
668 */
669struct GNUNET_CRYPTO_CsSignature
670{
671 /**
672 * Schnorr signatures are composed of a scalar s and a curve point
673 */
674 struct GNUNET_CRYPTO_CsS s_scalar;
675
676 /**
677 * Curve point of the Schnorr signature.
678 */
679 struct GNUNET_CRYPTO_CsRPublic r_point;
680};
681
682
683/**
684 * Nonce for the session, picked by client,
685 * shared with the signer.
686 */
687struct GNUNET_CRYPTO_CsSessionNonce
688{
689 /*a nonce*/
690 unsigned char snonce[256 / 8];
691};
692
693
694/**
695 * Nonce for computing blinding factors. Not
696 * shared with the signer.
697 */
698struct GNUNET_CRYPTO_CsBlindingNonce
699{
700 /*a nonce*/
701 unsigned char bnonce[256 / 8];
702};
703
704
395/* **************** Functions and Macros ************* */ 705/* **************** Functions and Macros ************* */
396 706
397/** 707/**
@@ -480,7 +790,7 @@ GNUNET_CRYPTO_zero_keys (void *buffer, size_t length);
480 * Fill block with a random values. 790 * Fill block with a random values.
481 * 791 *
482 * @param mode desired quality of the random number 792 * @param mode desired quality of the random number
483 * @param buffer the buffer to fill 793 * @param[out] buffer the buffer to fill
484 * @param length buffer length 794 * @param length buffer length
485 */ 795 */
486void 796void
@@ -497,7 +807,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
497 * here is not a completely random number. 807 * here is not a completely random number.
498 * 808 *
499 * @param mode desired quality of the random number 809 * @param mode desired quality of the random number
500 * @param uuid the value to fill 810 * @param[out] uuid the value to fill
501 */ 811 */
502void 812void
503GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode, 813GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode,
@@ -518,7 +828,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
518 828
519/** 829/**
520 * @ingroup crypto 830 * @ingroup crypto
521 * Random on unsigned 64-bit values. 831 * Generate a random unsigned 64-bit value.
522 * 832 *
523 * @param mode desired quality of the random number 833 * @param mode desired quality of the random number
524 * @param max value returned will be in range [0,@a max) (exclusive) 834 * @param max value returned will be in range [0,@a max) (exclusive)
@@ -781,7 +1091,7 @@ GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc);
781 1091
782/** 1092/**
783 * Calculate HMAC of a message (RFC 2104) 1093 * Calculate HMAC of a message (RFC 2104)
784 * TODO: Shouldn' this be the standard hmac function and 1094 * TODO: Shouldn't this be the standard hmac function and
785 * the above be renamed? 1095 * the above be renamed?
786 * 1096 *
787 * @param key secret key 1097 * @param key secret key
@@ -916,61 +1226,38 @@ GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
916 1226
917 1227
918/** 1228/**
919 * @ingroup hash 1229 * Count the number of leading 0 bits in @a h.
920 * Convert a hashcode into a key.
921 * 1230 *
922 * @param hc hash code that serves to generate the key 1231 * @param h a hash
923 * @param skey set to a valid session key 1232 * @return number of leading 0 bits in @a h
924 * @param iv set to a valid initialization vector
925 */ 1233 */
926void 1234unsigned int
927GNUNET_CRYPTO_hash_to_aes_key ( 1235GNUNET_CRYPTO_hash_count_leading_zeros (const struct GNUNET_HashCode *h);
928 const struct GNUNET_HashCode *hc,
929 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
930 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
931 1236
932 1237
933/** 1238/**
934 * @ingroup hash 1239 * Count the number of tailing 0 bits in @a h.
935 * Obtain a bit from a hashcode.
936 * 1240 *
937 * @param code the `struct GNUNET_HashCode` to index bit-wise 1241 * @param h a hash
938 * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit 1242 * @return number of tailing 0 bits in @a h
939 * (bytes in code interpreted big endian)
940 * @return Bit \a bit from hashcode \a code, -1 for invalid index
941 */
942int
943GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
944 unsigned int bit);
945
946
947/**
948 * Obtain a bit from a hashcode.
949 * @param code the GNUNET_CRYPTO_hash to index bit-wise
950 * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
951 * (bytes in code interpreted little endian)
952 * @return Bit \a bit from hashcode \a code, -1 for invalid index
953 */ 1243 */
954int 1244unsigned int
955GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, 1245GNUNET_CRYPTO_hash_count_tailing_zeros (const struct GNUNET_HashCode *h);
956 unsigned int bit);
957 1246
958 1247
959/** 1248/**
960 * @ingroup hash 1249 * @ingroup hash
961 * Determine how many low order bits match in two 1250 * Convert a hashcode into a key.
962 * `struct GNUNET_HashCodes`. e.g. - 010011 and 011111 share
963 * the first two lowest order bits, and therefore the
964 * return value is two (NOT XOR distance, nor how many
965 * bits match absolutely!).
966 * 1251 *
967 * @param first the first hashcode 1252 * @param hc hash code that serves to generate the key
968 * @param second the hashcode to compare first to 1253 * @param skey set to a valid session key
969 * @return the number of bits that match 1254 * @param iv set to a valid initialization vector
970 */ 1255 */
971unsigned int 1256void
972GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, 1257GNUNET_CRYPTO_hash_to_aes_key (
973 const struct GNUNET_HashCode *second); 1258 const struct GNUNET_HashCode *hc,
1259 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
1260 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
974 1261
975 1262
976/** 1263/**
@@ -1180,6 +1467,17 @@ GNUNET_CRYPTO_eddsa_key_get_public (
1180 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 1467 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1181 struct GNUNET_CRYPTO_EddsaPublicKey *pub); 1468 struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1182 1469
1470/**
1471 * @ingroup crypto
1472 * Extract the public key for the given private key.
1473 *
1474 * @param priv the private key
1475 * @param pub where to write the public key
1476 */
1477void
1478GNUNET_CRYPTO_edx25519_key_get_public (
1479 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
1480 struct GNUNET_CRYPTO_Edx25519PublicKey *pub);
1183 1481
1184/** 1482/**
1185 * @ingroup crypto 1483 * @ingroup crypto
@@ -1264,7 +1562,7 @@ enum GNUNET_GenericReturnValue
1264GNUNET_CRYPTO_eddsa_private_key_from_string ( 1562GNUNET_CRYPTO_eddsa_private_key_from_string (
1265 const char *enc, 1563 const char *enc,
1266 size_t enclen, 1564 size_t enclen,
1267 struct GNUNET_CRYPTO_EddsaPrivateKey *pub); 1565 struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
1268 1566
1269 1567
1270/** 1568/**
@@ -1366,7 +1664,34 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
1366 1664
1367/** 1665/**
1368 * @ingroup crypto 1666 * @ingroup crypto
1667 * Create a new private key.
1668 *
1669 * @param[out] pk private key to initialize
1670 */
1671void
1672GNUNET_CRYPTO_edx25519_key_create (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1673
1674/**
1675 * @ingroup crypto
1676 * Create a new private key for Edx25519 from a given seed. After expanding
1677 * the seed, the first half of the key will be clamped according to EdDSA.
1678 *
1679 * @param seed seed input
1680 * @param seedsize size of the seed in bytes
1681 * @param[out] pk private key to initialize
1682 */
1683void
1684GNUNET_CRYPTO_edx25519_key_create_from_seed (
1685 const void *seed,
1686 size_t seedsize,
1687 struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1688
1689/**
1690 * @ingroup crypto
1369 * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). 1691 * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
1692 * This is X25519 DH (RFC 7748 Section 5) and corresponds to
1693 * X25519(a,9).
1694 * See #GNUNET_CRYPTO_ecc_ecdh for the DH function.
1370 * 1695 *
1371 * @param[out] pk set to fresh private key; 1696 * @param[out] pk set to fresh private key;
1372 */ 1697 */
@@ -1393,6 +1718,14 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
1393void 1718void
1394GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk); 1719GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk);
1395 1720
1721/**
1722 * @ingroup crypto
1723 * Clear memory that was used to store a private key.
1724 *
1725 * @param pk location of the key
1726 */
1727void
1728GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1396 1729
1397/** 1730/**
1398 * @ingroup crypto 1731 * @ingroup crypto
@@ -1436,12 +1769,49 @@ GNUNET_CRYPTO_eddsa_setup_hostkey (const char *cfg_name);
1436 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity 1769 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
1437 * could not be retrieved 1770 * could not be retrieved
1438 */ 1771 */
1439int 1772enum GNUNET_GenericReturnValue
1440GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, 1773GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
1441 struct GNUNET_PeerIdentity *dst); 1774 struct GNUNET_PeerIdentity *dst);
1442 1775
1443 1776
1444/** 1777/**
1778 * @ingroup crypto
1779 * Sign a given block with a specific purpose using the host's peer identity.
1780 *
1781 * @param cfg configuration to use
1782 * @param purpose what to sign (size, purpose)
1783 * @param sig where to write the signature
1784 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
1785 * could not be retrieved
1786 */
1787enum GNUNET_GenericReturnValue
1788GNUNET_CRYPTO_sign_by_peer_identity (const struct
1789 GNUNET_CONFIGURATION_Handle *cfg,
1790 const struct
1791 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1792 struct GNUNET_CRYPTO_EddsaSignature *sig);
1793
1794
1795/**
1796 * @ingroup crypto
1797 * Verify a given signature with a peer's identity.
1798 *
1799 * @param purpose what is the purpose that the signature should have?
1800 * @param validate block to validate (size, purpose, data)
1801 * @param sig signature that is being validated
1802 * @param identity the peer's identity to verify
1803 * @return #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
1804 */
1805enum GNUNET_GenericReturnValue
1806GNUNET_CRYPTO_verify_peer_identity (uint32_t purpose,
1807 const struct
1808 GNUNET_CRYPTO_EccSignaturePurpose *validate,
1809 const struct
1810 GNUNET_CRYPTO_EddsaSignature *sig,
1811 const struct GNUNET_PeerIdentity *identity);
1812
1813
1814/**
1445 * Internal structure used to cache pre-calculated values for DLOG calculation. 1815 * Internal structure used to cache pre-calculated values for DLOG calculation.
1446 */ 1816 */
1447struct GNUNET_CRYPTO_EccDlogContext; 1817struct GNUNET_CRYPTO_EccDlogContext;
@@ -1484,7 +1854,7 @@ GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max,
1484 * Calculate ECC discrete logarithm for small factors. 1854 * Calculate ECC discrete logarithm for small factors.
1485 * Opposite of #GNUNET_CRYPTO_ecc_dexp(). 1855 * Opposite of #GNUNET_CRYPTO_ecc_dexp().
1486 * 1856 *
1487 * @param dlc precalculated values, determine range of factors 1857 * @param edc precalculated values, determine range of factors
1488 * @param input point on the curve to factor 1858 * @param input point on the curve to factor
1489 * @return INT_MAX if dlog failed, otherwise the factor 1859 * @return INT_MAX if dlog failed, otherwise the factor
1490 */ 1860 */
@@ -1607,6 +1977,9 @@ GNUNET_CRYPTO_ecc_scalar_from_int (int64_t val,
1607/** 1977/**
1608 * @ingroup crypto 1978 * @ingroup crypto
1609 * Derive key material from a public and a private ECC key. 1979 * Derive key material from a public and a private ECC key.
1980 * This is X25519 DH (RFC 7748 Section 5) and corresponds to
1981 * H(X25519(b,X25519(a,9))) where b := priv, pub := X25519(a,9),
1982 * and a := #GNUNET_CRYPTO_ecdhe_key_create().
1610 * 1983 *
1611 * @param priv private key to use for the ECDH (x) 1984 * @param priv private key to use for the ECDH (x)
1612 * @param pub public key to use for the ECDH (yG) 1985 * @param pub public key to use for the ECDH (yG)
@@ -1623,6 +1996,10 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1623 * @ingroup crypto 1996 * @ingroup crypto
1624 * Derive key material from a ECDH public key and a private EdDSA key. 1997 * Derive key material from a ECDH public key and a private EdDSA key.
1625 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. 1998 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
1999 * This uses the Ed25519 private seed as X25519 seed.
2000 * As such, this also is a X25519 DH (see #GNUNET_CRYPTO_ecc_ecdh).
2001 * NOTE: Whenever you can get away with it, use separate key pairs
2002 * for signing and encryption (DH)!
1626 * 2003 *
1627 * @param priv private key from EdDSA to use for the ECDH (x) 2004 * @param priv private key from EdDSA to use for the ECDH (x)
1628 * @param pub public key to use for the ECDH (yG) 2005 * @param pub public key to use for the ECDH (yG)
@@ -1634,6 +2011,122 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1634 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 2011 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1635 struct GNUNET_HashCode *key_material); 2012 struct GNUNET_HashCode *key_material);
1636 2013
2014/**
2015 * @ingroup crypto
2016 * Decapsulate a key for a private EdDSA key.
2017 * Dual to #GNUNET_CRRYPTO_eddsa_kem_encaps.
2018 *
2019 * @param priv private key from EdDSA to use for the ECDH (x)
2020 * @param c the encapsulated key
2021 * @param key_material where to write the key material H(h(x)yG)
2022 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2023 */
2024enum GNUNET_GenericReturnValue
2025GNUNET_CRYPTO_eddsa_kem_decaps (const struct
2026 GNUNET_CRYPTO_EddsaPrivateKey *priv,
2027 const struct GNUNET_CRYPTO_EcdhePublicKey *c,
2028 struct GNUNET_HashCode *key_material);
2029
2030/**
2031 * @ingroup crypto
2032 * Encapsulate key material for a EdDSA public key.
2033 * Dual to #GNUNET_CRRYPTO_eddsa_kem_decaps.
2034 *
2035 * @param priv private key to use for the ECDH (y)
2036 * @param c public key from EdDSA to use for the ECDH (X=h(x)G)
2037 * @param key_material where to write the key material H(yX)=H(h(x)yG)
2038 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2039 */
2040enum GNUNET_GenericReturnValue
2041GNUNET_CRYPTO_eddsa_kem_encaps (const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2042 struct GNUNET_CRYPTO_EcdhePublicKey *c,
2043 struct GNUNET_HashCode *key_material);
2044
2045/**
2046 * This is the encapsulated key of our FO-KEM.
2047 */
2048struct GNUNET_CRYPTO_FoKemC
2049{
2050 /* The output of the FO-OWTF F(x) */
2051 struct GNUNET_HashCode y;
2052
2053 /* The ephemeral public key from the DH in the KEM */
2054 struct GNUNET_CRYPTO_EcdhePublicKey pub;
2055};
2056
2057/**
2058 * @ingroup crypto
2059 * Encapsulate key material using a CCA-secure KEM.
2060 * The KEM is using a OWTF with image oracle constructed from
2061 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2062 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_decaps.
2063 *
2064 * @param pub public key to encapsulated for
2065 * @param[out] c the encapsulation
2066 * @param[out] key_material the encapsulated key
2067 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2068 */
2069enum GNUNET_GenericReturnValue
2070GNUNET_CRYPTO_eddsa_fo_kem_encaps (
2071 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2072 struct GNUNET_CRYPTO_FoKemC *c,
2073 struct GNUNET_HashCode *key_material);
2074
2075
2076/**
2077 * @ingroup crypto
2078 * Decapsulate key material using a CCA-secure KEM.
2079 * The KEM is using a OWTF with image oracle constructed from
2080 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2081 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_encaps.
2082 *
2083 * @param priv private key this encapsulation is for
2084 * @param c the encapsulation
2085 * @param[out] key_material the encapsulated key
2086 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2087 */
2088enum GNUNET_GenericReturnValue
2089GNUNET_CRYPTO_eddsa_fo_kem_decaps (const struct
2090 GNUNET_CRYPTO_EddsaPrivateKey *priv,
2091 const struct GNUNET_CRYPTO_FoKemC *c,
2092 struct GNUNET_HashCode *key_material);
2093
2094/**
2095 * @ingroup crypto
2096 * Encapsulate key material using a CCA-secure KEM.
2097 * The KEM is using a OWTF with image oracle constructed from
2098 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2099 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_decaps.
2100 *
2101 * @param pub public key to encapsulated for
2102 * @param[out] c the encapsulation
2103 * @param[out] key_material the encapsulated key
2104 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2105 */
2106enum GNUNET_GenericReturnValue
2107GNUNET_CRYPTO_ecdsa_fo_kem_encaps (const struct
2108 GNUNET_CRYPTO_EcdsaPublicKey *pub,
2109 struct GNUNET_CRYPTO_FoKemC *c,
2110 struct GNUNET_HashCode *key_material);
2111
2112
2113/**
2114 * @ingroup crypto
2115 * Decapsulate key material using a CCA-secure KEM.
2116 * The KEM is using a OWTF with image oracle constructed from
2117 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2118 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_encaps.
2119 *
2120 * @param priv private key this encapsulation is for
2121 * @param c the encapsulation
2122 * @param[out] key_material the encapsulated key
2123 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2124 */
2125enum GNUNET_GenericReturnValue
2126GNUNET_CRYPTO_ecdsa_fo_kem_decaps (const struct
2127 GNUNET_CRYPTO_EcdsaPrivateKey *priv,
2128 struct GNUNET_CRYPTO_FoKemC *c,
2129 struct GNUNET_HashCode *key_material);
1637 2130
1638/** 2131/**
1639 * @ingroup crypto 2132 * @ingroup crypto
@@ -1655,6 +2148,10 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1655 * @ingroup crypto 2148 * @ingroup crypto
1656 * Derive key material from a EdDSA public key and a private ECDH key. 2149 * Derive key material from a EdDSA public key and a private ECDH key.
1657 * Dual to #GNUNET_CRRYPTO_eddsa_ecdh. 2150 * Dual to #GNUNET_CRRYPTO_eddsa_ecdh.
2151 * This converts the Edwards25519 public key @a pub to a Curve25519
2152 * public key before computing a X25519 DH (see #GNUNET_CRYPTO_ecc_ecdh).
2153 * NOTE: Whenever you can get away with it, use separate key pairs
2154 * for signing and encryption (DH)!
1658 * 2155 *
1659 * @param priv private key to use for the ECDH (y) 2156 * @param priv private key to use for the ECDH (y)
1660 * @param pub public key from EdDSA to use for the ECDH (X=h(x)G) 2157 * @param pub public key from EdDSA to use for the ECDH (X=h(x)G)
@@ -1666,6 +2163,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1666 const struct GNUNET_CRYPTO_EddsaPublicKey *pub, 2163 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1667 struct GNUNET_HashCode *key_material); 2164 struct GNUNET_HashCode *key_material);
1668 2165
2166
1669/** 2167/**
1670 * @ingroup crypto 2168 * @ingroup crypto
1671 * Derive key material from a EcDSA public key and a private ECDH key. 2169 * Derive key material from a EcDSA public key and a private ECDH key.
@@ -1750,6 +2248,21 @@ GNUNET_CRYPTO_ecdsa_sign_ (
1750 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 2248 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1751 struct GNUNET_CRYPTO_EcdsaSignature *sig); 2249 struct GNUNET_CRYPTO_EcdsaSignature *sig);
1752 2250
2251/**
2252 * @brief
2253 *
2254 * @param priv
2255 * @param data
2256 * @param size
2257 * @param sig
2258 * @return enum GNUNET_GenericReturnValue
2259 */
2260enum GNUNET_GenericReturnValue
2261GNUNET_CRYPTO_eddsa_sign_raw (
2262 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
2263 void *data,
2264 size_t size,
2265 struct GNUNET_CRYPTO_EddsaSignature *sig);
1753 2266
1754/** 2267/**
1755 * @ingroup crypto 2268 * @ingroup crypto
@@ -1775,6 +2288,53 @@ GNUNET_CRYPTO_ecdsa_sign_ (
1775 sig)); \ 2288 sig)); \
1776} while (0) 2289} while (0)
1777 2290
2291/**
2292 * @ingroup crypto
2293 * @brief Edx25519 sign a given block.
2294 *
2295 * The @a purpose data is the beginning of the data of which the signature is
2296 * to be created. The `size` field in @a purpose must correctly indicate the
2297 * number of bytes of the data structure, including its header. If possible,
2298 * use #GNUNET_CRYPTO_edx25519_sign() instead of this function (only if @a
2299 * validate is not fixed-size, you must use this function directly).
2300 *
2301 * @param priv private key to use for the signing
2302 * @param purpose what to sign (size, purpose)
2303 * @param[out] sig where to write the signature
2304 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2305 */
2306enum GNUNET_GenericReturnValue
2307GNUNET_CRYPTO_edx25519_sign_ (
2308 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
2309 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
2310 struct GNUNET_CRYPTO_Edx25519Signature *sig);
2311
2312
2313/**
2314 * @ingroup crypto
2315 * @brief Edx25519 sign a given block. The resulting signature is compatible
2316 * with EdDSA.
2317 *
2318 * The @a ps data must be a fixed-size struct for which the signature is to be
2319 * created. The `size` field in @a ps->purpose must correctly indicate the
2320 * number of bytes of the data structure, including its header.
2321 *
2322 * @param priv private key to use for the signing
2323 * @param ps packed struct with what to sign, MUST begin with a purpose
2324 * @param[out] sig where to write the signature
2325 */
2326#define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \
2327 /* check size is set correctly */ \
2328 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2329 /* check 'ps' begins with the purpose */ \
2330 GNUNET_static_assert (((void*) (ps)) == \
2331 ((void*) &(ps)->purpose)); \
2332 GNUNET_assert (GNUNET_OK == \
2333 GNUNET_CRYPTO_edx25519_sign_ (priv, \
2334 &(ps)->purpose, \
2335 sig)); \
2336} while (0)
2337
1778 2338
1779/** 2339/**
1780 * @ingroup crypto 2340 * @ingroup crypto
@@ -1818,7 +2378,7 @@ GNUNET_CRYPTO_eddsa_verify_ (
1818 */ 2378 */
1819#define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \ 2379#define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \
1820 /* check size is set correctly */ \ 2380 /* check size is set correctly */ \
1821 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ 2381 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
1822 /* check 'ps' begins with the purpose */ \ 2382 /* check 'ps' begins with the purpose */ \
1823 GNUNET_static_assert (((void*) (ps)) == \ 2383 GNUNET_static_assert (((void*) (ps)) == \
1824 ((void*) &(ps)->purpose)); \ 2384 ((void*) &(ps)->purpose)); \
@@ -1828,7 +2388,6 @@ GNUNET_CRYPTO_eddsa_verify_ (
1828 pub); \ 2388 pub); \
1829 }) 2389 })
1830 2390
1831
1832/** 2391/**
1833 * @ingroup crypto 2392 * @ingroup crypto
1834 * @brief Verify ECDSA signature. 2393 * @brief Verify ECDSA signature.
@@ -1883,6 +2442,58 @@ GNUNET_CRYPTO_ecdsa_verify_ (
1883 2442
1884/** 2443/**
1885 * @ingroup crypto 2444 * @ingroup crypto
2445 * @brief Verify Edx25519 signature.
2446 *
2447 * The @a validate data is the beginning of the data of which the signature
2448 * is to be verified. The `size` field in @a validate must correctly indicate
2449 * the number of bytes of the data structure, including its header. If @a
2450 * purpose does not match the purpose given in @a validate (the latter must be
2451 * in big endian), signature verification fails. If possible, use
2452 * #GNUNET_CRYPTO_edx25519_verify() instead of this function (only if @a
2453 * validate is not fixed-size, you must use this function directly).
2454 *
2455 * @param purpose what is the purpose that the signature should have?
2456 * @param validate block to validate (size, purpose, data)
2457 * @param sig signature that is being validated
2458 * @param pub public key of the signer
2459 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
2460 */
2461enum GNUNET_GenericReturnValue
2462GNUNET_CRYPTO_edx25519_verify_ (
2463 uint32_t purpose,
2464 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
2465 const struct GNUNET_CRYPTO_Edx25519Signature *sig,
2466 const struct GNUNET_CRYPTO_Edx25519PublicKey *pub);
2467
2468
2469/**
2470 * @ingroup crypto
2471 * @brief Verify Edx25519 signature.
2472 *
2473 * The @a ps data must be a fixed-size struct for which the signature is to be
2474 * created. The `size` field in @a ps->purpose must correctly indicate the
2475 * number of bytes of the data structure, including its header.
2476 *
2477 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
2478 * (except in host byte order)
2479 * @param priv private key to use for the signing
2480 * @param ps packed struct with what to sign, MUST begin with a purpose
2481 * @param sig where to write the signature
2482 */
2483#define GNUNET_CRYPTO_edx25519_verify(purp,ps,sig,pub) ({ \
2484 /* check size is set correctly */ \
2485 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2486 /* check 'ps' begins with the purpose */ \
2487 GNUNET_static_assert (((void*) (ps)) == \
2488 ((void*) &(ps)->purpose)); \
2489 GNUNET_CRYPTO_edx25519_verify_ (purp, \
2490 &(ps)->purpose, \
2491 sig, \
2492 pub); \
2493 })
2494
2495/**
2496 * @ingroup crypto
1886 * Derive a private key from a given private key and a label. 2497 * Derive a private key from a given private key and a label.
1887 * Essentially calculates a private key 'h = H(l,P) * d mod n' 2498 * Essentially calculates a private key 'h = H(l,P) * d mod n'
1888 * where n is the size of the ECC group and P is the public 2499 * where n is the size of the ECC group and P is the public
@@ -1919,6 +2530,26 @@ GNUNET_CRYPTO_ecdsa_public_key_derive (
1919 const char *context, 2530 const char *context,
1920 struct GNUNET_CRYPTO_EcdsaPublicKey *result); 2531 struct GNUNET_CRYPTO_EcdsaPublicKey *result);
1921 2532
2533/**
2534 * This is a signature function for ECDSA which takes a
2535 * private key, derives/blinds it and signs the message.
2536 *
2537 * @param pkey original private key
2538 * @param label label to use for key deriviation
2539 * @param context additional context to use for HKDF of 'h';
2540 * typically the name of the subsystem/application
2541 * @param purpose the signature purpose
2542 * @param sig the resulting signature
2543 * @return GNUNET_OK on success
2544 */
2545enum GNUNET_GenericReturnValue
2546GNUNET_CRYPTO_ecdsa_sign_derived (
2547 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
2548 const char *label,
2549 const char *context,
2550 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
2551 struct GNUNET_CRYPTO_EcdsaSignature *sig);
2552
1922 2553
1923/** 2554/**
1924 * @ingroup crypto 2555 * @ingroup crypto
@@ -1964,23 +2595,23 @@ GNUNET_CRYPTO_eddsa_public_key_derive (
1964 2595
1965 2596
1966/** 2597/**
1967 * This is a signature function for EdDSA which takes the 2598 * This is a signature function for EdDSA which takes a
1968 * secret scalar sk instead of the private seed which is 2599 * private key and derives it using the label and context
1969 * usually the case for crypto APIs. We require this functionality 2600 * before signing.
1970 * in order to use derived private keys for signatures we
1971 * cannot calculate the inverse of a sk to find the seed
1972 * efficiently.
1973 *
1974 * The resulting signature is a standard EdDSA signature
1975 * which can be verified using the usual APIs.
1976 * 2601 *
1977 * @param sk the secret scalar 2602 * @param pkey original private key
1978 * @param purp the signature purpose 2603 * @param label label to use for key deriviation
2604 * @param context additional context to use for HKDF of 'h';
2605 * typically the name of the subsystem/application
2606 * @param purpose the signature purpose
1979 * @param sig the resulting signature 2607 * @param sig the resulting signature
2608 * @return GNUNET_OK on success
1980 */ 2609 */
1981void 2610enum GNUNET_GenericReturnValue
1982GNUNET_CRYPTO_eddsa_sign_with_scalar ( 2611GNUNET_CRYPTO_eddsa_sign_derived (
1983 const struct GNUNET_CRYPTO_EddsaPrivateScalar *priv, 2612 const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey,
2613 const char *label,
2614 const char *context,
1984 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 2615 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1985 struct GNUNET_CRYPTO_EddsaSignature *sig); 2616 struct GNUNET_CRYPTO_EddsaSignature *sig);
1986 2617
@@ -1996,6 +2627,134 @@ GNUNET_CRYPTO_eddsa_key_get_public_from_scalar (
1996 const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, 2627 const struct GNUNET_CRYPTO_EddsaPrivateScalar *s,
1997 struct GNUNET_CRYPTO_EddsaPublicKey *pkey); 2628 struct GNUNET_CRYPTO_EddsaPublicKey *pkey);
1998 2629
2630/**
2631 * @ingroup crypto
2632 * Derive a private scalar from a given private key and a label.
2633 * Essentially calculates a private key 'h = H(l,P) * d mod n'
2634 * where n is the size of the ECC group and P is the public
2635 * key associated with the private key 'd'.
2636 *
2637 * @param priv original private key
2638 * @param seed input seed
2639 * @param seedsize size of the seed
2640 * @param result derived private key
2641 */
2642void
2643GNUNET_CRYPTO_edx25519_private_key_derive (
2644 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
2645 const void *seed,
2646 size_t seedsize,
2647 struct GNUNET_CRYPTO_Edx25519PrivateKey *result);
2648
2649
2650/**
2651 * @ingroup crypto
2652 * Derive a public key from a given public key and a label.
2653 * Essentially calculates a public key 'V = H(l,P) * P'.
2654 *
2655 * @param pub original public key
2656 * @param seed input seed
2657 * @param seedsize size of the seed
2658 * @param result where to write the derived public key
2659 */
2660void
2661GNUNET_CRYPTO_edx25519_public_key_derive (
2662 const struct GNUNET_CRYPTO_Edx25519PublicKey *pub,
2663 const void *seed,
2664 size_t seedsize,
2665 struct GNUNET_CRYPTO_Edx25519PublicKey *result);
2666
2667
2668/**
2669 * @ingroup crypto
2670 * Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map.
2671 *
2672 * @param representative serialized elligator representative of an element of Curves25519's finite field
2673 * @param point destination for the calculated point on the curve
2674 * @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.
2675 */
2676void
2677GNUNET_CRYPTO_ecdhe_elligator_decoding (
2678 struct GNUNET_CRYPTO_EcdhePublicKey *point,
2679 bool *high_y,
2680 const struct GNUNET_CRYPTO_ElligatorRepresentative *representative);
2681
2682/**
2683 * @ingroup crypto
2684 * Encodes a point on Curve25519 to a an element of the underlying finite field.
2685 * This transformation is deterministic.
2686 *
2687 * @param r storage for the calculated representative
2688 * @param pub a point on the curve
2689 * @param high_y encodes if y-coordinate is > 2 ^254 - 10, which determines the representative value out of two
2690 * @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
2691 */
2692bool
2693GNUNET_CRYPTO_ecdhe_elligator_encoding (
2694 struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2695 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
2696 bool high_y);
2697
2698
2699/**
2700 * @ingroup crypto
2701 * Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.
2702 * Following Method 1 in description https://elligator.org/key-exchange section Step 2: Generate a “special” public key.
2703 *
2704 * @param pub valid public key for elligator inverse map
2705 * @param pk private key for generating valid public key
2706 * @return GNUNET_OK on success
2707 */
2708enum GNUNET_GenericReturnValue
2709GNUNET_CRYPTO_ecdhe_elligator_generate_public_key (
2710 struct GNUNET_CRYPTO_EcdhePublicKey *pub,
2711 struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
2712
2713
2714/**
2715 * @ingroup crypto
2716 * Generates a private key for Curve25519 and the elligator representative of the corresponding public key.
2717 *
2718 * @param repr representative of the public key
2719 * @param pk Curve25519 private key
2720 */
2721void
2722GNUNET_CRYPTO_ecdhe_elligator_key_create (
2723 struct GNUNET_CRYPTO_ElligatorRepresentative *repr,
2724 struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
2725
2726/**
2727 * @ingroup crypto
2728 * Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.
2729 * Following the terminology in https://eprint.iacr.org/2021/509.pdf.
2730 *
2731 * @param pub given edwards curve public key (X)
2732 * @param r representative of ephemeral public key A to use for the ECDH (direct_map(r)=A=aG)
2733 * @param key_material where to write the key material H(aX)=H(x(aG))
2734 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2735 */
2736enum GNUNET_GenericReturnValue
2737GNUNET_CRYPTO_eddsa_elligator_kem_encaps (
2738 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2739 struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2740 struct GNUNET_HashCode *key_material);
2741
2742/**
2743 * @ingroup crypto
2744 * Carries out ecdh decapsulation with own private key and the representative of the received public key.
2745 * Following the terminology in https://eprint.iacr.org/2021/509.pdf.
2746 *
2747 * @param priv own private key (x)
2748 * @param r received representative r, from which we can obtain the public key A (direct_map(r)=A=aG)
2749 * @param key_material where to write the key material H(xA)=H(a(xG))
2750 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2751 */
2752enum GNUNET_GenericReturnValue
2753GNUNET_CRYPTO_eddsa_elligator_kem_decaps (
2754 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
2755 const struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2756 struct GNUNET_HashCode *key_material);
2757
1999 2758
2000/** 2759/**
2001 * Output the given MPI value to the given buffer in network 2760 * Output the given MPI value to the given buffer in network
@@ -2063,7 +2822,7 @@ GNUNET_CRYPTO_paillier_encrypt (
2063 * @param private_key Private key to use for decryption. 2822 * @param private_key Private key to use for decryption.
2064 * @param public_key Public key to use for decryption. 2823 * @param public_key Public key to use for decryption.
2065 * @param ciphertext Ciphertext to decrypt. 2824 * @param ciphertext Ciphertext to decrypt.
2066 * @param[out] m Decryption of @a ciphertext with @private_key. 2825 * @param[out] m Decryption of @a ciphertext with @a private_key.
2067 */ 2826 */
2068void 2827void
2069GNUNET_CRYPTO_paillier_decrypt ( 2828GNUNET_CRYPTO_paillier_decrypt (
@@ -2074,7 +2833,8 @@ GNUNET_CRYPTO_paillier_decrypt (
2074 2833
2075 2834
2076/** 2835/**
2077 * Compute a ciphertext that represents the sum of the plaintext in @a x1 and @a x2 2836 * Compute a ciphertext that represents the sum of the plaintext in @a c1
2837 * and @a c2
2078 * 2838 *
2079 * Note that this operation can only be done a finite number of times 2839 * Note that this operation can only be done a finite number of times
2080 * before an overflow occurs. 2840 * before an overflow occurs.
@@ -2211,8 +2971,9 @@ GNUNET_CRYPTO_rsa_private_key_get_public (
2211 * @param hc where to store the hash code 2971 * @param hc where to store the hash code
2212 */ 2972 */
2213void 2973void
2214GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, 2974GNUNET_CRYPTO_rsa_public_key_hash (
2215 struct GNUNET_HashCode *hc); 2975 const struct GNUNET_CRYPTO_RsaPublicKey *key,
2976 struct GNUNET_HashCode *hc);
2216 2977
2217 2978
2218/** 2979/**
@@ -2317,53 +3078,83 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
2317 3078
2318 3079
2319/** 3080/**
3081 * @brief RSA Parameters to create blinded signature
3082 */
3083struct GNUNET_CRYPTO_RsaBlindedMessage
3084{
3085 /**
3086 * Blinded message to be signed
3087 * Note: is malloc()'ed!
3088 */
3089 void *blinded_msg;
3090
3091 /**
3092 * Size of the @e blinded_msg to be signed.
3093 */
3094 size_t blinded_msg_size;
3095};
3096
3097
3098/**
2320 * Blinds the given message with the given blinding key 3099 * Blinds the given message with the given blinding key
2321 * 3100 *
2322 * @param hash hash of the message to sign 3101 * @param message the message to sign
2323 * @param bkey the blinding key 3102 * @param message_size number of bytes in @a message
3103 * @param bks the blinding key
2324 * @param pkey the public key of the signer 3104 * @param pkey the public key of the signer
2325 * @param[out] buf set to a buffer with the blinded message to be signed 3105 * @param[out] bm set to the blinded message
2326 * @param[out] buf_size number of bytes stored in @a buf
2327 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious 3106 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
2328 */ 3107 */
2329int 3108enum GNUNET_GenericReturnValue
2330GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, 3109GNUNET_CRYPTO_rsa_blind (const void *message,
3110 size_t message_size,
2331 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, 3111 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
2332 struct GNUNET_CRYPTO_RsaPublicKey *pkey, 3112 struct GNUNET_CRYPTO_RsaPublicKey *pkey,
2333 void **buf, 3113 struct GNUNET_CRYPTO_RsaBlindedMessage *bm);
2334 size_t *buf_size);
2335 3114
2336 3115
2337/** 3116/**
2338 * Sign a blinded value, which must be a full domain hash of a message. 3117 * Sign a blinded value, which must be a full domain hash of a message.
2339 * 3118 *
2340 * @param key private key to use for the signing 3119 * @param key private key to use for the signing
2341 * @param msg the (blinded) message to sign 3120 * @param bm the (blinded) message to sign
2342 * @param msg_len number of bytes in @a msg to sign
2343 * @return NULL on error, signature on success 3121 * @return NULL on error, signature on success
2344 */ 3122 */
2345struct GNUNET_CRYPTO_RsaSignature * 3123struct GNUNET_CRYPTO_RsaSignature *
2346GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3124GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2347 const void *msg, 3125 const struct
2348 size_t msg_len); 3126 GNUNET_CRYPTO_RsaBlindedMessage *bm);
2349 3127
2350 3128
2351/** 3129/**
2352 * Create and sign a full domain hash of a message. 3130 * Create and sign a full domain hash of a message.
2353 * 3131 *
2354 * @param key private key to use for the signing 3132 * @param key private key to use for the signing
2355 * @param hash the hash of the message to sign 3133 * @param message the message to sign
3134 * @param message_size number of bytes in @a message
2356 * @return NULL on error, including a malicious RSA key, signature on success 3135 * @return NULL on error, including a malicious RSA key, signature on success
2357 */ 3136 */
2358struct GNUNET_CRYPTO_RsaSignature * 3137struct GNUNET_CRYPTO_RsaSignature *
2359GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3138GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2360 const struct GNUNET_HashCode *hash); 3139 const void *message,
3140 size_t message_size);
3141
3142
3143/**
3144 * Free memory occupied by blinded message. Only frees contents, not
3145 * @a bm itself.
3146 *
3147 * @param[in] bm memory to free
3148 */
3149void
3150GNUNET_CRYPTO_rsa_blinded_message_free (
3151 struct GNUNET_CRYPTO_RsaBlindedMessage *bm);
2361 3152
2362 3153
2363/** 3154/**
2364 * Free memory occupied by signature. 3155 * Free memory occupied by signature.
2365 * 3156 *
2366 * @param sig memory to free 3157 * @param[in] sig memory to free
2367 */ 3158 */
2368void 3159void
2369GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig); 3160GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig);
@@ -2391,8 +3182,9 @@ GNUNET_CRYPTO_rsa_signature_encode (
2391 * @return NULL on error 3182 * @return NULL on error
2392 */ 3183 */
2393struct GNUNET_CRYPTO_RsaSignature * 3184struct GNUNET_CRYPTO_RsaSignature *
2394GNUNET_CRYPTO_rsa_signature_decode (const void *buf, 3185GNUNET_CRYPTO_rsa_signature_decode (
2395 size_t buf_size); 3186 const void *buf,
3187 size_t buf_size);
2396 3188
2397 3189
2398/** 3190/**
@@ -2402,7 +3194,8 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf,
2402 * @return the duplicate key; NULL upon error 3194 * @return the duplicate key; NULL upon error
2403 */ 3195 */
2404struct GNUNET_CRYPTO_RsaSignature * 3196struct GNUNET_CRYPTO_RsaSignature *
2405GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig); 3197GNUNET_CRYPTO_rsa_signature_dup (
3198 const struct GNUNET_CRYPTO_RsaSignature *sig);
2406 3199
2407 3200
2408/** 3201/**
@@ -2425,17 +3218,1267 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
2425 * Verify whether the given hash corresponds to the given signature and the 3218 * Verify whether the given hash corresponds to the given signature and the
2426 * signature is valid with respect to the given public key. 3219 * signature is valid with respect to the given public key.
2427 * 3220 *
2428 * @param hash the message to verify to match the @a sig 3221 * @param message the message to sign
3222 * @param message_size number of bytes in @a message
2429 * @param sig signature that is being validated 3223 * @param sig signature that is being validated
2430 * @param public_key public key of the signer 3224 * @param public_key public key of the signer
2431 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature 3225 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature
2432 */ 3226 */
2433enum GNUNET_GenericReturnValue 3227enum GNUNET_GenericReturnValue
2434GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, 3228GNUNET_CRYPTO_rsa_verify (const void *message,
3229 size_t message_size,
2435 const struct GNUNET_CRYPTO_RsaSignature *sig, 3230 const struct GNUNET_CRYPTO_RsaSignature *sig,
2436 const struct GNUNET_CRYPTO_RsaPublicKey *public_key); 3231 const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
2437 3232
2438 3233
3234/**
3235 * Create a new random private key.
3236 *
3237 * @param[out] priv where to write the fresh private key
3238 */
3239void
3240GNUNET_CRYPTO_cs_private_key_generate (struct GNUNET_CRYPTO_CsPrivateKey *priv);
3241
3242
3243/**
3244 * Extract the public key of the given private key.
3245 *
3246 * @param priv the private key
3247 * @param[out] pub where to write the public key
3248 */
3249void
3250GNUNET_CRYPTO_cs_private_key_get_public (
3251 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
3252 struct GNUNET_CRYPTO_CsPublicKey *pub);
3253
3254
3255/**
3256 * Derive a new secret r pair r0 and r1.
3257 * In original papers r is generated randomly
3258 * To provide abort-idempotency, r needs to be derived but still needs to be UNPREDICTABLE
3259 * To ensure unpredictability a new nonce should be used when a new r needs to be derived.
3260 * Uses HKDF internally.
3261 * Comment: Can be done in one HKDF shot and split output.
3262 *
3263 * @param nonce is a random nonce
3264 * @param seed seed to use in derivation
3265 * @param lts is a long-term-secret in form of a private key
3266 * @param[out] r array containing derived secrets r0 and r1
3267 */
3268void
3269GNUNET_CRYPTO_cs_r_derive (
3270 const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
3271 const char *seed,
3272 const struct GNUNET_CRYPTO_CsPrivateKey *lts,
3273 struct GNUNET_CRYPTO_CsRSecret r[2]);
3274
3275
3276/**
3277 * Extract the public R of the given secret r.
3278 *
3279 * @param r_priv the private key
3280 * @param[out] r_pub where to write the public key
3281 */
3282void
3283GNUNET_CRYPTO_cs_r_get_public (
3284 const struct GNUNET_CRYPTO_CsRSecret *r_priv,
3285 struct GNUNET_CRYPTO_CsRPublic *r_pub);
3286
3287
3288/**
3289 * Derives new random blinding factors.
3290 * In original papers blinding factors are generated randomly
3291 * To provide abort-idempotency, blinding factors need to be derived but still need to be UNPREDICTABLE.
3292 * To ensure unpredictability a new nonce has to be used.
3293 * Uses HKDF internally.
3294 *
3295 * @param blind_seed is the blinding seed to derive blinding factors
3296 * @param[out] bs array containing the two derived blinding secrets
3297 */
3298void
3299GNUNET_CRYPTO_cs_blinding_secrets_derive (
3300 const struct GNUNET_CRYPTO_CsBlindingNonce *blind_seed,
3301 struct GNUNET_CRYPTO_CsBlindingSecret bs[2]);
3302
3303
3304/**
3305 * @brief CS Parameters derived from the message
3306 * during blinding to create blinded signature
3307 */
3308struct GNUNET_CRYPTO_CsBlindedMessage
3309{
3310 /**
3311 * The Clause Schnorr c_0 and c_1 containing the blinded message
3312 */
3313 struct GNUNET_CRYPTO_CsC c[2];
3314
3315 /**
3316 * Nonce used in initial request.
3317 */
3318 struct GNUNET_CRYPTO_CsSessionNonce nonce;
3319
3320};
3321
3322
3323/**
3324 * Pair of Public R values for Cs denominations
3325 */
3326struct GNUNET_CRYPTO_CSPublicRPairP
3327{
3328 struct GNUNET_CRYPTO_CsRPublic r_pub[2];
3329};
3330
3331
3332/**
3333 * Calculate two blinded c's.
3334 * Comment: One would be insecure due to Wagner's algorithm solving ROS
3335 *
3336 * @param bs array of the two blinding factor structs each containing alpha and beta
3337 * @param r_pub array of the two signer's nonce R
3338 * @param pub the public key of the signer
3339 * @param msg the message to blind in preparation for signing
3340 * @param msg_len length of message msg
3341 * @param[out] blinded_c array of the two blinded c's
3342 * @param[out] r_pub_blind array of the two blinded R
3343 */
3344void
3345GNUNET_CRYPTO_cs_calc_blinded_c (
3346 const struct GNUNET_CRYPTO_CsBlindingSecret bs[2],
3347 const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
3348 const struct GNUNET_CRYPTO_CsPublicKey *pub,
3349 const void *msg,
3350 size_t msg_len,
3351 struct GNUNET_CRYPTO_CsC blinded_c[2],
3352 struct GNUNET_CRYPTO_CSPublicRPairP *r_pub_blind);
3353
3354
3355/**
3356 * The Sign Answer for Clause Blind Schnorr signature.
3357 * The sign operation returns a parameter @param b and the signature
3358 * scalar @param s_scalar.
3359 */
3360struct GNUNET_CRYPTO_CsBlindSignature
3361{
3362 /**
3363 * To make ROS problem harder, the signer chooses an unpredictable b and
3364 * only calculates signature of c_b
3365 */
3366 unsigned int b;
3367
3368 /**
3369 * The blinded s scalar calculated from c_b
3370 */
3371 struct GNUNET_CRYPTO_CsBlindS s_scalar;
3372};
3373
3374
3375/**
3376 * Sign a blinded @a c.
3377 * This function derives b from a nonce and a longterm secret.
3378 * In the original papers b is generated randomly.
3379 * To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE.
3380 * To ensure unpredictability a new nonce has to be used for every signature.
3381 * HKDF is used internally for derivation.
3382 * r0 and r1 can be derived prior by using GNUNET_CRYPTO_cs_r_derive.
3383 *
3384 * @param priv private key to use for the signing and as LTS in HKDF
3385 * @param r array of the two secret inputs from the signer
3386 * @param bm blinded message, including array of the two blinded c to sign c_b and the random nonce
3387 * @param[out] cs_blind_sig where to write the blind signature
3388 */
3389void
3390GNUNET_CRYPTO_cs_sign_derive (
3391 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
3392 const struct GNUNET_CRYPTO_CsRSecret r[2],
3393 const struct GNUNET_CRYPTO_CsBlindedMessage *bm,
3394 struct GNUNET_CRYPTO_CsBlindSignature *cs_blind_sig);
3395
3396
3397/**
3398 * Unblind a blind-signed signature using a c that was blinded
3399 *
3400 * @param blinded_signature_scalar the signature made on the blinded c
3401 * @param bs the blinding factors used in the blinding
3402 * @param[out] signature_scalar where to write the unblinded signature
3403 */
3404void
3405GNUNET_CRYPTO_cs_unblind (
3406 const struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar,
3407 const struct GNUNET_CRYPTO_CsBlindingSecret *bs,
3408 struct GNUNET_CRYPTO_CsS *signature_scalar);
3409
3410
3411/**
3412 * Verify whether the given message corresponds to the given signature and the
3413 * signature is valid with respect to the given public key.
3414 *
3415 * @param sig signature that is being validated
3416 * @param pub public key of the signer
3417 * @param msg is the message that should be signed by @a sig (message is used to calculate c)
3418 * @param msg_len is the message length
3419 * @returns #GNUNET_YES on success, #GNUNET_SYSERR if signature invalid
3420 */
3421enum GNUNET_GenericReturnValue
3422GNUNET_CRYPTO_cs_verify (
3423 const struct GNUNET_CRYPTO_CsSignature *sig,
3424 const struct GNUNET_CRYPTO_CsPublicKey *pub,
3425 const void *msg,
3426 size_t msg_len);
3427
3428
3429/**
3430 * Types of public keys used for blind signatures.
3431 */
3432enum GNUNET_CRYPTO_BlindSignatureAlgorithm
3433{
3434
3435 /**
3436 * Invalid type of signature.
3437 */
3438 GNUNET_CRYPTO_BSA_INVALID = 0,
3439
3440 /**
3441 * RSA blind signature.
3442 */
3443 GNUNET_CRYPTO_BSA_RSA = 1,
3444
3445 /**
3446 * Clause Blind Schnorr signature.
3447 */
3448 GNUNET_CRYPTO_BSA_CS = 2
3449};
3450
3451
3452/**
3453 * @brief Type of (unblinded) signatures.
3454 */
3455struct GNUNET_CRYPTO_UnblindedSignature
3456{
3457
3458 /**
3459 * Type of the signature.
3460 */
3461 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3462
3463 /**
3464 * Reference counter.
3465 */
3466 unsigned int rc;
3467
3468 /**
3469 * Details, depending on @e cipher.
3470 */
3471 union
3472 {
3473 /**
3474 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3475 */
3476 struct GNUNET_CRYPTO_CsSignature cs_signature;
3477
3478 /**
3479 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3480 */
3481 struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
3482
3483 } details;
3484
3485};
3486
3487
3488/**
3489 * @brief Type for *blinded* signatures.
3490 * Must be unblinded before it becomes valid.
3491 */
3492struct GNUNET_CRYPTO_BlindedSignature
3493{
3494
3495 /**
3496 * Type of the signature.
3497 */
3498 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3499
3500 /**
3501 * Reference counter.
3502 */
3503 unsigned int rc;
3504
3505 /**
3506 * Details, depending on @e cipher.
3507 */
3508 union
3509 {
3510 /**
3511 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3512 * At this point only the blinded s scalar is used.
3513 * The final signature consisting of r,s is built after unblinding.
3514 */
3515 struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer;
3516
3517 /**
3518 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3519 */
3520 struct GNUNET_CRYPTO_RsaSignature *blinded_rsa_signature;
3521
3522 } details;
3523
3524};
3525
3526
3527/**
3528 * @brief Type of public signing keys for blind signatures.
3529 */
3530struct GNUNET_CRYPTO_BlindSignPublicKey
3531{
3532
3533 /**
3534 * Type of the public key.
3535 */
3536 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3537
3538 /**
3539 * Reference counter.
3540 */
3541 unsigned int rc;
3542
3543 /**
3544 * Hash of the public key.
3545 */
3546 struct GNUNET_HashCode pub_key_hash;
3547
3548 /**
3549 * Details, depending on @e cipher.
3550 */
3551 union
3552 {
3553 /**
3554 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3555 */
3556 struct GNUNET_CRYPTO_CsPublicKey cs_public_key;
3557
3558 /**
3559 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3560 */
3561 struct GNUNET_CRYPTO_RsaPublicKey *rsa_public_key;
3562
3563 } details;
3564};
3565
3566
3567/**
3568 * @brief Type of private signing keys for blind signing.
3569 */
3570struct GNUNET_CRYPTO_BlindSignPrivateKey
3571{
3572
3573 /**
3574 * Type of the public key.
3575 */
3576 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3577
3578 /**
3579 * Reference counter.
3580 */
3581 unsigned int rc;
3582
3583 /**
3584 * Details, depending on @e cipher.
3585 */
3586 union
3587 {
3588 /**
3589 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3590 */
3591 struct GNUNET_CRYPTO_CsPrivateKey cs_private_key;
3592
3593 /**
3594 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3595 */
3596 struct GNUNET_CRYPTO_RsaPrivateKey *rsa_private_key;
3597
3598 } details;
3599};
3600
3601
3602/**
3603 * @brief Blinded message ready for blind signing.
3604 */
3605struct GNUNET_CRYPTO_BlindedMessage
3606{
3607 /**
3608 * Type of the sign blinded message
3609 */
3610 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3611
3612 /**
3613 * Reference counter.
3614 */
3615 unsigned int rc;
3616
3617 /**
3618 * Details, depending on @e cipher.
3619 */
3620 union
3621 {
3622 /**
3623 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3624 */
3625 struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message;
3626
3627 /**
3628 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3629 */
3630 struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message;
3631
3632 } details;
3633};
3634
3635
3636/**
3637 * Secret r for Cs denominations
3638 */
3639struct GNUNET_CRYPTO_CSPrivateRPairP
3640{
3641 struct GNUNET_CRYPTO_CsRSecret r[2];
3642};
3643
3644
3645/**
3646 * @brief Input needed for blinding a message.
3647 */
3648struct GNUNET_CRYPTO_BlindingInputValues
3649{
3650
3651 /**
3652 * Type of the signature.
3653 */
3654 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3655
3656 /**
3657 * Reference counter.
3658 */
3659 unsigned int rc;
3660
3661 /**
3662 * Details, depending on @e cipher.
3663 */
3664 union
3665 {
3666 /**
3667 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3668 */
3669 struct GNUNET_CRYPTO_CSPublicRPairP cs_values;
3670
3671 } details;
3672
3673};
3674
3675
3676/**
3677 * Nonce used to deterministiacally derive input values
3678 * used in multi-round blind signature protocols.
3679 */
3680union GNUNET_CRYPTO_BlindSessionNonce
3681{
3682 /**
3683 * Nonce used when signing with CS.
3684 */
3685 struct GNUNET_CRYPTO_CsSessionNonce cs_nonce;
3686};
3687
3688
3689/**
3690 * Compute blinding input values for a given @a nonce and
3691 * @a salt.
3692 *
3693 * @param bsign_priv private key to compute input values for
3694 * @param nonce session nonce to derive input values from
3695 * @param salt salt to include in derivation logic
3696 * @return blinding input values
3697 */
3698struct GNUNET_CRYPTO_BlindingInputValues *
3699GNUNET_CRYPTO_get_blinding_input_values (
3700 const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv,
3701 const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
3702 const char *salt);
3703
3704
3705/**
3706 * Decrement reference counter of a @a bsign_pub, and free it if it reaches zero.
3707 *
3708 * @param[in] bsign_pub key to free
3709 */
3710void
3711GNUNET_CRYPTO_blind_sign_pub_decref (
3712 struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
3713
3714
3715/**
3716 * Decrement reference counter of a @a bsign_priv, and free it if it reaches zero.
3717 *
3718 * @param[in] bsign_priv key to free
3719 */
3720void
3721GNUNET_CRYPTO_blind_sign_priv_decref (
3722 struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv);
3723
3724
3725/**
3726 * Decrement reference counter of a @a ub_sig, and free it if it reaches zero.
3727 *
3728 * @param[in] ub_sig signature to free
3729 */
3730void
3731GNUNET_CRYPTO_unblinded_sig_decref (
3732 struct GNUNET_CRYPTO_UnblindedSignature *ub_sig);
3733
3734
3735/**
3736 * Decrement reference counter of a @a blind_sig, and free it if it reaches zero.
3737 *
3738 * @param[in] blind_sig signature to free
3739 */
3740void
3741GNUNET_CRYPTO_blinded_sig_decref (
3742 struct GNUNET_CRYPTO_BlindedSignature *blind_sig);
3743
3744
3745/**
3746 * Decrement reference counter of a @a bm, and free it if it reaches zero.
3747 *
3748 * @param[in] bm blinded message to free
3749 */
3750void
3751GNUNET_CRYPTO_blinded_message_decref (
3752 struct GNUNET_CRYPTO_BlindedMessage *bm);
3753
3754
3755/**
3756 * Increment reference counter of the given @a bm.
3757 *
3758 * @param[in,out] bm blinded message to increment reference counter for
3759 * @return alias of @a bm with RC incremented
3760 */
3761struct GNUNET_CRYPTO_BlindedMessage *
3762GNUNET_CRYPTO_blinded_message_incref (
3763 struct GNUNET_CRYPTO_BlindedMessage *bm);
3764
3765
3766/**
3767 * Increment reference counter of the given @a bi.
3768 *
3769 * @param[in,out] bi blinding input values to increment reference counter for
3770 * @return alias of @a bi with RC incremented
3771 */
3772struct GNUNET_CRYPTO_BlindingInputValues *
3773GNUNET_CRYPTO_blinding_input_values_incref (
3774 struct GNUNET_CRYPTO_BlindingInputValues *bm);
3775
3776
3777/**
3778 * Decrement reference counter of the given @a bi, and free it if it reaches
3779 * zero.
3780 *
3781 * @param[in,out] bi blinding input values to decrement reference counter for
3782 */
3783void
3784GNUNET_CRYPTO_blinding_input_values_decref (
3785 struct GNUNET_CRYPTO_BlindingInputValues *bm);
3786
3787
3788/**
3789 * Increment reference counter of the given @a bsign_pub.
3790 *
3791 * @param[in,out] bsign_pub public key to increment reference counter for
3792 * @return alias of @a bsign_pub with RC incremented
3793 */
3794struct GNUNET_CRYPTO_BlindSignPublicKey *
3795GNUNET_CRYPTO_bsign_pub_incref (
3796 struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
3797
3798
3799/**
3800 * Increment reference counter of the given @a bsign_priv.
3801 *
3802 * @param[in,out] bsign_priv private key to increment reference counter for
3803 * @return alias of @a bsign_priv with RC incremented
3804 */
3805struct GNUNET_CRYPTO_BlindSignPrivateKey *
3806GNUNET_CRYPTO_bsign_priv_incref (
3807 struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv);
3808
3809
3810/**
3811 * Increment reference counter of the given @a ub_sig.
3812 *
3813 * @param[in,out] ub_sig signature to increment reference counter for
3814 * @return alias of @a ub_sig with RC incremented
3815 */
3816struct GNUNET_CRYPTO_UnblindedSignature *
3817GNUNET_CRYPTO_ub_sig_incref (struct GNUNET_CRYPTO_UnblindedSignature *ub_sig);
3818
3819
3820/**
3821 * Increment reference counter of the given @a blind_sig.
3822 *
3823 * @param[in,out] blind_sig signature to increment reference counter for
3824 * @return alias of @a blind_sig with RC incremented
3825 */
3826struct GNUNET_CRYPTO_BlindedSignature *
3827GNUNET_CRYPTO_blind_sig_incref (
3828 struct GNUNET_CRYPTO_BlindedSignature *blind_sig);
3829
3830
3831/**
3832 * Compare two denomination public keys.
3833 *
3834 * @param bp1 first key
3835 * @param bp2 second key
3836 * @return 0 if the keys are equal, otherwise -1 or 1
3837 */
3838int
3839GNUNET_CRYPTO_bsign_pub_cmp (
3840 const struct GNUNET_CRYPTO_BlindSignPublicKey *bp1,
3841 const struct GNUNET_CRYPTO_BlindSignPublicKey *bp2);
3842
3843
3844/**
3845 * Compare two denomination signatures.
3846 *
3847 * @param sig1 first signature
3848 * @param sig2 second signature
3849 * @return 0 if the keys are equal, otherwise -1 or 1
3850 */
3851int
3852GNUNET_CRYPTO_ub_sig_cmp (const struct GNUNET_CRYPTO_UnblindedSignature *sig1,
3853 const struct GNUNET_CRYPTO_UnblindedSignature *sig2);
3854
3855
3856/**
3857 * Compare two blinded denomination signatures.
3858 *
3859 * @param sig1 first signature
3860 * @param sig2 second signature
3861 * @return 0 if the keys are equal, otherwise -1 or 1
3862 */
3863int
3864GNUNET_CRYPTO_blind_sig_cmp (
3865 const struct GNUNET_CRYPTO_BlindedSignature *sig1,
3866 const struct GNUNET_CRYPTO_BlindedSignature *sig2);
3867
3868
3869/**
3870 * Compare two blinded messages.
3871 *
3872 * @param bp1 first blinded message
3873 * @param bp2 second blinded message
3874 * @return 0 if the keys are equal, otherwise -1 or 1
3875 */
3876int
3877GNUNET_CRYPTO_blinded_message_cmp (
3878 const struct GNUNET_CRYPTO_BlindedMessage *bp1,
3879 const struct GNUNET_CRYPTO_BlindedMessage *bp2);
3880
3881
3882/**
3883 * Initialize public-private key pair for blind signatures.
3884 *
3885 * For #GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int"
3886 * argument with the number of bits for 'n' (e.g. 2048) must
3887 * be passed.
3888 *
3889 * @param[out] bsign_priv where to write the private key with RC 1
3890 * @param[out] bsign_pub where to write the public key with RC 1
3891 * @param cipher which type of cipher to use
3892 * @param ... RSA key size (eg. 2048/3072/4096)
3893 * @return #GNUNET_OK on success, #GNUNET_NO if parameterst were invalid
3894 */
3895enum GNUNET_GenericReturnValue
3896GNUNET_CRYPTO_blind_sign_keys_create (
3897 struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv,
3898 struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub,
3899 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
3900 ...);
3901
3902
3903/**
3904 * Initialize public-private key pair for blind signatures.
3905 *
3906 * For #GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int"
3907 * argument with the number of bits for 'n' (e.g. 2048) must
3908 * be passed.
3909 *
3910 * @param[out] bsign_priv where to write the private key with RC 1
3911 * @param[out] bsign_pub where to write the public key with RC 1
3912 * @param cipher which type of cipher to use
3913 * @param ap RSA key size (eg. 2048/3072/4096)
3914 * @return #GNUNET_OK on success, #GNUNET_NO if parameterst were invalid
3915 */
3916enum GNUNET_GenericReturnValue
3917GNUNET_CRYPTO_blind_sign_keys_create_va (
3918 struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv,
3919 struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub,
3920 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
3921 va_list ap);
3922
3923
3924/**
3925 * @brief Type of blinding secrets. Must be exactly 32 bytes (DB).
3926 */
3927union GNUNET_CRYPTO_BlindingSecretP
3928{
3929 /**
3930 * Clause Schnorr nonce.
3931 */
3932 struct GNUNET_CRYPTO_CsBlindingNonce nonce;
3933
3934 /**
3935 * Variant for RSA for blind signatures.
3936 */
3937 struct GNUNET_CRYPTO_RsaBlindingKeySecret rsa_bks;
3938};
3939
3940
3941/**
3942 * Blind message for blind signing with @a dk using blinding secret @a coin_bks.
3943 *
3944 * @param bsign_pub public key to blind for
3945 * @param bks blinding secret to use
3946 * @param nonce nonce used to obtain @a alg_values
3947 * can be NULL if input values are not used for the cipher
3948 * @param message message to sign
3949 * @param message_size number of bytes in @a message
3950 * @param alg_values algorithm specific values to blind the @a message
3951 * @return blinded message to give to signer, NULL on error
3952 */
3953struct GNUNET_CRYPTO_BlindedMessage *
3954GNUNET_CRYPTO_message_blind_to_sign (
3955 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub,
3956 const union GNUNET_CRYPTO_BlindingSecretP *bks,
3957 const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
3958 const void *message,
3959 size_t message_size,
3960 const struct GNUNET_CRYPTO_BlindingInputValues *alg_values);
3961
3962
3963/**
3964 * Create blind signature.
3965 *
3966 * @param bsign_priv private key to use for signing
3967 * @param salt salt value to use for the HKDF,
3968 * can be NULL if input values are not used for the cipher
3969 * @param blinded_message the already blinded message to sign
3970 * @return blind signature with RC=1, NULL on failure
3971 */
3972struct GNUNET_CRYPTO_BlindedSignature *
3973GNUNET_CRYPTO_blind_sign (
3974 const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv,
3975 const char *salt,
3976 const struct GNUNET_CRYPTO_BlindedMessage *blinded_message);
3977
3978
3979/**
3980 * Unblind blind signature.
3981 *
3982 * @param blinded_sig the blind signature
3983 * @param bks blinding secret to use
3984 * @param message message that was supposedly signed
3985 * @param message_size number of bytes in @a message
3986 * @param alg_values algorithm specific values
3987 * @param bsign_pub public key used for signing
3988 * @return unblinded signature with RC=1, NULL on error
3989 */
3990struct GNUNET_CRYPTO_UnblindedSignature *
3991GNUNET_CRYPTO_blind_sig_unblind (
3992 const struct GNUNET_CRYPTO_BlindedSignature *blinded_sig,
3993 const union GNUNET_CRYPTO_BlindingSecretP *bks,
3994 const void *message,
3995 size_t message_size,
3996 const struct GNUNET_CRYPTO_BlindingInputValues *alg_values,
3997 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
3998
3999
4000/**
4001 * Verify signature made blindly.
4002 *
4003 * @param bsign_pub public key
4004 * @param ub_sig signature made blindly with the private key
4005 * @param message message that was supposedly signed
4006 * @param message_size number of bytes in @a message
4007 * @return #GNUNET_OK if the signature is valid
4008 */
4009enum GNUNET_GenericReturnValue
4010GNUNET_CRYPTO_blind_sig_verify (
4011 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub,
4012 const struct GNUNET_CRYPTO_UnblindedSignature *ub_sig,
4013 const void *message,
4014 size_t message_size);
4015
4016
4017/**
4018 * Get the compacted length of a #GNUNET_CRYPTO_PublicKey.
4019 * Compacted means that it returns the minimum number of bytes this
4020 * key is long, as opposed to the union structure inside
4021 * #GNUNET_CRYPTO_PublicKey.
4022 * Useful for compact serializations.
4023 *
4024 * @param key the key.
4025 * @return -1 on error, else the compacted length of the key.
4026 */
4027ssize_t
4028GNUNET_CRYPTO_public_key_get_length (const struct
4029 GNUNET_CRYPTO_PublicKey *key);
4030
4031/**
4032 * Reads a #GNUNET_CRYPTO_PublicKey from a compact buffer.
4033 * The buffer has to contain at least the compacted length of
4034 * a #GNUNET_CRYPTO_PublicKey in bytes.
4035 * If the buffer is too small, the function returns -1 as error.
4036 * If the buffer does not contain a valid key, it returns -2 as error.
4037 *
4038 * @param buffer the buffer
4039 * @param len the length of buffer
4040 * @param key the key
4041 * @param the amount of bytes read from the buffer
4042 * @return #GNUNET_SYSERR on error
4043 */
4044enum GNUNET_GenericReturnValue
4045GNUNET_CRYPTO_read_public_key_from_buffer (
4046 const void *buffer,
4047 size_t len,
4048 struct GNUNET_CRYPTO_PublicKey *key,
4049 size_t *read);
4050
4051/**
4052 * Get the compacted length of a #GNUNET_CRYPTO_PrivateKey.
4053 * Compacted means that it returns the minimum number of bytes this
4054 * key is long, as opposed to the union structure inside
4055 * #GNUNET_CRYPTO_PrivateKey.
4056 * Useful for compact serializations.
4057 *
4058 * @param key the key.
4059 * @return -1 on error, else the compacted length of the key.
4060 */
4061ssize_t
4062GNUNET_CRYPTO_private_key_get_length (
4063 const struct GNUNET_CRYPTO_PrivateKey *key);
4064
4065
4066/**
4067 * Writes a #GNUNET_CRYPTO_PublicKey to a compact buffer.
4068 * The buffer requires space for at least the compacted length of
4069 * a #GNUNET_CRYPTO_PublicKey in bytes.
4070 * If the buffer is too small, the function returns -1 as error.
4071 * If the key is not valid, it returns -2 as error.
4072 *
4073 * @param key the key
4074 * @param buffer the buffer
4075 * @param len the length of buffer
4076 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4077 */
4078ssize_t
4079GNUNET_CRYPTO_write_public_key_to_buffer (const struct
4080 GNUNET_CRYPTO_PublicKey *key,
4081 void*buffer,
4082 size_t len);
4083
4084
4085/**
4086 * Reads a #GNUNET_CRYPTO_PrivateKey from a compact buffer.
4087 * The buffer has to contain at least the compacted length of
4088 * a #GNUNET_CRYPTO_PrivateKey in bytes.
4089 * If the buffer is too small, the function returns GNUNET_SYSERR as error.
4090 *
4091 * @param buffer the buffer
4092 * @param len the length of buffer
4093 * @param key the key
4094 * @param the amount of bytes read from the buffer
4095 * @return #GNUNET_SYSERR on error
4096 */
4097enum GNUNET_GenericReturnValue
4098GNUNET_CRYPTO_read_private_key_from_buffer (
4099 const void*buffer,
4100 size_t len,
4101 struct GNUNET_CRYPTO_PrivateKey *key,
4102 size_t *read);
4103
4104
4105/**
4106 * Writes a #GNUNET_CRYPTO_PrivateKey to a compact buffer.
4107 * The buffer requires space for at least the compacted length of
4108 * a #GNUNET_CRYPTO_PrivateKey in bytes.
4109 * If the buffer is too small, the function returns -1 as error.
4110 * If the key is not valid, it returns -2 as error.
4111 *
4112 * @param key the key
4113 * @param buffer the buffer
4114 * @param len the length of buffer
4115 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4116 */
4117ssize_t
4118GNUNET_CRYPTO_write_private_key_to_buffer (
4119 const struct GNUNET_CRYPTO_PrivateKey *key,
4120 void*buffer,
4121 size_t len);
4122
4123
4124/**
4125 * Get the compacted length of a #GNUNET_CRYPTO_Signature.
4126 * Compacted means that it returns the minimum number of bytes this
4127 * signature is long, as opposed to the union structure inside
4128 * #GNUNET_CRYPTO_Signature.
4129 * Useful for compact serializations.
4130 *
4131 * @param sig the signature.
4132 * @return -1 on error, else the compacted length of the signature.
4133 */
4134ssize_t
4135GNUNET_CRYPTO_signature_get_length (
4136 const struct GNUNET_CRYPTO_Signature *sig);
4137
4138
4139/**
4140 * Get the compacted length of a signature by type.
4141 * Compacted means that it returns the minimum number of bytes this
4142 * signature is long, as opposed to the union structure inside
4143 * #GNUNET_CRYPTO_Signature.
4144 * Useful for compact serializations.
4145 *
4146 * @param sig the signature.
4147 * @return -1 on error, else the compacted length of the signature.
4148 */
4149ssize_t
4150GNUNET_CRYPTO_signature_get_raw_length_by_type (uint32_t type);
4151
4152
4153/**
4154 * Reads a #GNUNET_CRYPTO_Signature from a compact buffer.
4155 * The buffer has to contain at least the compacted length of
4156 * a #GNUNET_CRYPTO_Signature in bytes.
4157 * If the buffer is too small, the function returns -1 as error.
4158 * If the buffer does not contain a valid key, it returns -2 as error.
4159 *
4160 * @param sig the signature
4161 * @param buffer the buffer
4162 * @param len the length of buffer
4163 * @return -1 or -2 on error, else the amount of bytes read from the buffer
4164 */
4165ssize_t
4166GNUNET_CRYPTO_read_signature_from_buffer (
4167 struct GNUNET_CRYPTO_Signature *sig,
4168 const void*buffer,
4169 size_t len);
4170
4171
4172/**
4173 * Writes a #GNUNET_CRYPTO_Signature to a compact buffer.
4174 * The buffer requires space for at least the compacted length of
4175 * a #GNUNET_CRYPTO_Signature in bytes.
4176 * If the buffer is too small, the function returns -1 as error.
4177 * If the key is not valid, it returns -2 as error.
4178 *
4179 * @param sig the signature
4180 * @param buffer the buffer
4181 * @param len the length of buffer
4182 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4183 */
4184ssize_t
4185GNUNET_CRYPTO_write_signature_to_buffer (
4186 const struct GNUNET_CRYPTO_Signature *sig,
4187 void*buffer,
4188 size_t len);
4189
4190
4191/**
4192 * @brief Sign a given block.
4193 *
4194 * The @a purpose data is the beginning of the data of which the signature is
4195 * to be created. The `size` field in @a purpose must correctly indicate the
4196 * number of bytes of the data structure, including its header. If possible,
4197 * use #GNUNET_CRYPTO_sign() instead of this function.
4198 *
4199 * @param priv private key to use for the signing
4200 * @param purpose what to sign (size, purpose)
4201 * @param[out] sig where to write the signature
4202 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
4203 */
4204enum GNUNET_GenericReturnValue
4205GNUNET_CRYPTO_sign_ (
4206 const struct GNUNET_CRYPTO_PrivateKey *priv,
4207 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
4208 struct GNUNET_CRYPTO_Signature *sig);
4209
4210/**
4211 * @brief Sign a given block.
4212 *
4213 * The @a purpose data is the beginning of the data of which the signature is
4214 * to be created. The `size` field in @a purpose must correctly indicate the
4215 * number of bytes of the data structure, including its header.
4216 * The signature payload and length depends on the key type.
4217 *
4218 * @param priv private key to use for the signing
4219 * @param purpose what to sign (size, purpose)
4220 * @param[out] sig where to write the signature
4221 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
4222 */
4223enum GNUNET_GenericReturnValue
4224GNUNET_CRYPTO_sign_raw_ (
4225 const struct GNUNET_CRYPTO_PrivateKey *priv,
4226 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
4227 unsigned char *sig);
4228
4229
4230/**
4231 * @brief Sign a given block with #GNUNET_CRYPTO_PrivateKey.
4232 *
4233 * The @a ps data must be a fixed-size struct for which the signature is to be
4234 * created. The `size` field in @a ps->purpose must correctly indicate the
4235 * number of bytes of the data structure, including its header.
4236 *
4237 * @param priv private key to use for the signing
4238 * @param ps packed struct with what to sign, MUST begin with a purpose
4239 * @param[out] sig where to write the signature
4240 */
4241#define GNUNET_CRYPTO_sign(priv,ps,sig) do { \
4242 /* check size is set correctly */ \
4243 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
4244 /* check 'ps' begins with the purpose */ \
4245 GNUNET_static_assert (((void*) (ps)) == \
4246 ((void*) &(ps)->purpose)); \
4247 GNUNET_assert (GNUNET_OK == \
4248 GNUNET_CRYPTO_sign_ (priv, \
4249 &(ps)->purpose, \
4250 sig)); \
4251} while (0)
4252
4253
4254/**
4255 * @brief Verify a given signature.
4256 *
4257 * The @a validate data is the beginning of the data of which the signature
4258 * is to be verified. The `size` field in @a validate must correctly indicate
4259 * the number of bytes of the data structure, including its header. If @a
4260 * purpose does not match the purpose given in @a validate (the latter must be
4261 * in big endian), signature verification fails. If possible,
4262 * use #GNUNET_CRYPTO_signature_verify() instead of this function (only if @a validate
4263 * is not fixed-size, you must use this function directly).
4264 *
4265 * @param purpose what is the purpose that the signature should have?
4266 * @param validate block to validate (size, purpose, data)
4267 * @param sig signature that is being validated
4268 * @param pub public key of the signer
4269 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
4270 */
4271enum GNUNET_GenericReturnValue
4272GNUNET_CRYPTO_signature_verify_ (
4273 uint32_t purpose,
4274 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
4275 const struct GNUNET_CRYPTO_Signature *sig,
4276 const struct GNUNET_CRYPTO_PublicKey *pub);
4277
4278/**
4279 * @brief Verify a given signature.
4280 *
4281 * The @a validate data is the beginning of the data of which the signature
4282 * is to be verified. The `size` field in @a validate must correctly indicate
4283 * the number of bytes of the data structure, including its header. If @a
4284 * purpose does not match the purpose given in @a validate (the latter must be
4285 * in big endian), signature verification fails.
4286 *
4287 * @param purpose what is the purpose that the signature should have?
4288 * @param validate block to validate (size, purpose, data)
4289 * @param sig signature that is being validated
4290 * @param pub public key of the signer
4291 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
4292 */
4293enum GNUNET_GenericReturnValue
4294GNUNET_CRYPTO_signature_verify_raw_ (
4295 uint32_t purpose,
4296 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
4297 const unsigned char *sig,
4298 const struct GNUNET_CRYPTO_PublicKey *pub);
4299
4300
4301/**
4302 * @brief Verify a given signature with #GNUNET_CRYPTO_PublicKey.
4303 *
4304 * The @a ps data must be a fixed-size struct for which the signature is to be
4305 * created. The `size` field in @a ps->purpose must correctly indicate the
4306 * number of bytes of the data structure, including its header.
4307 *
4308 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
4309 * (except in host byte order)
4310 * @param ps packed struct with what to sign, MUST begin with a purpose
4311 * @param sig where to read the signature from
4312 * @param pub public key to use for the verifying
4313 */
4314#define GNUNET_CRYPTO_signature_verify(purp,ps,sig,pub) ({ \
4315 /* check size is set correctly */ \
4316 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
4317 /* check 'ps' begins with the purpose */ \
4318 GNUNET_static_assert (((void*) (ps)) == \
4319 ((void*) &(ps)->purpose)); \
4320 GNUNET_CRYPTO_signature_verify_ (purp, \
4321 &(ps)->purpose, \
4322 sig, \
4323 pub); \
4324 })
4325
4326
4327/**
4328 * Encrypt a block with #GNUNET_CRYPTO_PublicKey and derives a
4329 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
4330 * using ecdh to derive a symmetric key.
4331 *
4332 * @param block the block to encrypt
4333 * @param size the size of the @a block
4334 * @param pub public key to use for ecdh
4335 * @param ecc where to write the ecc public key
4336 * @param result the output parameter in which to store the encrypted result
4337 * can be the same or overlap with @c block
4338 * @returns the size of the encrypted block, -1 for errors.
4339 * Due to the use of CFB and therefore an effective stream cipher,
4340 * this size should be the same as @c len.
4341 */
4342ssize_t
4343GNUNET_CRYPTO_encrypt_old (const void *block,
4344 size_t size,
4345 const struct GNUNET_CRYPTO_PublicKey *pub,
4346 struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
4347 void *result);
4348
4349
4350/**
4351 * Decrypt a given block with #GNUNET_CRYPTO_PrivateKey and a given
4352 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
4353 *
4354 * @param block the data to decrypt, encoded as returned by encrypt
4355 * @param size the size of the @a block to decrypt
4356 * @param priv private key to use for ecdh
4357 * @param ecc the ecc public key
4358 * @param result address to store the result at
4359 * can be the same or overlap with @c block
4360 * @return -1 on failure, size of decrypted block on success.
4361 * Due to the use of CFB and therefore an effective stream cipher,
4362 * this size should be the same as @c size.
4363 */
4364ssize_t
4365GNUNET_CRYPTO_decrypt_old (
4366 const void *block,
4367 size_t size,
4368 const struct GNUNET_CRYPTO_PrivateKey *priv,
4369 const struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
4370 void *result);
4371
4372#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES (crypto_secretbox_MACBYTES \
4373 + sizeof (struct \
4374 GNUNET_CRYPTO_FoKemC))
4375
4376/**
4377 * Encrypt a block with #GNUNET_CRYPTO_PublicKey and derives a
4378 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
4379 * using ecdh to derive a symmetric key.
4380 *
4381 * Note that the result buffer for the ciphertext must be the length of
4382 * the message to encrypt plus #GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES.
4383 *
4384 * @param block the block to encrypt
4385 * @param size the size of the @a block
4386 * @param pub public key to encrypt for
4387 * @param result the output parameter in which to store the encrypted result
4388 * can be the same or overlap with @c block
4389 * @returns GNUNET_OK on success.
4390 */
4391enum GNUNET_GenericReturnValue
4392GNUNET_CRYPTO_encrypt (const void *block,
4393 size_t size,
4394 const struct GNUNET_CRYPTO_PublicKey *pub,
4395 void *result,
4396 size_t result_size);
4397
4398
4399/**
4400 * Decrypt a given block with #GNUNET_CRYPTO_PrivateKey and a given
4401 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
4402 *
4403 * @param block the data to decrypt, encoded as returned by encrypt
4404 * @param size the size of the @a block to decrypt
4405 * @param priv private key to use for ecdh
4406 * @param result address to store the result at
4407 * can be the same or overlap with @c block
4408 * @returns GNUNET_OK on success.
4409 */
4410enum GNUNET_GenericReturnValue
4411GNUNET_CRYPTO_decrypt (const void *block,
4412 size_t size,
4413 const struct GNUNET_CRYPTO_PrivateKey *priv,
4414 void *result,
4415 size_t result_size);
4416
4417
4418/**
4419 * Creates a (Base32) string representation of the public key.
4420 * The resulting string encodes a compacted representation of the key.
4421 * See also #GNUNET_CRYPTO_key_get_length.
4422 *
4423 * @param key the key.
4424 * @return the string representation of the key, or NULL on error.
4425 */
4426char *
4427GNUNET_CRYPTO_public_key_to_string (
4428 const struct GNUNET_CRYPTO_PublicKey *key);
4429
4430
4431/**
4432 * Creates a (Base32) string representation of the private key.
4433 * The resulting string encodes a compacted representation of the key.
4434 * See also #GNUNET_CRYPTO_key_get_length.
4435 *
4436 * @param key the key.
4437 * @return the string representation of the key, or NULL on error.
4438 */
4439char *
4440GNUNET_CRYPTO_private_key_to_string (
4441 const struct GNUNET_CRYPTO_PrivateKey *key);
4442
4443
4444/**
4445 * Parses a (Base32) string representation of the public key.
4446 * See also #GNUNET_CRYPTO_public_key_to_string.
4447 *
4448 * @param str the encoded key.
4449 * @param key where to write the key.
4450 * @return GNUNET_SYSERR on error.
4451 */
4452enum GNUNET_GenericReturnValue
4453GNUNET_CRYPTO_public_key_from_string (const char*str,
4454 struct GNUNET_CRYPTO_PublicKey *key);
4455
4456
4457/**
4458 * Parses a (Base32) string representation of the private key.
4459 * See also #GNUNET_CRYPTO_private_key_to_string.
4460 *
4461 * @param str the encoded key.
4462 * @param key where to write the key.
4463 * @return GNUNET_SYSERR on error.
4464 */
4465enum GNUNET_GenericReturnValue
4466GNUNET_CRYPTO_private_key_from_string (const char*str,
4467 struct GNUNET_CRYPTO_PrivateKey *key);
4468
4469
4470/**
4471 * Retrieves the public key representation of a private key.
4472 *
4473 * @param privkey the private key.
4474 * @param key the public key result.
4475 * @return GNUNET_SYSERR on error.
4476 */
4477enum GNUNET_GenericReturnValue
4478GNUNET_CRYPTO_key_get_public (const struct
4479 GNUNET_CRYPTO_PrivateKey *privkey,
4480 struct GNUNET_CRYPTO_PublicKey *key);
4481
2439#if 0 /* keep Emacsens' auto-indent happy */ 4482#if 0 /* keep Emacsens' auto-indent happy */
2440{ 4483{
2441#endif 4484#endif
@@ -2446,4 +4489,7 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
2446 4489
2447/* ifndef GNUNET_CRYPTO_LIB_H */ 4490/* ifndef GNUNET_CRYPTO_LIB_H */
2448#endif 4491#endif
4492
4493/** @} */ /* end of group addition */
4494
2449/* end of gnunet_crypto_lib.h */ 4495/* end of gnunet_crypto_lib.h */
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h
index 38acecc48..967170085 100644
--- a/src/include/gnunet_curl_lib.h
+++ b/src/include/gnunet_curl_lib.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup lib_extra Additional libraries
22 * @{
23 *
21 * @file src/include/gnunet_curl_lib.h 24 * @file src/include/gnunet_curl_lib.h
22 * @brief library to make it easy to download JSON replies over HTTP 25 * @brief library to make it easy to download JSON replies over HTTP
23 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 26 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
@@ -29,13 +32,8 @@
29 */ 32 */
30#ifndef GNUNET_CURL_LIB_H 33#ifndef GNUNET_CURL_LIB_H
31#define GNUNET_CURL_LIB_H 34#define GNUNET_CURL_LIB_H
32#if HAVE_LIBCURL 35
33#include <curl/curl.h> 36#include <curl/curl.h>
34#elif HAVE_LIBGNURL
35#include <gnurl/curl.h>
36#else
37#error "needs curl or gnurl"
38#endif
39#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
40 38
41 39
@@ -230,7 +228,7 @@ typedef void
230 * be executed AND cleaned up 228 * be executed AND cleaned up
231 * @param jcc callback to invoke upon completion 229 * @param jcc callback to invoke upon completion
232 * @param jcc_cls closure for @a jcc 230 * @param jcc_cls closure for @a jcc
233 * @return NULL on error (in this case, @eh is still released!) 231 * @return NULL on error (in this case, @a eh is still released!)
234 */ 232 */
235struct GNUNET_CURL_Job * 233struct GNUNET_CURL_Job *
236GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, 234GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
@@ -252,7 +250,7 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
252 * be executed AND cleaned up 250 * be executed AND cleaned up
253 * @param jcc callback to invoke upon completion 251 * @param jcc callback to invoke upon completion
254 * @param jcc_cls closure for @a jcc 252 * @param jcc_cls closure for @a jcc
255 * @return NULL on error (in this case, @eh is still released!) 253 * @return NULL on error (in this case, @a eh is still released!)
256 */ 254 */
257struct GNUNET_CURL_Job * 255struct GNUNET_CURL_Job *
258GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx, 256GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx,
@@ -310,7 +308,7 @@ GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx,
310 * @param job_headers extra headers to add for this request 308 * @param job_headers extra headers to add for this request
311 * @param jcc callback to invoke upon completion 309 * @param jcc callback to invoke upon completion
312 * @param jcc_cls closure for @a jcc 310 * @param jcc_cls closure for @a jcc
313 * @return NULL on error (in this case, @eh is still released!) 311 * @return NULL on error (in this case, @a eh is still released!)
314 */ 312 */
315struct GNUNET_CURL_Job * 313struct GNUNET_CURL_Job *
316GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, 314GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
@@ -330,10 +328,9 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
330 * @param eh curl easy handle for the request, will 328 * @param eh curl easy handle for the request, will
331 * be executed AND cleaned up 329 * be executed AND cleaned up
332 * @param job_headers extra headers to add for this request 330 * @param job_headers extra headers to add for this request
333 * @param max_reply_size largest acceptable response body
334 * @param jcc callback to invoke upon completion 331 * @param jcc callback to invoke upon completion
335 * @param jcc_cls closure for @a jcc 332 * @param jcc_cls closure for @a jcc
336 * @return NULL on error (in this case, @eh is still released!) 333 * @return NULL on error (in this case, @a eh is still released!)
337 */ 334 */
338struct GNUNET_CURL_Job * 335struct GNUNET_CURL_Job *
339GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx, 336GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx,
@@ -436,11 +433,13 @@ GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
436 * 433 *
437 * @returns #GNUNET_YES iff given a valid scope ID 434 * @returns #GNUNET_YES iff given a valid scope ID
438 */ 435 */
439int 436enum GNUNET_GenericReturnValue
440GNUNET_CURL_is_valid_scope_id (const char *scope_id); 437GNUNET_CURL_is_valid_scope_id (const char *scope_id);
441 438
442 439
443#endif 440#endif
444/** @} */ /* end of group */ 441/** @} */ /* end of group */
445 442
443/** @} */ /* end of group addition to lib_extra */
444
446/* end of gnunet_curl_lib.h */ 445/* end of gnunet_curl_lib.h */
diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h
index 40885803b..2c7bf1e8f 100644
--- a/src/include/gnunet_datacache_lib.h
+++ b/src/include/gnunet_datacache_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -37,8 +40,10 @@
37#ifndef GNUNET_DATACACHE_LIB_H 40#ifndef GNUNET_DATACACHE_LIB_H
38#define GNUNET_DATACACHE_LIB_H 41#define GNUNET_DATACACHE_LIB_H
39 42
43
40#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
41#include "gnunet_block_lib.h" 45#include "gnunet_block_lib.h"
46#include "gnunet_dht_service.h"
42 47
43#ifdef __cplusplus 48#ifdef __cplusplus
44extern "C" 49extern "C"
@@ -50,6 +55,59 @@ extern "C"
50 55
51 56
52/** 57/**
58 * Information about a block stored in the datacache.
59 */
60struct GNUNET_DATACACHE_Block
61{
62 /**
63 * Key of the block.
64 */
65 struct GNUNET_HashCode key;
66
67 /**
68 * When does the block expire?
69 */
70 struct GNUNET_TIME_Absolute expiration_time;
71
72 /**
73 * If the path was truncated, this is the peer
74 * ID at which the path was truncated.
75 */
76 struct GNUNET_PeerIdentity trunc_peer;
77
78 /**
79 * PUT path taken by the block, array of peer identities.
80 */
81 const struct GNUNET_DHT_PathElement *put_path;
82
83 /**
84 * Actual block data.
85 */
86 const void *data;
87
88 /**
89 * Number of bytes in @a data.
90 */
91 size_t data_size;
92
93 /**
94 * Length of the @e put_path array.
95 */
96 unsigned int put_path_length;
97
98 /**
99 * Type of the block.
100 */
101 enum GNUNET_BLOCK_Type type;
102
103 /**
104 * Options for routing for the block.
105 */
106 enum GNUNET_DHT_RouteOption ro;
107};
108
109
110/**
53 * Handle to the cache. 111 * Handle to the cache.
54 */ 112 */
55struct GNUNET_DATACACHE_Handle; 113struct GNUNET_DATACACHE_Handle;
@@ -80,50 +138,26 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
80 * An iterator over a set of items stored in the datacache. 138 * An iterator over a set of items stored in the datacache.
81 * 139 *
82 * @param cls closure 140 * @param cls closure
83 * @param key key for the content 141 * @param block a block from the datacache
84 * @param data_size number of bytes in @a data
85 * @param data content stored
86 * @param type type of the content
87 * @param exp when will the content expire?
88 * @param path_info_len number of entries in @a path_info
89 * @param path_info a path through the network
90 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort 142 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
91 */ 143 */
92typedef int 144typedef enum GNUNET_GenericReturnValue
93(*GNUNET_DATACACHE_Iterator) (void *cls, 145(*GNUNET_DATACACHE_Iterator)(void *cls,
94 const struct GNUNET_HashCode *key, 146 const struct GNUNET_DATACACHE_Block *block);
95 size_t data_size,
96 const char *data,
97 enum GNUNET_BLOCK_Type type,
98 struct GNUNET_TIME_Absolute exp,
99 unsigned int path_info_len,
100 const struct GNUNET_PeerIdentity *path_info);
101 147
102 148
103/** 149/**
104 * Store an item in the datacache. 150 * Store an item in the datacache.
105 * 151 *
106 * @param h handle to the datacache 152 * @param h handle to the datacache
107 * @param key key to store data under 153 * @param xor_distance how close is the block's key to our pid?
108 * @param how close is @a key to our pid? 154 * @param block actual block data to store
109 * @param data_size number of bytes in @a data
110 * @param data data to store
111 * @param type type of the value
112 * @param discard_time when to discard the value in any case
113 * @param path_info_len number of entries in @a path_info
114 * @param path_info a path through the network
115 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate 155 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
116 */ 156 */
117int 157enum GNUNET_GenericReturnValue
118GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, 158GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
119 const struct GNUNET_HashCode *key,
120 uint32_t xor_distance, 159 uint32_t xor_distance,
121 size_t data_size, 160 const struct GNUNET_DATACACHE_Block *block);
122 const char *data,
123 enum GNUNET_BLOCK_Type type,
124 struct GNUNET_TIME_Absolute discard_time,
125 unsigned int path_info_len,
126 const struct GNUNET_PeerIdentity *path_info);
127 161
128 162
129/** 163/**
@@ -146,20 +180,6 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
146 180
147 181
148/** 182/**
149 * Obtain a random element from the datacache.
150 *
151 * @param h handle to the datacache
152 * @param iter maybe NULL (to just count)
153 * @param iter_cls closure for @a iter
154 * @return the number of results found (zero or 1)
155 */
156unsigned int
157GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
158 GNUNET_DATACACHE_Iterator iter,
159 void *iter_cls);
160
161
162/**
163 * Iterate over the results that are "close" to a particular key in 183 * Iterate over the results that are "close" to a particular key in
164 * the datacache. "close" is defined as numerically larger than @a 184 * the datacache. "close" is defined as numerically larger than @a
165 * key (when interpreted as a circular address space), with small 185 * key (when interpreted as a circular address space), with small
@@ -167,6 +187,7 @@ GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
167 * 187 *
168 * @param h handle to the datacache 188 * @param h handle to the datacache
169 * @param key area of the keyspace to look into 189 * @param key area of the keyspace to look into
190 * @param type entries of which type are relevant?
170 * @param num_results number of results that should be returned to @a iter 191 * @param num_results number of results that should be returned to @a iter
171 * @param iter maybe NULL (to just count) 192 * @param iter maybe NULL (to just count)
172 * @param iter_cls closure for @a iter 193 * @param iter_cls closure for @a iter
@@ -175,6 +196,7 @@ GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
175unsigned int 196unsigned int
176GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h, 197GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
177 const struct GNUNET_HashCode *key, 198 const struct GNUNET_HashCode *key,
199 enum GNUNET_BLOCK_Type type,
178 unsigned int num_results, 200 unsigned int num_results,
179 GNUNET_DATACACHE_Iterator iter, 201 GNUNET_DATACACHE_Iterator iter,
180 void *iter_cls); 202 void *iter_cls);
@@ -190,3 +212,5 @@ GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
190#endif 212#endif
191 213
192/** @} */ /* end of group */ 214/** @} */ /* end of group */
215
216/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h
index d7fa8fde0..e144e155e 100644
--- a/src/include/gnunet_datacache_plugin.h
+++ b/src/include/gnunet_datacache_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef PLUGIN_DATACACHE_H 34#ifndef PLUGIN_DATACACHE_H
32#define PLUGIN_DATACACHE_H 35#define PLUGIN_DATACACHE_H
33 36
37
34#include "gnunet_datacache_lib.h" 38#include "gnunet_datacache_lib.h"
35 39
36#ifdef __cplusplus 40#ifdef __cplusplus
@@ -105,25 +109,15 @@ struct GNUNET_DATACACHE_PluginFunctions
105 * Store an item in the datastore. 109 * Store an item in the datastore.
106 * 110 *
107 * @param cls closure (internal context for the plugin) 111 * @param cls closure (internal context for the plugin)
108 * @param key key to store the value under
109 * @param xor_distance how close is @a key to our PID? 112 * @param xor_distance how close is @a key to our PID?
110 * @param size number of bytes in @a data 113 * @param block data to store
111 * @param data data to store
112 * @param type type of the value
113 * @param discard_time when to discard the value in any case
114 * @param path_info_len number of entries in @a path_info
115 * @param path_info a path through the network
116 * @return 0 if duplicate, -1 on error, number of bytes used otherwise 114 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
117 */ 115 */
118 ssize_t (*put) (void *cls, 116 ssize_t
119 const struct GNUNET_HashCode *key, 117 (*put) (void *cls,
120 uint32_t xor_distance, 118 uint32_t xor_distance,
121 size_t size, 119 const struct GNUNET_DATACACHE_Block *block);
122 const char *data, 120
123 enum GNUNET_BLOCK_Type type,
124 struct GNUNET_TIME_Absolute discard_time,
125 unsigned int path_info_len,
126 const struct GNUNET_PeerIdentity *path_info);
127 121
128 /** 122 /**
129 * Iterate over the results for a particular key 123 * Iterate over the results for a particular key
@@ -136,11 +130,13 @@ struct GNUNET_DATACACHE_PluginFunctions
136 * @param iter_cls closure for @a iter 130 * @param iter_cls closure for @a iter
137 * @return the number of results found 131 * @return the number of results found
138 */ 132 */
139 unsigned int (*get) (void *cls, 133 unsigned int
140 const struct GNUNET_HashCode *key, 134 (*get) (void *cls,
141 enum GNUNET_BLOCK_Type type, 135 const struct GNUNET_HashCode *key,
142 GNUNET_DATACACHE_Iterator iter, 136 enum GNUNET_BLOCK_Type type,
143 void *iter_cls); 137 GNUNET_DATACACHE_Iterator iter,
138 void *iter_cls);
139
144 140
145 /** 141 /**
146 * Delete the entry with the lowest expiration value 142 * Delete the entry with the lowest expiration value
@@ -149,39 +145,32 @@ struct GNUNET_DATACACHE_PluginFunctions
149 * @param cls closure (internal context for the plugin) 145 * @param cls closure (internal context for the plugin)
150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 146 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
151 */ 147 */
152 int (*del) (void *cls); 148 enum GNUNET_GenericReturnValue
153 149 (*del)(void *cls);
154 /**
155 * Return a random value from the datastore.
156 *
157 * @param cls closure (internal context for the plugin)
158 * @param iter maybe NULL (to just count)
159 * @param iter_cls closure for @a iter
160 * @return the number of results found (zero or one)
161 */
162 unsigned int (*get_random) (void *cls,
163 GNUNET_DATACACHE_Iterator iter,
164 void *iter_cls);
165 150
166 151
167 /** 152 /**
168 * Iterate over the results that are "close" to a particular key in 153 * Iterate over the results that are "close" to a particular key in the
169 * the datacache. "close" is defined as numerically larger than @a 154 * datacache. "close" is defined as returning the @a num_results that are
170 * key (when interpreted as a circular address space), with small 155 * numerically closest and larger than @a key and also @a num_results that
171 * distance. 156 * are numerically lower than @a key. Thus, the maximum number of results
157 * returned is actually twice @a num_results.
172 * 158 *
173 * @param cls closure (internal context for the plugin) 159 * @param cls closure (internal context for the plugin)
174 * @param key area of the keyspace to look into 160 * @param key area of the keyspace to look into
175 * @param num_results number of results that should be returned to @a iter 161 * @param type desired block type for the replies
162 * @param num_results half the number of results that should be returned to @a iter
176 * @param iter maybe NULL (to just count) 163 * @param iter maybe NULL (to just count)
177 * @param iter_cls closure for @a iter 164 * @param iter_cls closure for @a iter
178 * @return the number of results found 165 * @return the number of results found
179 */ 166 */
180 unsigned int (*get_closest) (void *cls, 167 unsigned int
181 const struct GNUNET_HashCode *key, 168 (*get_closest) (void *cls,
182 unsigned int num_results, 169 const struct GNUNET_HashCode *key,
183 GNUNET_DATACACHE_Iterator iter, 170 enum GNUNET_BLOCK_Type type,
184 void *iter_cls); 171 unsigned int num_results,
172 GNUNET_DATACACHE_Iterator iter,
173 void *iter_cls);
185}; 174};
186 175
187 176
@@ -195,3 +184,5 @@ struct GNUNET_DATACACHE_PluginFunctions
195#endif 184#endif
196 185
197/** @} */ /* end of group */ 186/** @} */ /* end of group */
187
188/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h
index 113f6b2f2..c4f31c7ce 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2 File sharing and support services/libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef PLUGIN_DATASTORE_H 34#ifndef PLUGIN_DATASTORE_H
32#define PLUGIN_DATASTORE_H 35#define PLUGIN_DATASTORE_H
33 36
37
34#include "gnunet_block_lib.h" 38#include "gnunet_block_lib.h"
35#include "gnunet_configuration_lib.h" 39#include "gnunet_configuration_lib.h"
36#include "gnunet_datastore_service.h" 40#include "gnunet_datastore_service.h"
@@ -98,17 +102,17 @@ struct GNUNET_DATASTORE_PluginEnvironment
98 * @return #GNUNET_OK to keep the item 102 * @return #GNUNET_OK to keep the item
99 * #GNUNET_NO to delete the item 103 * #GNUNET_NO to delete the item
100 */ 104 */
101typedef int 105typedef enum GNUNET_GenericReturnValue
102(*PluginDatumProcessor) (void *cls, 106(*PluginDatumProcessor)(void *cls,
103 const struct GNUNET_HashCode *key, 107 const struct GNUNET_HashCode *key,
104 uint32_t size, 108 uint32_t size,
105 const void *data, 109 const void *data,
106 enum GNUNET_BLOCK_Type type, 110 enum GNUNET_BLOCK_Type type,
107 uint32_t priority, 111 uint32_t priority,
108 uint32_t anonymity, 112 uint32_t anonymity,
109 uint32_t replication, 113 uint32_t replication,
110 struct GNUNET_TIME_Absolute expiration, 114 struct GNUNET_TIME_Absolute expiration,
111 uint64_t uid); 115 uint64_t uid);
112 116
113 117
114/** 118/**
@@ -377,3 +381,5 @@ struct GNUNET_DATASTORE_PluginFunctions
377#endif 381#endif
378 382
379/** @} */ /* end of group */ 383/** @} */ /* end of group */
384
385/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h
index c99db67bc..153387238 100644
--- a/src/include/gnunet_datastore_service.h
+++ b/src/include/gnunet_datastore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2 File sharing and support services/libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -39,6 +42,7 @@
39#ifndef GNUNET_DATASTORE_SERVICE_H 42#ifndef GNUNET_DATASTORE_SERVICE_H
40#define GNUNET_DATASTORE_SERVICE_H 43#define GNUNET_DATASTORE_SERVICE_H
41 44
45
42#include "gnunet_util_lib.h" 46#include "gnunet_util_lib.h"
43#include "gnunet_block_lib.h" 47#include "gnunet_block_lib.h"
44 48
@@ -361,3 +365,5 @@ GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
361#endif 365#endif
362 366
363/** @} */ /* end of group */ 367/** @} */ /* end of group */
368
369/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h
index e88e836f6..1ff665c2b 100644
--- a/src/include/gnunet_db_lib.h
+++ b/src/include/gnunet_db_lib.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_DB_LIB_H 25#ifndef GNUNET_DB_LIB_H
26#define GNUNET_DB_LIB_H 26#define GNUNET_DB_LIB_H
27 27
28
28#include "gnunet_common.h" 29#include "gnunet_common.h"
29 30
30/** 31/**
diff --git a/src/include/gnunet_dht_block_types.h b/src/include/gnunet_dht_block_types.h
new file mode 100644
index 000000000..ab46af410
--- /dev/null
+++ b/src/include/gnunet_dht_block_types.h
@@ -0,0 +1,156 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_DHT_BLOCK_TYPES_H
21#define GNUNET_DHT_BLOCK_TYPES_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add DHT block types, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39/**
40 * Blocks in the datastore and the datacache must have a unique type.
41 */
42enum GNUNET_BLOCK_Type
43{
44
45
46 /**
47 * Identifier for any block.
48 */
49 GNUNET_BLOCK_TYPE_ANY = 0,
50
51
52 /**
53 * Data block (leaf) in the CHK tree.
54 */
55 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
56
57
58 /**
59 * Inner block in the CHK tree.
60 */
61 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
62
63
64 /**
65 * Type of a block representing a block to be encoded on demand from disk. Should never appear on the network directly.
66 */
67 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
68
69
70 /**
71 * Legacy type of a block that contains a HELLO for a peer.
72 */
73 GNUNET_BLOCK_TYPE_LEGACY_HELLO = 7,
74
75
76 /**
77 * Block for testing.
78 */
79 GNUNET_BLOCK_TYPE_TEST = 8,
80
81
82 /**
83 * Type of a block representing any type of search result (universal).
84 */
85 GNUNET_BLOCK_TYPE_FS_UBLOCK = 9,
86
87
88 /**
89 * Block for storing DNS exit service advertisements.
90 */
91 GNUNET_BLOCK_TYPE_DNS = 10,
92
93
94 /**
95 * Block for storing GNS record data.
96 */
97 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
98
99
100 /**
101 * Block type for a revocation message by which a key is revoked.
102 */
103 GNUNET_BLOCK_TYPE_REVOCATION = 12,
104
105
106 /**
107 * Type of a block that contains a DHT-NG HELLO for a peer.
108 */
109 GNUNET_BLOCK_TYPE_DHT_HELLO = 13,
110
111
112 /**
113 * Block to store a cadet regex state
114 */
115 GNUNET_BLOCK_TYPE_REGEX = 22,
116
117
118 /**
119 * Block to store a cadet regex accepting state
120 */
121 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23,
122
123
124 /**
125 * Block for testing set/consensus. If first byte of the block is non-zero, the block is considered invalid.
126 */
127 GNUNET_BLOCK_TYPE_SET_TEST = 24,
128
129
130 /**
131 * Block type for consensus elements. Contains either special marker elements or a nested block.
132 */
133 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25,
134
135
136 /**
137 * Block for testing set intersection. If first byte of the block is non-zero, the block is considered invalid.
138 */
139 GNUNET_BLOCK_TYPE_SETI_TEST = 26,
140
141
142 /**
143 * Block for testing set union. If first byte of the block is non-zero, the block is considered invalid.
144 */
145 GNUNET_BLOCK_TYPE_SETU_TEST = 27,
146};
147
148
149#if 0 /* keep Emacsens' auto-indent happy */
150{
151#endif
152#ifdef __cplusplus
153}
154#endif
155
156#endif
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index 95d30ae6f..a1ea31c25 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2004-2013, 2016 GNUnet e.V. 3 Copyright (C) 2004-2013, 2016, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,11 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 * @addtogroup dht_libs DHT and support libraries
25 * @{
26 *
22 * @author Christian Grothoff 27 * @author Christian Grothoff
23 * 28 *
24 * @file 29 * @file
@@ -35,9 +40,9 @@
35#ifndef GNUNET_DHT_SERVICE_H 40#ifndef GNUNET_DHT_SERVICE_H
36#define GNUNET_DHT_SERVICE_H 41#define GNUNET_DHT_SERVICE_H
37 42
43
38#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
39#include "gnunet_block_lib.h" 45#include "gnunet_block_lib.h"
40#include "gnunet_hello_lib.h"
41 46
42#ifdef __cplusplus 47#ifdef __cplusplus
43extern "C" 48extern "C"
@@ -56,6 +61,12 @@ extern "C"
56 61
57 62
58/** 63/**
64 * Maximum allowed replication level for all requests.
65 */
66#define GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL 16
67
68
69/**
59 * Connection to the DHT service. 70 * Connection to the DHT service.
60 */ 71 */
61struct GNUNET_DHT_Handle; 72struct GNUNET_DHT_Handle;
@@ -82,8 +93,9 @@ enum GNUNET_DHT_RouteOption
82 GNUNET_DHT_RO_NONE = 0, 93 GNUNET_DHT_RO_NONE = 0,
83 94
84 /** 95 /**
85 * Each peer along the way should look at 'enc' (otherwise 96 * Each peer along the way should process the request (otherwise
86 * only the k-peers closest to the key should look at it). 97 * only peers locally closest to the key when the random walk
98 * is over should look at it).
87 */ 99 */
88 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1, 100 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1,
89 101
@@ -94,22 +106,88 @@ enum GNUNET_DHT_RouteOption
94 GNUNET_DHT_RO_RECORD_ROUTE = 2, 106 GNUNET_DHT_RO_RECORD_ROUTE = 2,
95 107
96 /** 108 /**
97 * This is a 'FIND-PEER' request, so approximate results are fine. 109 * Approximate results are fine.
98 */ 110 */
99 GNUNET_DHT_RO_FIND_PEER = 4, 111 GNUNET_DHT_RO_FIND_APPROXIMATE = 4,
100 112
101 /** 113 /**
102 * Possible message option for query key randomization. 114 * Flag set if the path was truncated.
103 */ 115 */
104 GNUNET_DHT_RO_BART = 8, 116 GNUNET_DHT_RO_TRUNCATED = 8,
105 117
106 /** 118 /**
107 * Flag given to monitors if this was the last hop for a GET/PUT. 119 * Flag given to monitors if this was the last hop for a GET/PUT.
120 * This is only used for internal processing.
108 */ 121 */
109 GNUNET_DHT_RO_LAST_HOP = 16 122 GNUNET_DHT_RO_LAST_HOP = 32768
110}; 123};
111 124
112 125
126GNUNET_NETWORK_STRUCT_BEGIN
127
128/**
129 * Message signed by a peer when doing path tracking.
130 */
131struct GNUNET_DHT_HopSignature
132{
133 /**
134 * Must be #GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
135 */
136 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
137
138 /**
139 * Expiration time of the block.
140 */
141 struct GNUNET_TIME_AbsoluteNBO expiration_time;
142
143 /**
144 * Hash over the payload of the block.
145 */
146 struct GNUNET_HashCode h_data GNUNET_PACKED;
147
148 /**
149 * Previous hop the message was received from. All zeros
150 * if this peer was the initiator.
151 */
152 struct GNUNET_PeerIdentity pred;
153
154 /**
155 * Next hop the message was forwarded to.
156 */
157 struct GNUNET_PeerIdentity succ;
158};
159
160
161/**
162 * A (signed) path tracking a block's flow through the DHT is represented by
163 * an array of path elements, each consisting of a peer on the path and a
164 * signature by which the peer affirms its routing decision.
165 */
166struct GNUNET_DHT_PathElement
167{
168 /**
169 * Signature affirming the hop of type
170 * #GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
171 */
172 struct GNUNET_CRYPTO_EddsaSignature sig;
173
174 /**
175 * Previous peer on the path (matches "pred" in the signed field).
176 *
177 * The public key used to create the @e sig is in the *next* path element,
178 * or is the sender of the message if this was the last path element.
179 *
180 * The "succ" field can be found in 'pred' if there are two more path
181 * elements in the path, is the sender if there is only one more path
182 * element, or the recipient if this was the last element on the path.
183 */
184 struct GNUNET_PeerIdentity pred;
185
186};
187
188
189GNUNET_NETWORK_STRUCT_END
190
113/** 191/**
114 * Initialize the connection with the DHT service. 192 * Initialize the connection with the DHT service.
115 * 193 *
@@ -193,13 +271,16 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph);
193 * 271 *
194 * @param cls closure 272 * @param cls closure
195 * @param exp when will this value expire 273 * @param exp when will this value expire
196 * @param key key of the result 274 * @param query_hash key of the query
275 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
197 * @param get_path peers on reply path (or NULL if not recorded) 276 * @param get_path peers on reply path (or NULL if not recorded)
198 * [0] = datastore's first neighbor, [length - 1] = local peer 277 * [0] = datastore's first neighbor, [length - 1] = local peer
199 * @param get_path_length number of entries in @a get_path 278 * @param get_path_length number of entries in @a get_path
200 * @param put_path peers on the PUT path (or NULL if not recorded) 279 * @param put_path peers on the PUT path (or NULL if not recorded)
201 * [0] = origin, [length - 1] = datastore 280 * [0] = origin, [length - 1] = datastore
202 * @param put_path_length number of entries in @a put_path 281 * @param put_path_length number of entries in @a put_path,
282 * note that the last signature will be all zeros as
283 * we did not forward and thus did not sign!
203 * @param type type of the result 284 * @param type type of the result
204 * @param size number of bytes in @a data 285 * @param size number of bytes in @a data
205 * @param data pointer to the result data 286 * @param data pointer to the result data
@@ -207,10 +288,11 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph);
207typedef void 288typedef void
208(*GNUNET_DHT_GetIterator) (void *cls, 289(*GNUNET_DHT_GetIterator) (void *cls,
209 struct GNUNET_TIME_Absolute exp, 290 struct GNUNET_TIME_Absolute exp,
210 const struct GNUNET_HashCode *key, 291 const struct GNUNET_HashCode *query_hash,
211 const struct GNUNET_PeerIdentity *get_path, 292 const struct GNUNET_PeerIdentity *trunc_peer,
293 const struct GNUNET_DHT_PathElement *get_path,
212 unsigned int get_path_length, 294 unsigned int get_path_length,
213 const struct GNUNET_PeerIdentity *put_path, 295 const struct GNUNET_DHT_PathElement *put_path,
214 unsigned int put_path_length, 296 unsigned int put_path_length,
215 enum GNUNET_BLOCK_Type type, 297 enum GNUNET_BLOCK_Type type,
216 size_t size, 298 size_t size,
@@ -283,8 +365,6 @@ struct GNUNET_DHT_MonitorHandle;
283 * @param options Options, for instance RecordRoute, DemultiplexEverywhere. 365 * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
284 * @param type The type of data in the request. 366 * @param type The type of data in the request.
285 * @param hop_count Hop count so far. 367 * @param hop_count Hop count so far.
286 * @param path_length number of entries in @a path (or 0 if not recorded).
287 * @param path peers on the GET path (or NULL if not recorded).
288 * @param desired_replication_level Desired replication level. 368 * @param desired_replication_level Desired replication level.
289 * @param key Key of the requested data. 369 * @param key Key of the requested data.
290 */ 370 */
@@ -294,8 +374,6 @@ typedef void
294 enum GNUNET_BLOCK_Type type, 374 enum GNUNET_BLOCK_Type type,
295 uint32_t hop_count, 375 uint32_t hop_count,
296 uint32_t desired_replication_level, 376 uint32_t desired_replication_level,
297 unsigned int path_length,
298 const struct GNUNET_PeerIdentity *path,
299 const struct GNUNET_HashCode *key); 377 const struct GNUNET_HashCode *key);
300 378
301 379
@@ -304,7 +382,10 @@ typedef void
304 * 382 *
305 * @param cls Closure. 383 * @param cls Closure.
306 * @param type The type of data in the result. 384 * @param type The type of data in the result.
385 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
307 * @param get_path Peers on GET path (or NULL if not recorded). 386 * @param get_path Peers on GET path (or NULL if not recorded).
387 * note that the last signature will be all zeros as
388 * we did not forward and thus did not sign!
308 * @param get_path_length number of entries in @a get_path. 389 * @param get_path_length number of entries in @a get_path.
309 * @param put_path peers on the PUT path (or NULL if not recorded). 390 * @param put_path peers on the PUT path (or NULL if not recorded).
310 * @param put_path_length number of entries in @a get_path. 391 * @param put_path_length number of entries in @a get_path.
@@ -316,9 +397,10 @@ typedef void
316typedef void 397typedef void
317(*GNUNET_DHT_MonitorGetRespCB) (void *cls, 398(*GNUNET_DHT_MonitorGetRespCB) (void *cls,
318 enum GNUNET_BLOCK_Type type, 399 enum GNUNET_BLOCK_Type type,
319 const struct GNUNET_PeerIdentity *get_path, 400 const struct GNUNET_PeerIdentity *trunc_peer,
401 const struct GNUNET_DHT_PathElement *get_path,
320 unsigned int get_path_length, 402 unsigned int get_path_length,
321 const struct GNUNET_PeerIdentity *put_path, 403 const struct GNUNET_DHT_PathElement *put_path,
322 unsigned int put_path_length, 404 unsigned int put_path_length,
323 struct GNUNET_TIME_Absolute exp, 405 struct GNUNET_TIME_Absolute exp,
324 const struct GNUNET_HashCode *key, 406 const struct GNUNET_HashCode *key,
@@ -333,9 +415,12 @@ typedef void
333 * @param options Options, for instance RecordRoute, DemultiplexEverywhere. 415 * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
334 * @param type The type of data in the request. 416 * @param type The type of data in the request.
335 * @param hop_count Hop count so far. 417 * @param hop_count Hop count so far.
418 * @param desired_replication_level Desired replication level.
419 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
336 * @param path_length number of entries in @a path (or 0 if not recorded). 420 * @param path_length number of entries in @a path (or 0 if not recorded).
337 * @param path peers on the PUT path (or NULL if not recorded). 421 * @param path peers on the PUT path (or NULL if not recorded).
338 * @param desired_replication_level Desired replication level. 422 * note that the last signature will be all zeros as
423 * we did not forward and thus did not sign!
339 * @param exp Expiration time of the data. 424 * @param exp Expiration time of the data.
340 * @param key Key under which data is to be stored. 425 * @param key Key under which data is to be stored.
341 * @param data Pointer to the data carried. 426 * @param data Pointer to the data carried.
@@ -347,8 +432,9 @@ typedef void
347 enum GNUNET_BLOCK_Type type, 432 enum GNUNET_BLOCK_Type type,
348 uint32_t hop_count, 433 uint32_t hop_count,
349 uint32_t desired_replication_level, 434 uint32_t desired_replication_level,
435 const struct GNUNET_PeerIdentity *trunc_peer,
350 unsigned int path_length, 436 unsigned int path_length,
351 const struct GNUNET_PeerIdentity *path, 437 const struct GNUNET_DHT_PathElement *path,
352 struct GNUNET_TIME_Absolute exp, 438 struct GNUNET_TIME_Absolute exp,
353 const struct GNUNET_HashCode *key, 439 const struct GNUNET_HashCode *key,
354 const void *data, 440 const void *data,
@@ -388,6 +474,107 @@ void
388GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle); 474GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
389 475
390 476
477/**
478 * Convert a peer path to a human-readable string.
479 *
480 * @param path array of path elements to convert to a string
481 * @param path_len length of the @a path array
482 * @return string representing the array of @a pids
483 */
484char *
485GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path,
486 unsigned int path_len);
487
488
489/**
490 * Verify signatures on a path consisting of @a put_path and @a get_path in
491 * reverse order (starting at the last element of the @a get_path). Note that
492 * the last signature on the path is never verified as that is the slot where
493 * our peer (@a me) would need to sign.
494 *
495 * @param data payload (the block)
496 * @param data_size number of bytes in @a data
497 * @param exp_time expiration time of @a data
498 * @param trunc_peer peer which signature was broken or where the path was truncated,
499 * NULL if path is not truncated
500 * @param get_path array of path elements to verify
501 * @param get_path_len length of the @a get_path array
502 * @param put_path array of path elements to verify
503 * @param put_path_len length of the @a put_path array
504 * @param me our own peer identity (needed to verify the last element)
505 * @return 0 on success, otherwise the index of
506 * the last path element that succeeded with verification;
507 * @a get_path_len + @a put_path_len if no signature was valid
508 */
509unsigned int
510GNUNET_DHT_verify_path (const void *data,
511 size_t data_size,
512 struct GNUNET_TIME_Absolute exp_time,
513 const struct GNUNET_PeerIdentity *trunc_peer,
514 const struct GNUNET_DHT_PathElement *put_path,
515 unsigned int put_path_len,
516 const struct GNUNET_DHT_PathElement *get_path,
517 unsigned int get_path_len,
518 const struct GNUNET_PeerIdentity *me);
519
520
521/**
522 * Handle to get a HELLO URL from the DHT for manual bootstrapping.
523 */
524struct GNUNET_DHT_HelloGetHandle;
525
526
527/**
528 * Signature called with the result of a HELLO GET operation.
529 *
530 * @param cls closure
531 * @param hello_url the resulting HELLO URL, NULL on error
532 */
533typedef void
534(*GNUNET_DHT_HelloGetCallback)(void *cls,
535 const char *hello_url);
536
537
538/**
539 * Obtain HELLO URL of the DHT identified by @a dht_handle.
540 *
541 * @param dht_handle DHT to query
542 * @param cb function to call with the result
543 * @param cb_cls closure for @a cb
544 * @return NULL on failure
545 */
546struct GNUNET_DHT_HelloGetHandle *
547GNUNET_DHT_hello_get (struct GNUNET_DHT_Handle *dht_handle,
548 GNUNET_DHT_HelloGetCallback cb,
549 void *cb_cls);
550
551
552/**
553 * Cancel hello get operation.
554 *
555 * @param[in] hgh operation to cancel.
556 */
557void
558GNUNET_DHT_hello_get_cancel (struct GNUNET_DHT_HelloGetHandle *hgh);
559
560
561/**
562 * Offer HELLO URL of the DHT identified by @a dht_handle.
563 * Callback may be invoked once, only way to cancel is to
564 * disconnect @a dht_handle.
565 *
566 * @param dht_handle DHT to query
567 * @param url URL with a HELLO to offer to the DHT
568 * @param cb function called when done
569 * @param cb_cls closure for @a cb
570 */
571void
572GNUNET_DHT_hello_offer (struct GNUNET_DHT_Handle *dht_handle,
573 const char *url,
574 GNUNET_SCHEDULER_TaskCallback cb,
575 void *cb_cls);
576
577
391#if 0 /* keep Emacsens' auto-indent happy */ 578#if 0 /* keep Emacsens' auto-indent happy */
392{ 579{
393#endif 580#endif
@@ -398,3 +585,7 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
398#endif 585#endif
399 586
400/** @} */ /* end of group dht */ 587/** @} */ /* end of group dht */
588
589/** @} */ /* end of group addition */
590
591/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dhtu_plugin.h b/src/include/gnunet_dhtu_plugin.h
index e65318fb5..0503dda1c 100644
--- a/src/include/gnunet_dhtu_plugin.h
+++ b/src/include/gnunet_dhtu_plugin.h
@@ -27,6 +27,7 @@
27#ifndef PLUGIN_DHTU_H 27#ifndef PLUGIN_DHTU_H
28#define PLUGIN_DHTU_H 28#define PLUGIN_DHTU_H
29 29
30
30#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
31 32
32 33
@@ -57,38 +58,6 @@ struct GNUNET_DHTU_Target;
57 */ 58 */
58struct GNUNET_DHTU_PreferenceHandle; 59struct GNUNET_DHTU_PreferenceHandle;
59 60
60/**
61 * Opaque handle for a private key used by this underlay.
62 */
63struct GNUNET_DHTU_PrivateKey;
64
65/**
66 * Handle for a public key used by another peer. Note that
67 * the underlay used must be communicated separately.
68 */
69struct GNUNET_DHTU_PublicKey
70{
71 /**
72 * How long is the public key, in network byte order.
73 */
74 uint16_t size;
75
76 /* followed by size-2 bytes of the actual public key */
77};
78
79
80/**
81 * Hash used by the DHT for keys and peers.
82 */
83struct GNUNET_DHTU_Hash
84{
85
86 /**
87 * For now, use a 512 bit hash. (To be discussed).
88 */
89 struct GNUNET_HashCode hc;
90};
91
92 61
93/** 62/**
94 * The datastore service will pass a pointer to a struct 63 * The datastore service will pass a pointer to a struct
@@ -111,9 +80,6 @@ struct GNUNET_DHTU_PluginEnvironment
111 * Function to call with new addresses of this peer. 80 * Function to call with new addresses of this peer.
112 * 81 *
113 * @param cls the closure 82 * @param cls the closure
114 * @param my_id hash position of this address in the DHT
115 * @param pk private key of this peer used at @a address,
116 * pointer will remain valid until @e address_del_cb is called
117 * @param address address under which we are likely reachable, 83 * @param address address under which we are likely reachable,
118 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/" 84 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/"
119 * @param source handle for sending from this address, NULL if we can only receive 85 * @param source handle for sending from this address, NULL if we can only receive
@@ -121,8 +87,6 @@ struct GNUNET_DHTU_PluginEnvironment
121 */ 87 */
122 void 88 void
123 (*address_add_cb)(void *cls, 89 (*address_add_cb)(void *cls,
124 const struct GNUNET_DHTU_Hash *my_id,
125 const struct GNUNET_DHTU_PrivateKey *pk,
126 const char *address, 90 const char *address,
127 struct GNUNET_DHTU_Source *source, 91 struct GNUNET_DHTU_Source *source,
128 void **ctx); 92 void **ctx);
@@ -154,21 +118,19 @@ struct GNUNET_DHTU_PluginEnvironment
154 * that peer. 118 * that peer.
155 * 119 *
156 * @param cls the closure 120 * @param cls the closure
157 * @param pk public key of the target,
158 * pointer will remain valid until @e disconnect_cb is called
159 * @para peer_id hash position of the peer,
160 * pointer will remain valid until @e disconnect_cb is called
161 * @param target handle to the target, 121 * @param target handle to the target,
162 * pointer will remain valid until @e disconnect_cb is called 122 * pointer will remain valid until @e disconnect_cb is called
123 * @param pid peer identity,
124 * pointer will remain valid until @e disconnect_cb is called
163 * @param[out] ctx storage space for DHT to use in association with this target 125 * @param[out] ctx storage space for DHT to use in association with this target
164 */ 126 */
165 void 127 void
166 (*connect_cb)(void *cls, 128 (*connect_cb)(void *cls,
167 const struct GNUNET_DHTU_PublicKey *pk,
168 const struct GNUNET_DHTU_Hash *peer_id,
169 struct GNUNET_DHTU_Target *target, 129 struct GNUNET_DHTU_Target *target,
130 const struct GNUNET_PeerIdentity *pid,
170 void **ctx); 131 void **ctx);
171 132
133
172 /** 134 /**
173 * Function to call when we disconnected from a peer and can henceforth 135 * Function to call when we disconnected from a peer and can henceforth
174 * cannot transmit to that peer anymore. 136 * cannot transmit to that peer anymore.
@@ -209,50 +171,18 @@ struct GNUNET_DHTU_PluginFunctions
209 void *cls; 171 void *cls;
210 172
211 /** 173 /**
212 * Use our private key to sign a message.
213 *
214 * @param cls closure
215 * @param pk our private key to sign with
216 * @param purpose what to sign
217 * @param[out] signature, allocated on heap and returned
218 * @return -1 on error, otherwise number of bytes in @a sig
219 */
220 ssize_t
221 (*sign)(void *cls,
222 const struct GNUNET_DHTU_PrivateKey *pk,
223 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
224 void **sig);
225
226 /**
227 * Verify signature in @a sig over @a purpose.
228 *
229 * @param cls closure
230 * @param pk public key to verify signature of
231 * @param purpose what was being signed
232 * @param sig signature data
233 * @param sig_size number of bytes in @a sig
234 * @return #GNUNET_OK if signature is valid
235 * #GNUNET_NO if signatures are not supported
236 * #GNUNET_SYSERR if signature is invalid
237 */
238 enum GNUNET_GenericReturnValue
239 (*verify)(void *cls,
240 const struct GNUNET_DHTU_PublicKey *pk,
241 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
242 const void *sig,
243 size_t sig_size);
244
245
246 /**
247 * Request creation of a session with a peer at the given @a address. 174 * Request creation of a session with a peer at the given @a address.
248 * 175 *
249 * @param cls closure (internal context for the plugin) 176 * @param cls closure (internal context for the plugin)
250 * @param address target address to connect to 177 * @param pid target identity of the peer to connect to
178 * @param address target address URI to connect to
251 */ 179 */
252 void 180 void
253 (*try_connect) (void *cls, 181 (*try_connect) (void *cls,
182 const struct GNUNET_PeerIdentity *pid,
254 const char *address); 183 const char *address);
255 184
185
256 /** 186 /**
257 * Request underlay to keep the connection to @a target alive if possible. 187 * Request underlay to keep the connection to @a target alive if possible.
258 * Hold may be called multiple times to express a strong preference to 188 * Hold may be called multiple times to express a strong preference to
@@ -266,7 +196,7 @@ struct GNUNET_DHTU_PluginFunctions
266 struct GNUNET_DHTU_Target *target); 196 struct GNUNET_DHTU_Target *target);
267 197
268 /** 198 /**
269 * Do no long request underlay to keep the connection alive. 199 * Do no longer request underlay to keep the connection alive.
270 * 200 *
271 * @param cls closure 201 * @param cls closure
272 * @param target connection to keep alive 202 * @param target connection to keep alive
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 7dfd9ccf1..2aec55851 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -18,6 +18,10 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup libgnunetutil
22 * Multi-function utilities library for GNUnet programs
23 * @{
24 *
21 * @author Christian Grothoff 25 * @author Christian Grothoff
22 * 26 *
23 * @file 27 * @file
@@ -27,6 +31,11 @@
27 * Disk IO APIs 31 * Disk IO APIs
28 * @{ 32 * @{
29 */ 33 */
34
35#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
36#error "Only <gnunet_util_lib.h> can be included directly."
37#endif
38
30#ifndef GNUNET_DISK_LIB_H 39#ifndef GNUNET_DISK_LIB_H
31#define GNUNET_DISK_LIB_H 40#define GNUNET_DISK_LIB_H
32 41
@@ -72,6 +81,7 @@ struct GNUNET_DISK_FileHandle
72 or unsigned long long, this IS platform dependent; 81 or unsigned long long, this IS platform dependent;
73 but "stdlib.h" should be portable 'enough' to be 82 but "stdlib.h" should be portable 'enough' to be
74 unconditionally available... */ 83 unconditionally available... */
84
75#include <stdlib.h> 85#include <stdlib.h>
76#include "gnunet_configuration_lib.h" 86#include "gnunet_configuration_lib.h"
77#include "gnunet_scheduler_lib.h" 87#include "gnunet_scheduler_lib.h"
@@ -670,7 +680,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
670 * Currently, the glob_pattern only supports asterisks in the last 680 * Currently, the glob_pattern only supports asterisks in the last
671 * path component. 681 * path component.
672 * 682 *
673 * @param glob_patterb the glob pattern to search for 683 * @param glob_pattern the glob pattern to search for
674 * @param callback the method to call for each file 684 * @param callback the method to call for each file
675 * @param callback_cls closure for @a callback 685 * @param callback_cls closure for @a callback
676 * @return the number of files found, -1 on error 686 * @return the number of files found, -1 on error
@@ -815,4 +825,6 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
815 825
816/** @} */ /* end of group */ 826/** @} */ /* end of group */
817 827
828/** @} */ /* end of group addition */
829
818/* end of gnunet_disk_lib.h */ 830/* end of gnunet_disk_lib.h */
diff --git a/src/include/gnunet_dns_service.h b/src/include/gnunet_dns_service.h
index 20f0f13ee..b5741a7e2 100644
--- a/src/include/gnunet_dns_service.h
+++ b/src/include/gnunet_dns_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite VPN services and libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -33,6 +36,7 @@
33#ifndef GNUNET_DNS_SERVICE_H 36#ifndef GNUNET_DNS_SERVICE_H
34#define GNUNET_DNS_SERVICE_H 37#define GNUNET_DNS_SERVICE_H
35 38
39
36#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
37 41
38 42
@@ -191,3 +195,5 @@ GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh);
191#endif 195#endif
192 196
193/** @} */ /* end of group */ 197/** @} */ /* end of group */
198
199/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index f77073264..9a84f346f 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
25
21/** 26/**
27 * @addtogroup libgnunetutil
28 * @{
29 *
22 * @author Philipp Toelke 30 * @author Philipp Toelke
23 * @author Christian Grothoff 31 * @author Christian Grothoff
24 * 32 *
@@ -32,8 +40,6 @@
32#ifndef GNUNET_DNSPARSER_LIB_H 40#ifndef GNUNET_DNSPARSER_LIB_H
33#define GNUNET_DNSPARSER_LIB_H 41#define GNUNET_DNSPARSER_LIB_H
34 42
35#include "gnunet_util_lib.h"
36
37/** 43/**
38 * Maximum length of a label in DNS. 44 * Maximum length of a label in DNS.
39 */ 45 */
@@ -78,6 +84,7 @@
78#define GNUNET_DNSPARSER_TYPE_NSEC3 50 84#define GNUNET_DNSPARSER_TYPE_NSEC3 50
79#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51 85#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
80#define GNUNET_DNSPARSER_TYPE_TLSA 52 86#define GNUNET_DNSPARSER_TYPE_TLSA 52
87#define GNUNET_DNSPARSER_TYPE_SMIMEA 53
81#define GNUNET_DNSPARSER_TYPE_HIP 55 88#define GNUNET_DNSPARSER_TYPE_HIP 55
82#define GNUNET_DNSPARSER_TYPE_CDS 59 89#define GNUNET_DNSPARSER_TYPE_CDS 59
83#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60 90#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
@@ -172,6 +179,33 @@ struct GNUNET_DNSPARSER_SrvRecord
172 179
173 180
174/** 181/**
182 * Information from URI records (RFC 7553).
183 */
184struct GNUNET_DNSPARSER_UriRecord
185{
186 /**
187 * URI of the target,
188 * where the URI is as specified in RFC 3986.
189 */
190 char *target;
191
192 /**
193 * Preference for this entry (lower value is higher preference). Clients
194 * will contact hosts from the lowest-priority group first and fall back
195 * to higher priorities if the low-priority entries are unavailable.
196 */
197 uint16_t priority;
198
199 /**
200 * Relative weight for records with the same priority. Clients will use
201 * the hosts of the same (lowest) priority with a probability proportional
202 * to the weight given.
203 */
204 uint16_t weight;
205};
206
207
208/**
175 * DNS CERT types as defined in RFC 4398. 209 * DNS CERT types as defined in RFC 4398.
176 */ 210 */
177enum GNUNET_DNSPARSER_CertType 211enum GNUNET_DNSPARSER_CertType
@@ -473,6 +507,11 @@ struct GNUNET_DNSPARSER_Record
473 struct GNUNET_DNSPARSER_SrvRecord *srv; 507 struct GNUNET_DNSPARSER_SrvRecord *srv;
474 508
475 /** 509 /**
510 * URI data for URI records.
511 */
512 struct GNUNET_DNSPARSER_UriRecord *uri;
513
514 /**
476 * Raw data for all other types. 515 * Raw data for all other types.
477 */ 516 */
478 struct GNUNET_DNSPARSER_RawRecord raw; 517 struct GNUNET_DNSPARSER_RawRecord raw;
@@ -737,6 +776,25 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst,
737 size_t *off, 776 size_t *off,
738 const struct GNUNET_DNSPARSER_SrvRecord *srv); 777 const struct GNUNET_DNSPARSER_SrvRecord *srv);
739 778
779
780/**
781 * Add an URI record to the UDP packet at the given location.
782 *
783 * @param dst where to write the URI record
784 * @param dst_len number of bytes in @a dst
785 * @param off pointer to offset where to write the URI information (increment by bytes used)
786 * can also change if there was an error
787 * @param uri URI information to write
788 * @return #GNUNET_SYSERR if @a uri is invalid
789 * #GNUNET_NO if @a uri did not fit
790 * #GNUNET_OK if @a uri was added to @a dst
791 */
792int
793GNUNET_DNSPARSER_builder_add_uri (char *dst,
794 size_t dst_len,
795 size_t *off,
796 const struct GNUNET_DNSPARSER_UriRecord *uri);
797
740/* ***************** low-level parsing API ******************** */ 798/* ***************** low-level parsing API ******************** */
741 799
742/** 800/**
@@ -847,6 +905,21 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
847 size_t udp_payload_length, 905 size_t udp_payload_length,
848 size_t *off); 906 size_t *off);
849 907
908
909/**
910 * Parse a DNS URI record.
911 *
912 * @param udp_payload reference to UDP packet
913 * @param udp_payload_length length of @a udp_payload
914 * @param off pointer to the offset of the query to parse in the URI record (to be
915 * incremented by the size of the record), unchanged on error
916 * @return the parsed URI record, NULL on error
917 */
918struct GNUNET_DNSPARSER_UriRecord *
919GNUNET_DNSPARSER_parse_uri (const char *udp_payload,
920 size_t udp_payload_length,
921 size_t *off);
922
850/* ***************** low-level duplication API ******************** */ 923/* ***************** low-level duplication API ******************** */
851 924
852/** 925/**
@@ -903,6 +976,16 @@ GNUNET_DNSPARSER_duplicate_srv_record (const struct
903 GNUNET_DNSPARSER_SrvRecord *r); 976 GNUNET_DNSPARSER_SrvRecord *r);
904 977
905 978
979/**
980 * Duplicate (deep-copy) the given DNS record
981 *
982 * @param r the record
983 * @return the newly allocated record
984 */
985struct GNUNET_DNSPARSER_UriRecord *
986GNUNET_DNSPARSER_duplicate_uri_record (const struct
987 GNUNET_DNSPARSER_UriRecord *r);
988
906/* ***************** low-level deallocation API ******************** */ 989/* ***************** low-level deallocation API ******************** */
907 990
908/** 991/**
@@ -933,6 +1016,15 @@ GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv);
933 1016
934 1017
935/** 1018/**
1019 * Free URI information record.
1020 *
1021 * @param uri record to free
1022 */
1023void
1024GNUNET_DNSPARSER_free_uri (struct GNUNET_DNSPARSER_UriRecord *uri);
1025
1026
1027/**
936 * Free SOA information record. 1028 * Free SOA information record.
937 * 1029 *
938 * @param soa record to free 1030 * @param soa record to free
@@ -978,3 +1070,5 @@ GNUNET_DNSPARSER_hex_to_bin (const char *hex,
978#endif 1070#endif
979 1071
980/** @} */ /* end of group */ 1072/** @} */ /* end of group */
1073
1074/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dnsstub_lib.h b/src/include/gnunet_dnsstub_lib.h
index 4e93105bb..fa5151a8c 100644
--- a/src/include/gnunet_dnsstub_lib.h
+++ b/src/include/gnunet_dnsstub_lib.h
@@ -18,7 +18,14 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -31,6 +38,7 @@
31#ifndef GNUNET_DNSSTUB_LIB_H 38#ifndef GNUNET_DNSSTUB_LIB_H
32#define GNUNET_DNSSTUB_LIB_H 39#define GNUNET_DNSSTUB_LIB_H
33 40
41
34#include "gnunet_util_lib.h" 42#include "gnunet_util_lib.h"
35 43
36/** 44/**
@@ -86,7 +94,7 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
86 * Only effective for requests issued after this call. 94 * Only effective for requests issued after this call.
87 * 95 *
88 * @param ctx resolver context to modify 96 * @param ctx resolver context to modify
89 * @param retry_frequ how long to wait between retries 97 * @param retry_freq how long to wait between retries
90 */ 98 */
91void 99void
92GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx, 100GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
@@ -147,3 +155,5 @@ GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
147#endif 155#endif
148 156
149/** @} */ /* end of group */ 157/** @} */ /* end of group */
158
159/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_error_codes.h b/src/include/gnunet_error_codes.h
new file mode 100644
index 000000000..aa897afe0
--- /dev/null
+++ b/src/include/gnunet_error_codes.h
@@ -0,0 +1,242 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 /**
21 * @file include/taler_error_codes.h
22 * @brief GNUnet error codes, generated via https://gana.gnunet.org/
23 *
24 * Do NOT edit this file, it is generated!
25 */
26#ifndef GNUNET_ERROR_CODES_H
27#define GNUNET_ERROR_CODES_H
28
29#ifdef __cplusplus
30extern "C" {
31#if 0 /* keep Emacsens' auto-indent happy */
32}
33#endif
34#endif
35
36#include <limits.h>
37
38
39/**
40 * Taler error codes.
41 */
42enum GNUNET_ErrorCode
43{
44
45
46 /**
47 * No error (success).
48 * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
49 */
50 GNUNET_EC_NONE = 0,
51
52
53 /**
54 * Unknown and unspecified error.
55 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
56 */
57 GNUNET_EC_UNKNOWN = 1,
58
59
60 /**
61 * Communication with service failed.
62 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
63 */
64 GNUNET_EC_SERVICE_COMMUNICATION_FAILED = 101,
65
66
67 /**
68 * Ego not found.
69 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
70 */
71 GNUNET_EC_IDENTITY_NOT_FOUND = 200,
72
73
74 /**
75 * Identifier already in use for another ego.
76 * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409).
77 */
78 GNUNET_EC_IDENTITY_NAME_CONFLICT = 201,
79
80
81 /**
82 * The given ego is invalid or malformed.
83 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
84 */
85 GNUNET_EC_IDENTITY_INVALID = 202,
86
87
88 /**
89 * Unknown namestore error.
90 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
91 */
92 GNUNET_EC_NAMESTORE_UNKNOWN = 5000,
93
94
95 /**
96 * Zone iteration failed.
97 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
98 */
99 GNUNET_EC_NAMESTORE_ITERATION_FAILED = 5001,
100
101
102 /**
103 * Zone not found.
104 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
105 */
106 GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND = 5002,
107
108
109 /**
110 * Record not found.
111 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
112 */
113 GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND = 5003,
114
115
116 /**
117 * Zone iteration failed.
118 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
119 */
120 GNUNET_EC_NAMESTORE_RECORD_DELETE_FAILED = 5004,
121
122
123 /**
124 * Zone does not contain any records.
125 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
126 */
127 GNUNET_EC_NAMESTORE_ZONE_EMPTY = 5005,
128
129
130 /**
131 * Failed to lookup record.
132 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
133 */
134 GNUNET_EC_NAMESTORE_LOOKUP_ERROR = 5006,
135
136
137 /**
138 * No records given.
139 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
140 */
141 GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN = 5007,
142
143
144 /**
145 * Record data invalid.
146 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
147 */
148 GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID = 5008,
149
150
151 /**
152 * No label given.
153 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
154 */
155 GNUNET_EC_NAMESTORE_NO_LABEL_GIVEN = 5009,
156
157
158 /**
159 * No results given.
160 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
161 */
162 GNUNET_EC_NAMESTORE_NO_RESULTS = 5010,
163
164
165 /**
166 * Record already exists.
167 * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409).
168 */
169 GNUNET_EC_NAMESTORE_RECORD_EXISTS = 5011,
170
171
172 /**
173 * Record size exceeds maximum limit.
174 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
175 */
176 GNUNET_EC_NAMESTORE_RECORD_TOO_BIG = 5012,
177
178
179 /**
180 * There was an error in the database backend.
181 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
182 */
183 GNUNET_EC_NAMESTORE_BACKEND_FAILED = 5013,
184
185
186 /**
187 * Failed to store the given records.
188 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
189 */
190 GNUNET_EC_NAMESTORE_STORE_FAILED = 5014,
191
192
193 /**
194 * Label invalid or malformed.
195 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
196 */
197 GNUNET_EC_NAMESTORE_LABEL_INVALID = 5015,
198
199
200};
201
202
203/**
204 * Returns a hint for a given error code.
205 *
206 * @param ec the error code.
207 * @return the hint if it could be found, otherwise "<no hint found>"
208 */
209const char *
210GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec);
211
212
213/**
214 * Return HTTP status for a given error code.
215 *
216 * @param ec the error code.
217 * @return the HTTP status code for the given @a ec, UINT_MAX if not found
218 */
219unsigned int
220GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec);
221
222
223/**
224 * Return HTTP status for a given error code that is guaranteed
225 * to work (no corner cases).
226 *
227 * @param ec the error code.
228 * @return the HTTP status code for the given @a ec, 500 if
229 * the @a ec is not found or is a client-side code
230 */
231unsigned int
232GNUNET_ErrorCode_get_http_status_safe (enum GNUNET_ErrorCode ec);
233
234
235#if 0 /* keep Emacsens' auto-indent happy */
236{
237#endif
238#ifdef __cplusplus
239}
240#endif
241
242#endif
diff --git a/src/include/gnunet_fragmentation_lib.h b/src/include/gnunet_fragmentation_lib.h
deleted file mode 100644
index c964b5434..000000000
--- a/src/include/gnunet_fragmentation_lib.h
+++ /dev/null
@@ -1,230 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009, 2011, 2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Library to help fragment messages
25 *
26 * @defgroup fragmentation Fragmentation library
27 * Library to help fragment messages
28 * @{
29 *
30 * @todo Consider additional flow-control for sending from
31 * fragmentation based on continuations.
32 */
33
34#ifndef GNUNET_FRAGMENTATION_LIB_H
35#define GNUNET_FRAGMENTATION_LIB_H
36
37#include "gnunet_util_lib.h"
38#include "gnunet_bandwidth_lib.h"
39#include "gnunet_statistics_service.h"
40
41#ifdef __cplusplus
42extern "C"
43{
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
49
50/**
51 * Fragmentation context.
52 */
53struct GNUNET_FRAGMENT_Context;
54
55
56/**
57 * Function that is called with messages created by the fragmentation
58 * module. In the case of the 'proc' callback of the
59 * #GNUNET_FRAGMENT_context_create() function, this function must
60 * eventually call #GNUNET_FRAGMENT_context_transmission_done().
61 *
62 * @param cls closure
63 * @param msg the message that was created
64 */
65typedef void
66(*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
67 const struct GNUNET_MessageHeader *msg);
68
69
70/**
71 * Create a fragmentation context for the given message.
72 * Fragments the message into fragments of size @a mtu or
73 * less. Calls @a proc on each un-acknowledged fragment,
74 * using both the expected @a msg_delay between messages and
75 * acknowledgements and the given @a tracker to guide the
76 * frequency of calls to @a proc.
77 *
78 * @param stats statistics context
79 * @param mtu the maximum message size for each fragment
80 * @param tracker bandwidth tracker to use for flow control (can be NULL)
81 * @param msg_delay initial delay to insert between fragment transmissions
82 * based on previous messages
83 * @param ack_delay expected delay between fragment transmission
84 * and ACK based on previous messages
85 * @param msg the message to fragment
86 * @param proc function to call for each fragment to transmit
87 * @param proc_cls closure for proc
88 * @return the fragmentation context
89 */
90struct GNUNET_FRAGMENT_Context *
91GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
92 uint16_t mtu,
93 struct GNUNET_BANDWIDTH_Tracker *tracker,
94 struct GNUNET_TIME_Relative msg_delay,
95 struct GNUNET_TIME_Relative ack_delay,
96 const struct GNUNET_MessageHeader *msg,
97 GNUNET_FRAGMENT_MessageProcessor proc,
98 void *proc_cls);
99
100
101/**
102 * Continuation to call from the 'proc' function after the fragment
103 * has been transmitted (and hence the next fragment can now be
104 * given to proc).
105 *
106 * @param fc fragmentation context
107 */
108void
109GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
110
111
112/**
113 * Process an acknowledgement message we got from the other
114 * side (to control re-transmits).
115 *
116 * @param fc fragmentation context
117 * @param msg acknowledgement message we received
118 * @return #GNUNET_OK if this ack completes the work of the 'fc'
119 * (all fragments have been received);
120 * #GNUNET_NO if more messages are pending
121 * #GNUNET_SYSERR if this ack is not valid for this fc
122 */
123int
124GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
125 const struct GNUNET_MessageHeader *msg);
126
127
128/**
129 * Destroy the given fragmentation context (stop calling 'proc', free
130 * resources).
131 *
132 * @param fc fragmentation context
133 * @param msg_delay where to store average delay between individual message transmissions the
134 * last message (OUT only)
135 * @param ack_delay where to store average delay between transmission and ACK for the
136 * last message, set to FOREVER if the message was not fully transmitted (OUT only)
137 */
138void
139GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
140 struct GNUNET_TIME_Relative *msg_delay,
141 struct GNUNET_TIME_Relative *ack_delay);
142
143
144/**
145 * Convert an ACK message to a printable format suitable for logging.
146 *
147 * @param ack message to print
148 * @return ack in human-readable format
149 */
150const char *
151GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack);
152
153
154/**
155 * Defragmentation context (one per connection).
156 */
157struct GNUNET_DEFRAGMENT_Context;
158
159
160/**
161 * Function that is called with acknowledgement messages created by
162 * the fragmentation module. Acknowledgements are cumulative,
163 * so it is OK to only transmit the 'latest' ack message for the same
164 * message ID.
165 *
166 * @param cls closure
167 * @param id unique message ID (modulo collisions)
168 * @param msg the message that was created
169 */
170typedef void
171(*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
172 uint32_t id,
173 const struct GNUNET_MessageHeader *msg);
174
175
176/**
177 * Create a defragmentation context.
178 *
179 * @param stats statistics context
180 * @param mtu the maximum message size for each fragment
181 * @param num_msgs how many fragmented messages
182 * to we defragment at most at the same time?
183 * @param cls closure for @a proc and @a ackp
184 * @param proc function to call with defragmented messages
185 * @param ackp function to call with acknowledgements (to send
186 * back to the other side)
187 * @return the defragmentation context
188 */
189struct GNUNET_DEFRAGMENT_Context *
190GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
191 uint16_t mtu,
192 unsigned int num_msgs,
193 void *cls,
194 GNUNET_FRAGMENT_MessageProcessor proc,
195 GNUNET_DEFRAGMENT_AckProcessor ackp);
196
197
198/**
199 * Destroy the given defragmentation context.
200 *
201 * @param dc defragmentation context
202 */
203void
204GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
205
206
207/**
208 * We have received a fragment. Process it.
209 *
210 * @param dc the context
211 * @param msg the message that was received
212 * @return #GNUNET_OK on success,
213 * #GNUNET_NO if this was a duplicate,
214 * #GNUNET_SYSERR on error
215 */
216int
217GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
218 const struct GNUNET_MessageHeader *msg);
219
220
221#if 0 /* keep Emacsens' auto-indent happy */
222{
223#endif
224#ifdef __cplusplus
225}
226#endif
227
228#endif
229
230/** @} */ /* end of group */
diff --git a/src/include/gnunet_friends_lib.h b/src/include/gnunet_friends_lib.h
deleted file mode 100644
index d591ea082..000000000
--- a/src/include/gnunet_friends_lib.h
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 Christian Grothoff
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Library to read and write the FRIENDS file
26 *
27 * @defgroup friends Friends library
28 * Library to read and write the FRIENDS file
29 * @{
30 */
31#ifndef GNUNET_FRIENDS_LIB_H
32#define GNUNET_FRIENDS_LIB_H
33
34#ifdef __cplusplus
35extern "C"
36{
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42#include "gnunet_util_lib.h"
43
44
45/**
46 * Signature of a function called on each friend found.
47 *
48 * @param cls closure
49 * @param friend_id peer identity of the friend
50 */
51typedef void (*GNUNET_FRIENDS_Callback)(void *cls,
52 const struct
53 GNUNET_PeerIdentity *friend_id);
54
55
56/**
57 * Parse the FRIENDS file.
58 *
59 * @param cfg our configuration
60 * @param cb function to call on each friend found
61 * @param cb_cls closure for @a cb
62 * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors
63 */
64int
65GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
66 GNUNET_FRIENDS_Callback cb,
67 void *cb_cls);
68
69
70/**
71 * Handle for writing a friends file.
72 */
73struct GNUNET_FRIENDS_Writer;
74
75
76/**
77 * Start writing a fresh FRIENDS file. Will make a backup of the
78 * old one.
79 *
80 * @param cfg configuration to use.
81 * @return NULL on error
82 */
83struct GNUNET_FRIENDS_Writer *
84GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
85
86
87/**
88 * Finish writing out the friends file.
89 *
90 * @param w write handle
91 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
92 */
93int
94GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w);
95
96
97/**
98 * Add a friend to the friends file.
99 *
100 * @param w write handle
101 * @param friend_id friend to add
102 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
103 */
104int
105GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
106 const struct GNUNET_PeerIdentity *friend_id);
107
108
109#if 0 /* keep Emacsens' auto-indent happy */
110{
111#endif
112#ifdef __cplusplus
113}
114#endif
115
116#endif
117
118/** @} */ /* end of group */
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 686035e2c..a05e07ac5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup fs_l2 File sharing and support services/libraries
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * 25 *
23 * @file 26 * @file
@@ -33,6 +36,8 @@
33#ifndef GNUNET_FS_LIB_H 36#ifndef GNUNET_FS_LIB_H
34#define GNUNET_FS_LIB_H 37#define GNUNET_FS_LIB_H
35 38
39
40#include "gnunet_common.h"
36#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
37 42
38#ifdef __cplusplus 43#ifdef __cplusplus
@@ -66,6 +71,106 @@ extern "C"
66 */ 71 */
67#define GNUNET_FS_VERSION 0x00090300 72#define GNUNET_FS_VERSION 0x00090300
68 73
74#if GNUNET_FS_EXTRACTOR_ENABLED
75
76#include <extractor.h>
77
78#else
79
80/* definitions from extractor.h we need for the build */
81
82/**
83 * Enumeration defining various sources of keywords. See also
84 * http://dublincore.org/documents/1998/09/dces/
85 */
86enum EXTRACTOR_MetaType
87{
88 EXTRACTOR_METATYPE_RESERVED = 0,
89 EXTRACTOR_METATYPE_MIMETYPE = 1,
90 EXTRACTOR_METATYPE_FILENAME = 2,
91 EXTRACTOR_METATYPE_COMMENT = 3,
92 EXTRACTOR_METATYPE_TITLE = 4,
93 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
94 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
95 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
96 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
97 EXTRACTOR_METATYPE_URL = 29,
98 EXTRACTOR_METATYPE_URI = 30,
99 EXTRACTOR_METATYPE_ISRC = 31,
100 EXTRACTOR_METATYPE_UNKNOWN = 45,
101 EXTRACTOR_METATYPE_DESCRIPTION = 46,
102 EXTRACTOR_METATYPE_KEYWORDS = 49,
103 EXTRACTOR_METATYPE_SUBJECT = 52,
104 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
105 EXTRACTOR_METATYPE_THUMBNAIL = 114,
106 EXTRACTOR_METATYPE_ALBUM = 129,
107 EXTRACTOR_METATYPE_ARTIST = 130,
108 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
109 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
110 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
111};
112
113/**
114 * Format in which the extracted meta data is presented.
115 */
116enum EXTRACTOR_MetaFormat
117{
118 /**
119 * Format is unknown.
120 */
121 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
122
123 /**
124 * 0-terminated, UTF-8 encoded string. "data_len"
125 * is strlen(data)+1.
126 */
127 EXTRACTOR_METAFORMAT_UTF8 = 1,
128
129 /**
130 * Some kind of binary format, see given Mime type.
131 */
132 EXTRACTOR_METAFORMAT_BINARY = 2,
133
134 /**
135 * 0-terminated string. The specific encoding is unknown.
136 * "data_len" is strlen (data)+1.
137 */
138 EXTRACTOR_METAFORMAT_C_STRING = 3
139};
140
141
142/**
143 * Type of a function that libextractor calls for each
144 * meta data item found.
145 *
146 * @param cls closure (user-defined)
147 * @param plugin_name name of the plugin that produced this value;
148 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
149 * used in the main libextractor library and yielding
150 * meta data).
151 * @param type libextractor-type describing the meta data
152 * @param format basic format information about @a data
153 * @param data_mime_type mime-type of @a data (not of the original file);
154 * can be NULL (if mime-type is not known)
155 * @param data actual meta-data found
156 * @param data_len number of bytes in @a data
157 * @return 0 to continue extracting, 1 to abort
158 */
159typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
160 const char *plugin_name,
161 enum EXTRACTOR_MetaType type,
162 enum EXTRACTOR_MetaFormat format,
163 const char *data_mime_type,
164 const char *data,
165 size_t data_len);
166
167#endif
168
169#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
170/* hack for LE < 0.6.3 */
171#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
172#endif
173
69 174
70/* ******************** URI API *********************** */ 175/* ******************** URI API *********************** */
71 176
@@ -88,6 +193,12 @@ extern "C"
88 */ 193 */
89struct GNUNET_FS_Uri; 194struct GNUNET_FS_Uri;
90 195
196/**
197 * @ingroup metadata
198 * Meta data to associate with a file, directory or namespace.
199 */
200struct GNUNET_FS_MetaData;
201
91 202
92/** 203/**
93 * Iterator over keywords 204 * Iterator over keywords
@@ -108,7 +219,7 @@ typedef int
108 * into HashMaps. The key may change between FS implementations. 219 * into HashMaps. The key may change between FS implementations.
109 * 220 *
110 * @param uri uri to convert to a unique key 221 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key 222 * @param key where to store the unique key
112 * @return #GNUNET_OK on success 223 * @return #GNUNET_OK on success
113 */ 224 */
114int 225int
@@ -414,6 +525,17 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
414 525
415 526
416/** 527/**
528 * What is the hash of the original file's content
529 * that this URI refers to?
530 *
531 * @param uri the CHK URI to inspect
532 * @return hash of the file as specified in the CHK URI
533 */
534const struct GNUNET_HashCode*
535GNUNET_FS_uri_chk_get_file_hash (const struct GNUNET_FS_Uri *uri);
536
537
538/**
417 * Is this a location URI? 539 * Is this a location URI?
418 * 540 *
419 * @param uri the uri to check 541 * @param uri the uri to check
@@ -432,7 +554,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
432 * @return NULL on error, otherwise a KSK URI 554 * @return NULL on error, otherwise a KSK URI
433 */ 555 */
434struct GNUNET_FS_Uri * 556struct GNUNET_FS_Uri *
435GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData 557GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_FS_MetaData
436 *md); 558 *md);
437 559
438 560
@@ -461,14 +583,14 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName,
461 * @param name long name of the option 583 * @param name long name of the option
462 * @param argumentHelp help text for the option argument 584 * @param argumentHelp help text for the option argument
463 * @param description long help text for the option 585 * @param description long help text for the option
464 * @param[out] metadata set to the desired value 586 * @param[out] meta metadata set to the desired value
465 */ 587 */
466struct GNUNET_GETOPT_CommandLineOption 588struct GNUNET_GETOPT_CommandLineOption
467GNUNET_FS_GETOPT_METADATA (char shortName, 589GNUNET_FS_GETOPT_METADATA (char shortName,
468 const char *name, 590 const char *name,
469 const char *argumentHelp, 591 const char *argumentHelp,
470 const char *description, 592 const char *description,
471 struct GNUNET_CONTAINER_MetaData **meta); 593 struct GNUNET_FS_MetaData **meta);
472 594
473/** 595/**
474 * Command-line option parser function that allows the user to specify 596 * Command-line option parser function that allows the user to specify
@@ -477,7 +599,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
477 * the metadata must be passed as the "scls" argument. 599 * the metadata must be passed as the "scls" argument.
478 * 600 *
479 * @param ctx command line processor context 601 * @param ctx command line processor context
480 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **` 602 * @param scls must be of type `struct GNUNET_FS_MetaData **`
481 * @param option name of the option (typically 'k') 603 * @param option name of the option (typically 'k')
482 * @param value command line argument given 604 * @param value command line argument given
483 * @return #GNUNET_OK on success 605 * @return #GNUNET_OK on success
@@ -1095,7 +1217,7 @@ struct GNUNET_FS_ProgressInfo
1095 /** 1217 /**
1096 * Known metadata for the download. 1218 * Known metadata for the download.
1097 */ 1219 */
1098 const struct GNUNET_CONTAINER_MetaData *meta; 1220 const struct GNUNET_FS_MetaData *meta;
1099 } start; 1221 } start;
1100 1222
1101 /** 1223 /**
@@ -1107,7 +1229,7 @@ struct GNUNET_FS_ProgressInfo
1107 /** 1229 /**
1108 * Known metadata for the download. 1230 * Known metadata for the download.
1109 */ 1231 */
1110 const struct GNUNET_CONTAINER_MetaData *meta; 1232 const struct GNUNET_FS_MetaData *meta;
1111 1233
1112 /** 1234 /**
1113 * Error message, NULL if we have not encountered any error yet. 1235 * Error message, NULL if we have not encountered any error yet.
@@ -1192,7 +1314,7 @@ struct GNUNET_FS_ProgressInfo
1192 /** 1314 /**
1193 * Metadata for the search result. 1315 * Metadata for the search result.
1194 */ 1316 */
1195 const struct GNUNET_CONTAINER_MetaData *meta; 1317 const struct GNUNET_FS_MetaData *meta;
1196 1318
1197 /** 1319 /**
1198 * URI for the search result. 1320 * URI for the search result.
@@ -1220,7 +1342,7 @@ struct GNUNET_FS_ProgressInfo
1220 /** 1342 /**
1221 * Metadata for the search result. 1343 * Metadata for the search result.
1222 */ 1344 */
1223 const struct GNUNET_CONTAINER_MetaData *meta; 1345 const struct GNUNET_FS_MetaData *meta;
1224 1346
1225 /** 1347 /**
1226 * URI for the search result. 1348 * URI for the search result.
@@ -1267,7 +1389,7 @@ struct GNUNET_FS_ProgressInfo
1267 /** 1389 /**
1268 * Metadata for the search result. 1390 * Metadata for the search result.
1269 */ 1391 */
1270 const struct GNUNET_CONTAINER_MetaData *meta; 1392 const struct GNUNET_FS_MetaData *meta;
1271 1393
1272 /** 1394 /**
1273 * URI for the search result. 1395 * URI for the search result.
@@ -1319,7 +1441,7 @@ struct GNUNET_FS_ProgressInfo
1319 /** 1441 /**
1320 * Metadata for the search result. 1442 * Metadata for the search result.
1321 */ 1443 */
1322 const struct GNUNET_CONTAINER_MetaData *meta; 1444 const struct GNUNET_FS_MetaData *meta;
1323 1445
1324 /** 1446 /**
1325 * URI for the search result. 1447 * URI for the search result.
@@ -1347,7 +1469,7 @@ struct GNUNET_FS_ProgressInfo
1347 /** 1469 /**
1348 * Metadata for the search result. 1470 * Metadata for the search result.
1349 */ 1471 */
1350 const struct GNUNET_CONTAINER_MetaData *meta; 1472 const struct GNUNET_FS_MetaData *meta;
1351 1473
1352 /** 1474 /**
1353 * URI for the search result. 1475 * URI for the search result.
@@ -1402,7 +1524,7 @@ struct GNUNET_FS_ProgressInfo
1402 /** 1524 /**
1403 * Metadata for the namespace. 1525 * Metadata for the namespace.
1404 */ 1526 */
1405 const struct GNUNET_CONTAINER_MetaData *meta; 1527 const struct GNUNET_FS_MetaData *meta;
1406 1528
1407 /** 1529 /**
1408 * Public key of the namespace. 1530 * Public key of the namespace.
@@ -1702,7 +1824,7 @@ typedef int
1702(*GNUNET_FS_FileInformationProcessor) (void *cls, 1824(*GNUNET_FS_FileInformationProcessor) (void *cls,
1703 struct GNUNET_FS_FileInformation *fi, 1825 struct GNUNET_FS_FileInformation *fi,
1704 uint64_t length, 1826 uint64_t length,
1705 struct GNUNET_CONTAINER_MetaData *meta, 1827 struct GNUNET_FS_MetaData *meta,
1706 struct GNUNET_FS_Uri **uri, 1828 struct GNUNET_FS_Uri **uri,
1707 struct GNUNET_FS_BlockOptions *bo, 1829 struct GNUNET_FS_BlockOptions *bo,
1708 int *do_index, 1830 int *do_index,
@@ -1729,7 +1851,8 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1729 * @return "filename" field of the structure (can be NULL) 1851 * @return "filename" field of the structure (can be NULL)
1730 */ 1852 */
1731const char * 1853const char *
1732GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s); 1854GNUNET_FS_file_information_get_filename (const struct
1855 GNUNET_FS_FileInformation *s);
1733 1856
1734 1857
1735/** 1858/**
@@ -1766,7 +1889,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1766 const struct 1889 const struct
1767 GNUNET_FS_Uri *keywords, 1890 GNUNET_FS_Uri *keywords,
1768 const struct 1891 const struct
1769 GNUNET_CONTAINER_MetaData *meta, 1892 GNUNET_FS_MetaData *meta,
1770 int do_index, 1893 int do_index,
1771 const struct 1894 const struct
1772 GNUNET_FS_BlockOptions *bo); 1895 GNUNET_FS_BlockOptions *bo);
@@ -1796,7 +1919,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1796 const struct 1919 const struct
1797 GNUNET_FS_Uri *keywords, 1920 GNUNET_FS_Uri *keywords,
1798 const struct 1921 const struct
1799 GNUNET_CONTAINER_MetaData *meta, 1922 GNUNET_FS_MetaData *meta,
1800 int do_index, 1923 int do_index,
1801 const struct 1924 const struct
1802 GNUNET_FS_BlockOptions *bo); 1925 GNUNET_FS_BlockOptions *bo);
@@ -1855,7 +1978,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1855 const struct GNUNET_FS_Uri 1978 const struct GNUNET_FS_Uri
1856 *keywords, 1979 *keywords,
1857 const struct 1980 const struct
1858 GNUNET_CONTAINER_MetaData *meta, 1981 GNUNET_FS_MetaData *meta,
1859 int do_index, 1982 int do_index,
1860 const struct 1983 const struct
1861 GNUNET_FS_BlockOptions *bo); 1984 GNUNET_FS_BlockOptions *bo);
@@ -1879,7 +2002,7 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1879 const struct GNUNET_FS_Uri 2002 const struct GNUNET_FS_Uri
1880 *keywords, 2003 *keywords,
1881 const struct 2004 const struct
1882 GNUNET_CONTAINER_MetaData 2005 GNUNET_FS_MetaData
1883 *meta, 2006 *meta,
1884 const struct 2007 const struct
1885 GNUNET_FS_BlockOptions *bo, 2008 GNUNET_FS_BlockOptions *bo,
@@ -2038,7 +2161,7 @@ struct GNUNET_FS_PublishKskContext;
2038struct GNUNET_FS_PublishKskContext * 2161struct GNUNET_FS_PublishKskContext *
2039GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 2162GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2040 const struct GNUNET_FS_Uri *ksk_uri, 2163 const struct GNUNET_FS_Uri *ksk_uri,
2041 const struct GNUNET_CONTAINER_MetaData *meta, 2164 const struct GNUNET_FS_MetaData *meta,
2042 const struct GNUNET_FS_Uri *uri, 2165 const struct GNUNET_FS_Uri *uri,
2043 const struct GNUNET_FS_BlockOptions *bo, 2166 const struct GNUNET_FS_BlockOptions *bo,
2044 enum GNUNET_FS_PublishOptions options, 2167 enum GNUNET_FS_PublishOptions options,
@@ -2080,7 +2203,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2080 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 2203 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2081 const char *identifier, 2204 const char *identifier,
2082 const char *update, 2205 const char *update,
2083 const struct GNUNET_CONTAINER_MetaData *meta, 2206 const struct GNUNET_FS_MetaData *meta,
2084 const struct GNUNET_FS_Uri *uri, 2207 const struct GNUNET_FS_Uri *uri,
2085 const struct GNUNET_FS_BlockOptions *bo, 2208 const struct GNUNET_FS_BlockOptions *bo,
2086 enum GNUNET_FS_PublishOptions options, 2209 enum GNUNET_FS_PublishOptions options,
@@ -2176,7 +2299,7 @@ typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2176 const struct 2299 const struct
2177 GNUNET_FS_Uri *last_uri, 2300 GNUNET_FS_Uri *last_uri,
2178 const struct 2301 const struct
2179 GNUNET_CONTAINER_MetaData * 2302 GNUNET_FS_MetaData *
2180 last_meta, 2303 last_meta,
2181 const char *next_id); 2304 const char *next_id);
2182 2305
@@ -2286,7 +2409,7 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2286struct GNUNET_FS_SearchResult * 2409struct GNUNET_FS_SearchResult *
2287GNUNET_FS_probe (struct GNUNET_FS_Handle *h, 2410GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2288 const struct GNUNET_FS_Uri *uri, 2411 const struct GNUNET_FS_Uri *uri,
2289 const struct GNUNET_CONTAINER_MetaData *meta, 2412 const struct GNUNET_FS_MetaData *meta,
2290 void *client_info, 2413 void *client_info,
2291 uint32_t anonymity); 2414 uint32_t anonymity);
2292 2415
@@ -2374,7 +2497,7 @@ enum GNUNET_FS_DownloadOptions
2374struct GNUNET_FS_DownloadContext * 2497struct GNUNET_FS_DownloadContext *
2375GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 2498GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2376 const struct GNUNET_FS_Uri *uri, 2499 const struct GNUNET_FS_Uri *uri,
2377 const struct GNUNET_CONTAINER_MetaData *meta, 2500 const struct GNUNET_FS_MetaData *meta,
2378 const char *filename, const char *tempname, 2501 const char *filename, const char *tempname,
2379 uint64_t offset, uint64_t length, uint32_t anonymity, 2502 uint64_t offset, uint64_t length, uint32_t anonymity,
2380 enum GNUNET_FS_DownloadOptions options, void *cctx, 2503 enum GNUNET_FS_DownloadOptions options, void *cctx,
@@ -2468,7 +2591,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2468 * we have no mime-type information (treat as #GNUNET_NO) 2591 * we have no mime-type information (treat as #GNUNET_NO)
2469 */ 2592 */
2470int 2593int
2471GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData 2594GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_FS_MetaData
2472 *md); 2595 *md);
2473 2596
2474 2597
@@ -2479,7 +2602,7 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2479 * @param md metadata to add mimetype to 2602 * @param md metadata to add mimetype to
2480 */ 2603 */
2481void 2604void
2482GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); 2605GNUNET_FS_meta_data_make_directory (struct GNUNET_FS_MetaData *md);
2483 2606
2484 2607
2485/** 2608/**
@@ -2490,7 +2613,7 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2490 */ 2613 */
2491char * 2614char *
2492GNUNET_FS_meta_data_suggest_filename (const struct 2615GNUNET_FS_meta_data_suggest_filename (const struct
2493 GNUNET_CONTAINER_MetaData *md); 2616 GNUNET_FS_MetaData *md);
2494 2617
2495 2618
2496/** 2619/**
@@ -2513,7 +2636,7 @@ typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2513 const struct GNUNET_FS_Uri * 2636 const struct GNUNET_FS_Uri *
2514 uri, 2637 uri,
2515 const struct 2638 const struct
2516 GNUNET_CONTAINER_MetaData * 2639 GNUNET_FS_MetaData *
2517 meta, size_t length, 2640 meta, size_t length,
2518 const void *data); 2641 const void *data);
2519 2642
@@ -2556,7 +2679,7 @@ struct GNUNET_FS_DirectoryBuilder;
2556 * @param mdir metadata for the directory 2679 * @param mdir metadata for the directory
2557 */ 2680 */
2558struct GNUNET_FS_DirectoryBuilder * 2681struct GNUNET_FS_DirectoryBuilder *
2559GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData 2682GNUNET_FS_directory_builder_create (const struct GNUNET_FS_MetaData
2560 *mdir); 2683 *mdir);
2561 2684
2562 2685
@@ -2573,7 +2696,7 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2573void 2696void
2574GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, 2697GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2575 const struct GNUNET_FS_Uri *uri, 2698 const struct GNUNET_FS_Uri *uri,
2576 const struct GNUNET_CONTAINER_MetaData *md, 2699 const struct GNUNET_FS_MetaData *md,
2577 const void *data); 2700 const void *data);
2578 2701
2579 2702
@@ -2688,7 +2811,7 @@ struct GNUNET_FS_ShareTreeItem
2688 /** 2811 /**
2689 * Metadata for this file or directory 2812 * Metadata for this file or directory
2690 */ 2813 */
2691 struct GNUNET_CONTAINER_MetaData *meta; 2814 struct GNUNET_FS_MetaData *meta;
2692 2815
2693 /** 2816 /**
2694 * Keywords for this file or directory (derived from metadata). 2817 * Keywords for this file or directory (derived from metadata).
@@ -2777,6 +2900,336 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2777void 2900void
2778GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel); 2901GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2779 2902
2903/**
2904 * Meta data processing
2905 * @defgroup metadata Metadata
2906 * GNU libextractor key-value pairs
2907 */
2908
2909
2910/* ****************** metadata ******************* */
2911
2912
2913/**
2914 * @ingroup metadata
2915 * Create a fresh meta data container.
2916 *
2917 * @return empty meta-data container
2918 */
2919struct GNUNET_FS_MetaData *
2920GNUNET_FS_meta_data_create (void);
2921
2922
2923/**
2924 * @ingroup metadata
2925 * Duplicate a MetaData token.
2926 *
2927 * @param md what to duplicate
2928 * @return duplicate meta-data container
2929 */
2930struct GNUNET_FS_MetaData *
2931GNUNET_FS_meta_data_duplicate (
2932 const struct GNUNET_FS_MetaData *md);
2933
2934
2935/**
2936 * @ingroup metadata
2937 * Free meta data.
2938 *
2939 * @param md what to free
2940 */
2941void
2942GNUNET_FS_meta_data_destroy (struct GNUNET_FS_MetaData *md);
2943
2944
2945/**
2946 * @ingroup metadata
2947 * Test if two MDs are equal. We consider them equal if
2948 * the meta types, formats and content match (we do not
2949 * include the mime types and plugins names in this
2950 * consideration).
2951 *
2952 * @param md1 first value to check
2953 * @param md2 other value to check
2954 * @return #GNUNET_YES if they are equal
2955 */
2956int
2957GNUNET_FS_meta_data_test_equal (
2958 const struct GNUNET_FS_MetaData *md1,
2959 const struct GNUNET_FS_MetaData *md2);
2960
2961
2962/**
2963 * @ingroup metadata
2964 * Extend metadata.
2965 *
2966 * @param md metadata to extend
2967 * @param plugin_name name of the plugin that produced this value;
2968 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
2969 * used in the main libextractor library and yielding
2970 * meta data).
2971 * @param type libextractor-type describing the meta data
2972 * @param format basic format information about data
2973 * @param data_mime_type mime-type of data (not of the original file);
2974 * can be NULL (if mime-type is not known)
2975 * @param data actual meta-data found
2976 * @param data_size number of bytes in data
2977 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
2978 * data_mime_type and plugin_name are not considered for "exists" checks
2979 */
2980int
2981GNUNET_FS_meta_data_insert (struct GNUNET_FS_MetaData *md,
2982 const char *plugin_name,
2983 enum EXTRACTOR_MetaType type,
2984 enum EXTRACTOR_MetaFormat format,
2985 const char *data_mime_type,
2986 const char *data,
2987 size_t data_size);
2988
2989
2990/**
2991 * @ingroup metadata
2992 * Extend metadata. Merges the meta data from the second argument
2993 * into the first, discarding duplicate key-value pairs.
2994 *
2995 * @param md metadata to extend
2996 * @param in metadata to merge
2997 */
2998void
2999GNUNET_FS_meta_data_merge (struct GNUNET_FS_MetaData *md,
3000 const struct GNUNET_FS_MetaData *in);
3001
3002
3003/**
3004 * @ingroup metadata
3005 * Remove an item.
3006 *
3007 * @param md metadata to manipulate
3008 * @param type type of the item to remove
3009 * @param data specific value to remove, NULL to remove all
3010 * entries of the given type
3011 * @param data_size number of bytes in data
3012 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
3013 */
3014int
3015GNUNET_FS_meta_data_delete (struct GNUNET_FS_MetaData *md,
3016 enum EXTRACTOR_MetaType type,
3017 const char *data,
3018 size_t data_size);
3019
3020
3021/**
3022 * @ingroup metadata
3023 * Remove all items in the container.
3024 *
3025 * @param md metadata to manipulate
3026 */
3027void
3028GNUNET_FS_meta_data_clear (struct GNUNET_FS_MetaData *md);
3029
3030
3031/**
3032 * @ingroup metadata
3033 * Add the current time as the publication date
3034 * to the meta-data.
3035 *
3036 * @param md metadata to modify
3037 */
3038void
3039GNUNET_FS_meta_data_add_publication_date (
3040 struct GNUNET_FS_MetaData *md);
3041
3042
3043/**
3044 * @ingroup metadata
3045 * Iterate over MD entries.
3046 *
3047 * @param md metadata to inspect
3048 * @param iter function to call on each entry, return 0 to continue to iterate
3049 * and 1 to abort iteration in this function (GNU libextractor API!)
3050 * @param iter_cls closure for @a iter
3051 * @return number of entries
3052 */
3053int
3054GNUNET_FS_meta_data_iterate (const struct GNUNET_FS_MetaData *md,
3055 EXTRACTOR_MetaDataProcessor iter,
3056 void *iter_cls);
3057
3058
3059/**
3060 * @ingroup metadata
3061 * Get the first MD entry of the given type. Caller
3062 * is responsible for freeing the return value.
3063 * Also, only meta data items that are strings (0-terminated)
3064 * are returned by this function.
3065 *
3066 * @param md metadata to inspect
3067 * @param type type to look for
3068 * @return NULL if no entry was found
3069 */
3070char *
3071GNUNET_FS_meta_data_get_by_type (
3072 const struct GNUNET_FS_MetaData *md,
3073 enum EXTRACTOR_MetaType type);
3074
3075
3076/**
3077 * @ingroup metadata
3078 * Get the first matching MD entry of the given types. Caller is
3079 * responsible for freeing the return value. Also, only meta data
3080 * items that are strings (0-terminated) are returned by this
3081 * function.
3082 *
3083 * @param md metadata to inspect
3084 * @param ... -1-terminated list of types
3085 * @return NULL if we do not have any such entry,
3086 * otherwise client is responsible for freeing the value!
3087 */
3088char *
3089GNUNET_FS_meta_data_get_first_by_types (
3090 const struct GNUNET_FS_MetaData *md,
3091 ...);
3092
3093/**
3094 * @ingroup metadata
3095 * Get a thumbnail from the meta-data (if present). Only matches meta
3096 * data with mime type "image" and binary format.
3097 *
3098 * @param md metadata to inspect
3099 * @param thumb will be set to the thumbnail data. Must be
3100 * freed by the caller!
3101 * @return number of bytes in thumbnail, 0 if not available
3102 */
3103size_t
3104GNUNET_FS_meta_data_get_thumbnail (
3105 const struct GNUNET_FS_MetaData *md,
3106 unsigned char **thumb);
3107
3108
3109/**
3110 * @ingroup metadata
3111 * Options for metadata serialization.
3112 */
3113enum GNUNET_FS_MetaDataSerializationOptions
3114{
3115 /**
3116 * @ingroup metadata
3117 * Serialize all of the data.
3118 */
3119 GNUNET_FS_META_DATA_SERIALIZE_FULL = 0,
3120
3121 /**
3122 * @ingroup metadata
3123 * If not enough space is available, it is acceptable
3124 * to only serialize some of the metadata.
3125 */
3126 GNUNET_FS_META_DATA_SERIALIZE_PART = 1,
3127
3128 /**
3129 * @ingroup metadata
3130 * Speed is of the essence, do not allow compression.
3131 */
3132 GNUNET_FS_META_DATA_SERIALIZE_NO_COMPRESS = 2
3133};
3134
3135
3136/**
3137 * @ingroup metadata
3138 * Serialize meta-data to target.
3139 *
3140 * @param md metadata to serialize
3141 * @param target where to write the serialized metadata;
3142 * *target can be NULL, in which case memory is allocated
3143 * @param max maximum number of bytes available
3144 * @param opt is it ok to just write SOME of the
3145 * meta-data to match the size constraint,
3146 * possibly discarding some data?
3147 * @return number of bytes written on success,
3148 * -1 on error (typically: not enough
3149 * space)
3150 */
3151ssize_t
3152GNUNET_FS_meta_data_serialize (
3153 const struct GNUNET_FS_MetaData *md,
3154 char **target,
3155 size_t max,
3156 enum GNUNET_FS_MetaDataSerializationOptions opt);
3157
3158
3159/**
3160 * @ingroup metadata
3161 * Get the size of the full meta-data in serialized form.
3162 *
3163 * @param md metadata to inspect
3164 * @return number of bytes needed for serialization, -1 on error
3165 */
3166ssize_t
3167GNUNET_FS_meta_data_get_serialized_size (
3168 const struct GNUNET_FS_MetaData *md);
3169
3170
3171/**
3172 * @ingroup metadata
3173 * Deserialize meta-data. Initializes md.
3174 *
3175 * @param input serialized meta-data.
3176 * @param size number of bytes available
3177 * @return MD on success, NULL on error (e.g.
3178 * bad format)
3179 */
3180struct GNUNET_FS_MetaData *
3181GNUNET_FS_meta_data_deserialize (const char *input, size_t size);
3182
3183/**
3184 * Write a metadata container.
3185 *
3186 * @param h the IO handle to write to
3187 * @param what what is being written (for error message creation)
3188 * @param m metadata to write
3189 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
3190 */
3191enum GNUNET_GenericReturnValue
3192GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
3193 const char *what,
3194 const struct GNUNET_FS_MetaData *m);
3195
3196/**
3197 * Create the specification to read a metadata container.
3198 *
3199 * @param what describes what is being read (for error message creation)
3200 * @param result the buffer to store a pointer to the (allocated) metadata
3201 * @return the read spec
3202 */
3203struct GNUNET_BIO_ReadSpec
3204GNUNET_FS_read_spec_meta_data (const char *what,
3205 struct GNUNET_FS_MetaData **result);
3206
3207
3208
3209/**
3210 * Create the specification to write a metadata container.
3211 *
3212 * @param what what is being written (for error message creation)
3213 * @param m metadata to write
3214 * @return the write spec
3215 */
3216struct GNUNET_BIO_WriteSpec
3217GNUNET_FS_write_spec_meta_data (const char *what,
3218 const struct GNUNET_FS_MetaData *m);
3219
3220/**
3221 * Read a metadata container.
3222 *
3223 * @param h handle to an open file
3224 * @param what describes what is being read (for error message creation)
3225 * @param result the buffer to store a pointer to the (allocated) metadata
3226 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
3227 */
3228enum GNUNET_GenericReturnValue
3229GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
3230 const char *what,
3231 struct GNUNET_FS_MetaData **result);
3232
2780 3233
2781#if 0 /* keep Emacsens' auto-indent happy */ 3234#if 0 /* keep Emacsens' auto-indent happy */
2782{ 3235{
@@ -2788,3 +3241,5 @@ GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2788#endif 3241#endif
2789 3242
2790/** @} */ /* end of group */ 3243/** @} */ /* end of group */
3244
3245/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index 731be4159..390e8c153 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,6 +33,10 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif
39
32#ifndef GNUNET_GETOPT_LIB_H 40#ifndef GNUNET_GETOPT_LIB_H
33#define GNUNET_GETOPT_LIB_H 41#define GNUNET_GETOPT_LIB_H
34 42
@@ -39,6 +47,7 @@ extern "C" {
39#endif 47#endif
40#endif 48#endif
41 49
50
42#include "gnunet_configuration_lib.h" 51#include "gnunet_configuration_lib.h"
43 52
44/** 53/**
@@ -378,12 +387,29 @@ GNUNET_GETOPT_option_absolute_time (char shortName,
378 387
379 388
380/** 389/**
381 * Increment @a val each time the option flag is given by one. 390 * Allow user to specify a `struct GNUNET_TIME_Timestamp`
391 * (using human-readable "fancy" time).
382 * 392 *
383 * @param shortName short name of the option 393 * @param shortName short name of the option
384 * @param name long name of the option 394 * @param name long name of the option
385 * @param argumentHelp help text for the option argument 395 * @param argumentHelp help text for the option argument
386 * @param description long help text for the option 396 * @param description long help text for the option
397 * @param[out] val set to the time specified at the command line
398 */
399struct GNUNET_GETOPT_CommandLineOption
400GNUNET_GETOPT_option_timestamp (char shortName,
401 const char *name,
402 const char *argumentHelp,
403 const char *description,
404 struct GNUNET_TIME_Timestamp *val);
405
406
407/**
408 * Increment @a val each time the option flag is given by one.
409 *
410 * @param shortName short name of the option
411 * @param name long name of the option
412 * @param description long help text for the option
387 * @param[out] val set to 1 if the option is present 413 * @param[out] val set to 1 if the option is present
388 */ 414 */
389struct GNUNET_GETOPT_CommandLineOption 415struct GNUNET_GETOPT_CommandLineOption
@@ -489,4 +515,6 @@ GNUNET_GETOPT_run (const char *binaryOptions,
489 515
490/** @} */ /* end of group getopt */ 516/** @} */ /* end of group getopt */
491 517
518/** @} */ /* end of group addition */
519
492/* end of gnunet_getopt_lib.h */ 520/* end of gnunet_getopt_lib.h */
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 3f6c9b9aa..1f19e58ac 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -34,8 +37,8 @@
34#ifndef GNUNET_GNS_SERVICE_H 37#ifndef GNUNET_GNS_SERVICE_H
35#define GNUNET_GNS_SERVICE_H 38#define GNUNET_GNS_SERVICE_H
36 39
40
37#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
38#include "gnunet_dnsparser_lib.h"
39#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
40#include "gnunet_namestore_service.h" 43#include "gnunet_namestore_service.h"
41 44
@@ -48,12 +51,6 @@ extern "C" {
48 51
49 52
50/** 53/**
51 * String we use to indicate an empty label (top-level
52 * entry in the zone). DNS uses "@", so do we.
53 */
54#define GNUNET_GNS_EMPTY_LABEL_AT "@"
55
56/**
57 * Connection to the GNS service. 54 * Connection to the GNS service.
58 */ 55 */
59struct GNUNET_GNS_Handle; 56struct GNUNET_GNS_Handle;
@@ -140,7 +137,7 @@ enum GNUNET_GNS_LocalOptions
140struct GNUNET_GNS_LookupRequest * 137struct GNUNET_GNS_LookupRequest *
141GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 138GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
142 const char *name, 139 const char *name,
143 const struct GNUNET_IDENTITY_PublicKey *zone, 140 const struct GNUNET_CRYPTO_PublicKey *zone,
144 uint32_t type, 141 uint32_t type,
145 enum GNUNET_GNS_LocalOptions options, 142 enum GNUNET_GNS_LocalOptions options,
146 GNUNET_GNS_LookupResultProcessor proc, 143 GNUNET_GNS_LookupResultProcessor proc,
@@ -164,7 +161,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
164struct GNUNET_GNS_LookupRequest * 161struct GNUNET_GNS_LookupRequest *
165GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, 162GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
166 const char *name, 163 const char *name,
167 const struct GNUNET_IDENTITY_PublicKey *zone, 164 const struct GNUNET_CRYPTO_PublicKey *zone,
168 uint32_t type, 165 uint32_t type,
169 enum GNUNET_GNS_LocalOptions options, 166 enum GNUNET_GNS_LocalOptions options,
170 uint16_t recursion_depth_limit, 167 uint16_t recursion_depth_limit,
@@ -241,3 +238,5 @@ GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
241#endif 238#endif
242 239
243/** @} */ /* end of group */ 240/** @} */ /* end of group */
241
242/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_json_lib.h b/src/include/gnunet_gnsrecord_json_lib.h
index 966461705..5bc48034b 100644
--- a/src/include/gnunet_gnsrecord_json_lib.h
+++ b/src/include/gnunet_gnsrecord_json_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,7 @@
34#ifndef GNUNET_GNSRECORD_JSON_LIB_H 37#ifndef GNUNET_GNSRECORD_JSON_LIB_H
35#define GNUNET_GNSRECORD_JSON_LIB_H 38#define GNUNET_GNSRECORD_JSON_LIB_H
36 39
40
37#include "gnunet_gnsrecord_lib.h" 41#include "gnunet_gnsrecord_lib.h"
38#include "gnunet_json_lib.h" 42#include "gnunet_json_lib.h"
39 43
@@ -69,5 +73,15 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
69 const struct GNUNET_GNSRECORD_Data *rd, 73 const struct GNUNET_GNSRECORD_Data *rd,
70 unsigned int rd_count); 74 unsigned int rd_count);
71 75
76#if 0 /* keep Emacsens' auto-indent happy */
77{
78#endif
79#ifdef __cplusplus
80}
81#endif
72 82
73#endif 83#endif
84
85/** @} */ /* end of group */
86
87/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index f00a5d0f8..b4e45727b 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,8 @@
34#ifndef GNUNET_GNSRECORD_LIB_H 37#ifndef GNUNET_GNSRECORD_LIB_H
35#define GNUNET_GNSRECORD_LIB_H 38#define GNUNET_GNSRECORD_LIB_H
36 39
40
41#include "gnunet_common.h"
37#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
38 43
39#ifdef __cplusplus 44#ifdef __cplusplus
@@ -44,6 +49,12 @@ extern "C" {
44#endif 49#endif
45 50
46/** 51/**
52 * String we use to indicate an empty label (top-level
53 * entry in the zone). DNS uses "@", so do we.
54 */
55#define GNUNET_GNS_EMPTY_LABEL_AT "@"
56
57/**
47 * Maximum size of a value that can be stored in a GNS block. 58 * Maximum size of a value that can be stored in a GNS block.
48 */ 59 */
49#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024) 60#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024)
@@ -60,50 +71,102 @@ extern "C" {
60#include "gnu_name_system_record_types.h" 71#include "gnu_name_system_record_types.h"
61 72
62/** 73/**
74 * When comparing flags for record equality for removal,
75 * which flags should must match (in addition to the type,
76 * name, expiration value and data of the record)? All flags
77 * that are not listed here will be ignored for this purpose.
78 * (for example, we don't expect that users will remember to
79 * pass the '--private' option when removing a record from
80 * the namestore, hence we don't require this particular option
81 * to match upon removal). See also
82 * #GNUNET_GNSRECORD_records_cmp.
83 */
84#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
85
86
87/**
63 * Flags that can be set for a record. 88 * Flags that can be set for a record.
89 * The numbers in the registry correspond to the bit index as specified in
90 * LSD0001 Chapter "Resource Records".
91 * Each enum member represents the 16-bit integer value of the flags field if
92 * only that particular flag was set.
93 * The value can be used to efficiently compare the bitmask setting for the
94 * record flag in C.
95 * WARNING: The values are in host byte order! In order to correctly check
96 * against the flags field a record, the respective fields must
97 * also be converted to HBO (or the enum value to NBO).
64 */ 98 */
65enum GNUNET_GNSRECORD_Flags 99enum GNUNET_GNSRECORD_Flags
66{ 100{
67 /** 101 /**
68 * No special options. 102 * Entry for no flags / cleared flags.
69 */ 103 */
70 GNUNET_GNSRECORD_RF_NONE = 0, 104 GNUNET_GNSRECORD_RF_NONE = 0,
71 105
106
107 /**
108 * This record is critical. If it cannot be processed (for example because the record type is unknown) resolution MUST fail
109 */
110 GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15),
111
112
72 /** 113 /**
73 * This is a private record of this peer and it should 114 * This record should not be used unless all (other) records in the set with an absolute expiration time have expired.
74 * thus not be handed out to other peers.
75 */ 115 */
76 GNUNET_GNSRECORD_RF_PRIVATE = 2, 116 GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14),
117
77 118
78 /** 119 /**
79 * This is a supplemental record. 120 * This is a supplemental record.
80 */ 121 */
81 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4, 122 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
82 123
83 /** 124 /**
84 * This expiration time of the record is a relative 125 * Maintenance records. E.g. TOMBSTONEs
85 * time (not an absolute time).
86 */ 126 */
87 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8, 127 GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2),
88 128
89 /** 129 /**
90 * This record should not be used unless all (other) records with an absolute 130 * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation.
91 * expiration time have expired.
92 */ 131 */
93 GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 132 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1),
133
134
135 /**
136 * This is a private record of this peer and it should thus not be published.
137 */
138 GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0),
139
140};
141
94 142
95/** 143/**
96 * When comparing flags for record equality for removal, 144 * Filter for GNUNET_GNSRECORD_normalize_record_set().
97 * which flags should must match (in addition to the type,
98 * name, expiration value and data of the record)? All flags
99 * that are not listed here will be ignored for this purpose.
100 * (for example, we don't expect that users will remember to
101 * pass the '--private' option when removing a record from
102 * the namestore, hence we don't require this particular option
103 * to match upon removal). See also
104 * #GNUNET_GNSRECORD_records_cmp.
105 */ 145 */
106#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) 146enum GNUNET_GNSRECORD_Filter
147{
148 /**
149 * No filter flags set.
150 * Private and public records are returned,
151 * maintenance records (TOMBSTONE etc) are not.
152 */
153 GNUNET_GNSRECORD_FILTER_NONE = 0,
154
155 /**
156 * Include maintenance records (TOMBSTONE etc).
157 */
158 GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE = 1,
159
160 /**
161 * Filter private records
162 */
163 GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE = 2,
164
165 /**
166 * Filter public records.
167 * FIXME: Not implemented
168 */
169 // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
107}; 170};
108 171
109 172
@@ -184,12 +247,6 @@ struct GNUNET_GNSRECORD_EcdsaBlock
184 struct GNUNET_CRYPTO_EcdsaSignature signature; 247 struct GNUNET_CRYPTO_EcdsaSignature signature;
185 248
186 /** 249 /**
187 * Number of bytes signed; also specifies the number of bytes
188 * of encrypted data that follow.
189 */
190 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
191
192 /**
193 * Expiration time of the block. 250 * Expiration time of the block.
194 */ 251 */
195 struct GNUNET_TIME_AbsoluteNBO expiration_time; 252 struct GNUNET_TIME_AbsoluteNBO expiration_time;
@@ -214,22 +271,25 @@ struct GNUNET_GNSRECORD_EddsaBlock
214 struct GNUNET_CRYPTO_EddsaSignature signature; 271 struct GNUNET_CRYPTO_EddsaSignature signature;
215 272
216 /** 273 /**
217 * Number of bytes signed; also specifies the number of bytes
218 * of encrypted data that follow.
219 */
220 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
221
222 /**
223 * Expiration time of the block. 274 * Expiration time of the block.
224 */ 275 */
225 struct GNUNET_TIME_AbsoluteNBO expiration_time; 276 struct GNUNET_TIME_AbsoluteNBO expiration_time;
226 277
278
227 /* followed by encrypted data */ 279 /* followed by encrypted data */
228}; 280};
229 281
230 282
231struct GNUNET_GNSRECORD_Block 283struct GNUNET_GNSRECORD_Block
232{ 284{
285 /**
286 * Size of the block.
287 */
288 uint32_t size;
289
290 /**
291 * The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
292 */
233 uint32_t type; 293 uint32_t type;
234 294
235 union 295 union
@@ -271,6 +331,31 @@ struct GNUNET_GNSRECORD_BoxRecord
271 /* followed by the 'original' record */ 331 /* followed by the 'original' record */
272}; 332};
273 333
334
335/**
336 * Record type used to box up SMIMEA records. For example, a
337 * SMIMEA record for "c93f1e400f26708f98cb19d936620da35eec8f72e57
338 * f9eec01c1afd6._smimecert.foo.gnu" will be stored under
339 * "foo.gnu" as a SBOX record with the local-path of the associated
340 * e-mails hash turnicated to 28 octets encoded as hex and protocol _smimecert
341 * and record_type "SMIMEA". When a BOX record is received, GNS
342 * unboxes it if the name contained "hash._PROTO", otherwise GNS
343 * leaves it untouched. This is done to ensure that SMIMEA
344 * records do not require a separate network request, thus making SMIMEA
345 * records inseparable from the "main" A/AAAA/VPN/etc. records.
346 */
347struct GNUNET_GNSRECORD_SBoxRecord
348{
349 /**
350 * GNS record type of the boxed record. In NBO.
351 */
352 uint32_t record_type GNUNET_PACKED;
353
354 /* followed by the zero terminated hostname prefix */
355 /* followed by the 'original' record */
356};
357
358
274/** 359/**
275 * Record type used internally to keep track of reverse mappings into a 360 * Record type used internally to keep track of reverse mappings into a
276 * namespace. 361 * namespace.
@@ -283,7 +368,7 @@ struct GNUNET_GNSRECORD_ReverseRecord
283 /** 368 /**
284 * The public key of the namespace the is delegating to our namespace 369 * The public key of the namespace the is delegating to our namespace
285 */ 370 */
286 struct GNUNET_IDENTITY_PublicKey pkey; 371 struct GNUNET_CRYPTO_PublicKey pkey;
287 372
288 /** 373 /**
289 * The expiration time of the delegation 374 * The expiration time of the delegation
@@ -293,8 +378,6 @@ struct GNUNET_GNSRECORD_ReverseRecord
293 /* followed by the name the delegator uses to refer to our namespace */ 378 /* followed by the name the delegator uses to refer to our namespace */
294}; 379};
295 380
296GNUNET_NETWORK_STRUCT_END
297
298 381
299/** 382/**
300 * Process a records that were decrypted from a block. 383 * Process a records that were decrypted from a block.
@@ -387,6 +470,9 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
387 const struct GNUNET_GNSRECORD_Data *rd, 470 const struct GNUNET_GNSRECORD_Data *rd,
388 size_t dest_size, char *dest); 471 size_t dest_size, char *dest);
389 472
473unsigned int
474GNUNET_GNSRECORD_records_deserialize_get_size (size_t len,
475 const char *src);
390 476
391/** 477/**
392 * Deserialize the given records to the given destination. 478 * Deserialize the given records to the given destination.
@@ -418,12 +504,13 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd);
418 504
419 505
420/** 506/**
421 * Convert a UTF-8 string to UTF-8 lowercase 507 * Normalize a UTF-8 string to a GNS name
508 *
422 * @param src source string 509 * @param src source string
423 * @return converted result 510 * @return converted result
424 */ 511 */
425char * 512char *
426GNUNET_GNSRECORD_string_to_lowercase (const char *src); 513GNUNET_GNSRECORD_string_normalize (const char *src);
427 514
428 515
429/** 516/**
@@ -436,7 +523,7 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src);
436 * #GNUNET_GNSRECORD_z2s. 523 * #GNUNET_GNSRECORD_z2s.
437 */ 524 */
438const char * 525const char *
439GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); 526GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z);
440 527
441 528
442/** 529/**
@@ -450,7 +537,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z);
450 * key in an encoding suitable for DNS labels. 537 * key in an encoding suitable for DNS labels.
451 */ 538 */
452const char * 539const char *
453GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); 540GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey);
454 541
455 542
456/** 543/**
@@ -464,7 +551,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey);
464 */ 551 */
465int 552int
466GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 553GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
467 struct GNUNET_IDENTITY_PublicKey *pkey); 554 struct GNUNET_CRYPTO_PublicKey *pkey);
468 555
469 556
470/** 557/**
@@ -476,12 +563,13 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
476 */ 563 */
477void 564void
478GNUNET_GNSRECORD_query_from_private_key ( 565GNUNET_GNSRECORD_query_from_private_key (
479 const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, 566 const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label,
480 struct GNUNET_HashCode *query); 567 struct GNUNET_HashCode *query);
481 568
482 569
483/** 570/**
484 * Calculate the DHT query for a given @a label in a given @a zone. 571 * Calculate the DHT query for a given @a label in a given @a zone.
572 * FIXME: We may want to plugin-ize this at some point.
485 * 573 *
486 * @param pub public key of the zone 574 * @param pub public key of the zone
487 * @param label label of the record 575 * @param label label of the record
@@ -489,11 +577,39 @@ GNUNET_GNSRECORD_query_from_private_key (
489 */ 577 */
490void 578void
491GNUNET_GNSRECORD_query_from_public_key ( 579GNUNET_GNSRECORD_query_from_public_key (
492 const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, 580 const struct GNUNET_CRYPTO_PublicKey *pub, const char *label,
493 struct GNUNET_HashCode *query); 581 struct GNUNET_HashCode *query);
494 582
495 583
496/** 584/**
585 * Get size of buffer for block creation.
586 *
587 * @param key the zone key
588 * @param rd record data
589 * @param rd_count number of records
590 * @return -1 on error (otherwise the length of the block)
591 */
592ssize_t
593GNUNET_GNSRECORD_block_calculate_size (const struct
594 GNUNET_CRYPTO_PrivateKey *key,
595 const struct GNUNET_GNSRECORD_Data *rd,
596 unsigned int rd_count);
597
598/**
599 * Sign a block create with #GNUNET_GNSRECORD_block_create_unsigned
600 *
601 * @param key the private key
602 * @param label the label of the block
603 * @param block the unsigned block
604 * @return GNUNET_OK on success
605 */
606enum GNUNET_GenericReturnValue
607GNUNET_GNSRECORD_block_sign (const struct
608 GNUNET_CRYPTO_PrivateKey *key,
609 const char *label,
610 struct GNUNET_GNSRECORD_Block *block);
611
612/**
497 * Sign name and records 613 * Sign name and records
498 * 614 *
499 * @param key the private key 615 * @param key the private key
@@ -501,13 +617,41 @@ GNUNET_GNSRECORD_query_from_public_key (
501 * @param label the name for the records 617 * @param label the name for the records
502 * @param rd record data 618 * @param rd record data
503 * @param rd_count number of records in @a rd 619 * @param rd_count number of records in @a rd
620 * @param result the block buffer. Will be allocated.
621 * @return GNUNET_OK on success
504 */ 622 */
505struct GNUNET_GNSRECORD_Block * 623enum GNUNET_GenericReturnValue
506GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, 624GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key,
507 struct GNUNET_TIME_Absolute expire, 625 struct GNUNET_TIME_Absolute expire,
508 const char *label, 626 const char *label,
509 const struct GNUNET_GNSRECORD_Data *rd, 627 const struct GNUNET_GNSRECORD_Data *rd,
510 unsigned int rd_count); 628 unsigned int rd_count,
629 struct GNUNET_GNSRECORD_Block **block);
630
631
632/**
633 * Create name and records but do not sign!
634 * Sign later with #GNUNET_GNSRECORD_block_sign().
635 * Cache derived public key (also keeps the
636 * private key in static memory, so do not use this function if
637 * keeping the private key in the process'es RAM is a major issue).
638 *
639 * @param key the private key
640 * @param expire block expiration
641 * @param label the name for the records
642 * @param rd record data
643 * @param rd_count number of records in @a rd
644 * @param result the block buffer. Will be allocated.
645 * @return GNUNET_OK on success.
646 */
647enum GNUNET_GenericReturnValue
648GNUNET_GNSRECORD_block_create_unsigned (const struct
649 GNUNET_CRYPTO_PrivateKey *key,
650 struct GNUNET_TIME_Absolute expire,
651 const char *label,
652 const struct GNUNET_GNSRECORD_Data *rd,
653 unsigned int rd_count,
654 struct GNUNET_GNSRECORD_Block **result);
511 655
512 656
513/** 657/**
@@ -520,13 +664,16 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key,
520 * @param label the name for the records 664 * @param label the name for the records
521 * @param rd record data 665 * @param rd record data
522 * @param rd_count number of records in @a rd 666 * @param rd_count number of records in @a rd
667 * @param result the block buffer. Will be allocated.
668 * @return GNUNET_OK on success.
523 */ 669 */
524struct GNUNET_GNSRECORD_Block * 670enum GNUNET_GenericReturnValue
525GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, 671GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key,
526 struct GNUNET_TIME_Absolute expire, 672 struct GNUNET_TIME_Absolute expire,
527 const char *label, 673 const char *label,
528 const struct GNUNET_GNSRECORD_Data *rd, 674 const struct GNUNET_GNSRECORD_Data *rd,
529 unsigned int rd_count); 675 unsigned int rd_count,
676 struct GNUNET_GNSRECORD_Block **result);
530 677
531 678
532/** 679/**
@@ -536,7 +683,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key,
536 * @param block block to verify 683 * @param block block to verify
537 * @return #GNUNET_OK if the signature is valid 684 * @return #GNUNET_OK if the signature is valid
538 */ 685 */
539int 686enum GNUNET_GenericReturnValue
540GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); 687GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
541 688
542 689
@@ -551,10 +698,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
551 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was 698 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was
552 * not well-formed 699 * not well-formed
553 */ 700 */
554int 701enum GNUNET_GenericReturnValue
555GNUNET_GNSRECORD_block_decrypt ( 702GNUNET_GNSRECORD_block_decrypt (
556 const struct GNUNET_GNSRECORD_Block *block, 703 const struct GNUNET_GNSRECORD_Block *block,
557 const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, 704 const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label,
558 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); 705 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls);
559 706
560 707
@@ -565,7 +712,7 @@ GNUNET_GNSRECORD_block_decrypt (
565 * @param b another record 712 * @param b another record
566 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. 713 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not.
567 */ 714 */
568int 715enum GNUNET_GenericReturnValue
569GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, 716GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
570 const struct GNUNET_GNSRECORD_Data *b); 717 const struct GNUNET_GNSRECORD_Data *b);
571 718
@@ -577,11 +724,14 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
577 * 724 *
578 * @param rd_count number of records given in @a rd 725 * @param rd_count number of records given in @a rd
579 * @param rd array of records 726 * @param rd array of records
727 * @param min minimum expiration time
580 * @return absolute expiration time 728 * @return absolute expiration time
581 */ 729 */
582struct GNUNET_TIME_Absolute 730struct GNUNET_TIME_Absolute
583GNUNET_GNSRECORD_record_get_expiration_time ( 731GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
584 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); 732 const struct
733 GNUNET_GNSRECORD_Data *rd,
734 struct GNUNET_TIME_Absolute min);
585 735
586 736
587/** 737/**
@@ -631,7 +781,7 @@ enum GNUNET_GenericReturnValue
631GNUNET_GNSRECORD_identity_from_data (const char *data, 781GNUNET_GNSRECORD_identity_from_data (const char *data,
632 size_t data_size, 782 size_t data_size,
633 uint32_t type, 783 uint32_t type,
634 struct GNUNET_IDENTITY_PublicKey *key); 784 struct GNUNET_CRYPTO_PublicKey *key);
635 785
636 786
637/** 787/**
@@ -645,7 +795,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data,
645 */ 795 */
646enum GNUNET_GenericReturnValue 796enum GNUNET_GenericReturnValue
647GNUNET_GNSRECORD_data_from_identity (const struct 797GNUNET_GNSRECORD_data_from_identity (const struct
648 GNUNET_IDENTITY_PublicKey *key, 798 GNUNET_CRYPTO_PublicKey *key,
649 char **data, 799 char **data,
650 size_t *data_size, 800 size_t *data_size,
651 uint32_t *type); 801 uint32_t *type);
@@ -661,6 +811,181 @@ GNUNET_GNSRECORD_data_from_identity (const struct
661enum GNUNET_GenericReturnValue 811enum GNUNET_GenericReturnValue
662GNUNET_GNSRECORD_is_zonekey_type (uint32_t type); 812GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
663 813
814/**
815 * Check if this type is a critical record.
816 *
817 * @param type the type to check
818 * @return GNUNET_YES if it is critical.
819 */
820enum GNUNET_GenericReturnValue
821GNUNET_GNSRECORD_is_critical (uint32_t type);
822
823/**
824 * Normalize namestore records: Check for consistency and
825 * expirations. Purge expired records. Returns a "clean" record set.
826 * Also returns the minimum expiration time this block should be
827 * published under.
828 * Also checks rules with respect to labels (e.g. no delegations under
829 * the empty label)
830 *
831 * @param label the label under which this set (supposed to be) stored.
832 * @param rd input records
833 * @param rd_count size of the @a rd and @a rd_public arrays
834 * @param rd_public where to write the converted records
835 * @param rd_count_public number of records written to @a rd_public
836 * @param min_expiry the minimum expiration of this set
837 * @param filter the record set filter, see GNUNET_GNSRECORD_Filter.
838 * @param emsg the error message if something went wrong
839 * @return GNUNET_OK if set could be normalized and is consistent
840 */
841enum GNUNET_GenericReturnValue
842GNUNET_GNSRECORD_normalize_record_set (const char *label,
843 const struct GNUNET_GNSRECORD_Data *rd,
844 unsigned int rd_count,
845 struct GNUNET_GNSRECORD_Data *rd_public,
846 unsigned int *rd_count_public,
847 struct GNUNET_TIME_Absolute *min_expiry,
848 enum GNUNET_GNSRECORD_Filter filter,
849 char **emsg);
850
851/**
852 * Check label for invalid characters.
853 *
854 * @param label the label to check
855 * @param emsg an error message (NULL if label is valid). Will be allocated.
856 * @return GNUNET_OK if label is valid.
857 */
858enum GNUNET_GenericReturnValue
859GNUNET_GNSRECORD_label_check (const char*label, char **emsg);
860
861/**
862 * Maximum length of a revocation
863 */
864#define GNUNET_MAX_POW_SIZE sizeof(struct GNUNET_GNSRECORD_PowP) \
865 + sizeof(struct GNUNET_CRYPTO_PublicKey) \
866 + 1024 // FIXME max sig_len
867
868/**
869 * The proof-of-work narrowing factor.
870 * The number of PoWs that are calculates as part of revocation.
871 */
872#define POW_COUNT 32
873
874
875GNUNET_NETWORK_STRUCT_BEGIN
876
877/**
878 * Struct for a proof of work as part of the revocation.
879 */
880struct GNUNET_GNSRECORD_PowP
881{
882 /**
883 * The timestamp of the revocation
884 */
885 struct GNUNET_TIME_AbsoluteNBO timestamp;
886
887 /**
888 * The TTL of this revocation (purely informational)
889 */
890 struct GNUNET_TIME_RelativeNBO ttl;
891
892 /**
893 * The PoWs
894 */
895 uint64_t pow[POW_COUNT] GNUNET_PACKED;
896
897 /** followed by the public key type, the key and a signature **/
898};
899
900
901/**
902 * The signature object we use for the PoW
903 */
904struct GNUNET_GNSRECORD_SignaturePurposePS
905{
906 /**
907 * The signature purpose
908 */
909 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
910
911 /**
912 * The timestamp of the revocation
913 */
914 struct GNUNET_TIME_AbsoluteNBO timestamp;
915
916 /** Followed by the zone public key type and key **/
917};
918
919GNUNET_NETWORK_STRUCT_END
920
921
922/**
923 * Handle to a running proof-of-work calculation.
924 */
925struct GNUNET_GNSRECORD_PowCalculationHandle;
926
927
928/**
929 * Check if the given proof-of-work is valid.
930 *
931 * @param pow proof of work
932 * @param matching_bits how many bits must match (configuration)
933 * @param epoch_duration length of single epoch in configuration
934 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
935 */
936enum GNUNET_GenericReturnValue
937GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow,
938 unsigned int matching_bits,
939 struct GNUNET_TIME_Relative epoch_duration);
940
941
942/**
943 * Initializes a fresh PoW computation.
944 *
945 * @param key the key to calculate the PoW for.
946 * @param pow the pow object to work with in the calculation.
947 */
948void
949GNUNET_GNSRECORD_pow_init (const struct GNUNET_CRYPTO_PrivateKey *key,
950 struct GNUNET_GNSRECORD_PowP *pow);
951
952
953/**
954 * Starts a proof-of-work calculation given the pow object as well as
955 * target epochs and difficulty.
956 *
957 * @param pow the PoW to based calculations on.
958 * @param epochs the number of epochs for which the PoW must be valid.
959 * @param difficulty the base difficulty of the PoW.
960 * @return a handle for use in PoW rounds
961 */
962struct GNUNET_GNSRECORD_PowCalculationHandle*
963GNUNET_GNSRECORD_pow_start (struct GNUNET_GNSRECORD_PowP *pow,
964 int epochs,
965 unsigned int difficulty);
966
967
968/**
969 * Calculate a single round in the key revocation PoW.
970 *
971 * @param pc handle to the PoW, initially called with NULL.
972 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
973 */
974enum GNUNET_GenericReturnValue
975GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
976
977size_t
978GNUNET_GNSRECORD_proof_get_size (const struct GNUNET_GNSRECORD_PowP *pow);
979
980/**
981 * Stop a PoW calculation
982 *
983 * @param pc the calculation to clean up
984 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
985 * valid
986 */
987void
988GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
664 989
665#if 0 /* keep Emacsens' auto-indent happy */ 990#if 0 /* keep Emacsens' auto-indent happy */
666{ 991{
@@ -672,3 +997,5 @@ GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
672#endif 997#endif
673 998
674/** @} */ /* end of group */ 999/** @} */ /* end of group */
1000
1001/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_plugin.h b/src/include/gnunet_gnsrecord_plugin.h
index aec22c3af..f55934b60 100644
--- a/src/include/gnunet_gnsrecord_plugin.h
+++ b/src/include/gnunet_gnsrecord_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -105,6 +108,18 @@ typedef const char *
105(*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls, 108(*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls,
106 uint32_t type); 109 uint32_t type);
107 110
111/**
112 * Function called to check for critical records.
113 *
114 * @param cls closure
115 * @param type number of a type to check
116 * @return GNUNET_YES if critical, otherwise GNUNET_NO
117 */
118typedef enum GNUNET_GenericReturnValue
119(*GNUNET_GNSRECORD_IsCriticalFunction) (void *cls,
120 uint32_t type);
121
122
108 123
109/** 124/**
110 * Each plugin is required to return a pointer to a struct of this 125 * Each plugin is required to return a pointer to a struct of this
@@ -136,10 +151,17 @@ struct GNUNET_GNSRECORD_PluginFunctions
136 * Number to typename. 151 * Number to typename.
137 */ 152 */
138 GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename; 153 GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename;
154
155 /**
156 * Is critical.
157 */
158 GNUNET_GNSRECORD_IsCriticalFunction is_critical;
139}; 159};
140 160
141/** @} */ /* end of group */ 161/** @} */ /* end of group */
142 162
163/** @} */ /* end of group addition */
164
143#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
144{ 166{
145#endif 167#endif
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h
deleted file mode 100644
index 74eca999d..000000000
--- a/src/include/gnunet_hello_lib.h
+++ /dev/null
@@ -1,539 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 * @file
24 * Helper library for handling HELLOs
25 *
26 * @defgroup hello Hello library
27 * Helper library for handling HELLOs
28 *
29 * @see [Documentation](https://gnunet.org/gnunets-hostlist-subsystem)
30 *
31 * @{
32 */
33
34#ifndef GNUNET_HELLO_LIB_H
35#define GNUNET_HELLO_LIB_H
36
37#ifdef __cplusplus
38extern "C" {
39#if 0 /* keep Emacsens' auto-indent happy */
40}
41#endif
42#endif
43
44#include "gnunet_util_lib.h"
45
46/**
47 * Prefix that every HELLO URI must start with.
48 */
49#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
50
51/**
52 * Prefix that every FRIEND HELLO URI must start with.
53 */
54#define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
55
56/**
57 * Separator used in HELLO URI
58 */
59#define GNUNET_HELLO_URI_SEP '+'
60
61
62/**
63 * Additional local information about an address
64 *
65 * These information are only valid for the local peer and are not serialized
66 * when a #GNUNET_HELLO_Message is created
67 */
68enum GNUNET_HELLO_AddressInfo
69{
70 /**
71 * No additional information
72 */
73 GNUNET_HELLO_ADDRESS_INFO_NONE = 0,
74
75 /**
76 * This is an inbound address and cannot be used to initiate an outbound
77 * connection to another peer
78 */
79 GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1
80};
81
82
83/**
84 * An address for communicating with a peer. We frequently
85 * need this tuple and the components cannot really be
86 * separated. This is NOT the format that would be used
87 * on the wire.
88 */
89struct GNUNET_HELLO_Address
90{
91 /**
92 * For which peer is this an address?
93 */
94 struct GNUNET_PeerIdentity peer;
95
96 /**
97 * Name of the transport plugin enabling the communication using
98 * this address.
99 */
100 const char *transport_name;
101
102 /**
103 * Binary representation of the address (plugin-specific).
104 */
105 const void *address;
106
107 /**
108 * Number of bytes in @e address.
109 */
110 size_t address_length;
111
112 /**
113 * Extended information about address
114 *
115 * This field contains additional #GNUNET_HELLO_AddressInfo flags e.g.
116 * to indicate an address is inbound and cannot be used to initiate an
117 * outbound connection.
118 *
119 * These information are only valid for the local peer and are not serialized
120 * when a #GNUNET_HELLO_Message is created
121 */
122 enum GNUNET_HELLO_AddressInfo local_info;
123};
124
125
126/**
127 * Allocate an address struct.
128 *
129 * @param peer the peer
130 * @param transport_name plugin name
131 * @param address binary address
132 * @param address_length number of bytes in @a address
133 * @param local_info additional local information for the address
134 * @return the address struct
135 */
136struct GNUNET_HELLO_Address *
137GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
138 const char *transport_name,
139 const void *address,
140 size_t address_length,
141 enum GNUNET_HELLO_AddressInfo local_info);
142
143
144/**
145 * Copy an address struct.
146 *
147 * @param address address to copy
148 * @return a copy of the address struct
149 */
150struct GNUNET_HELLO_Address *
151GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
152
153
154/**
155 * Compare two addresses. Does NOT compare the peer identity,
156 * that is assumed already to match!
157 *
158 * @param a1 first address
159 * @param a2 second address
160 * @return 0 if the addresses are equal, -1 if @a a1< @a a2, 1 if @a a1> @a a2.
161 */
162int
163GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
164 const struct GNUNET_HELLO_Address *a2);
165
166
167/**
168 * Get the size of an address struct.
169 *
170 * @param address address
171 * @return the size
172 */
173size_t
174GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
175
176
177/**
178 * Check if an address has a local option set
179 *
180 * @param address the address to check
181 * @param option the respective option to check for
182 * @return #GNUNET_YES or #GNUNET_NO
183 */
184int
185GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address,
186 enum GNUNET_HELLO_AddressInfo option);
187
188
189/**
190 * Free an address.
191 *
192 * @param addr address to free
193 */
194#define GNUNET_HELLO_address_free(addr) GNUNET_free (addr)
195
196
197GNUNET_NETWORK_STRUCT_BEGIN
198
199/**
200 * A HELLO message is used to exchange information about
201 * transports with other peers. This struct is always
202 * followed by the actual network addresses which have
203 * the format:
204 *
205 * 1) transport-name (0-terminated)
206 * 2) address-length (uint16_t, network byte order; possibly
207 * unaligned!)
208 * 3) address expiration (`struct GNUNET_TIME_AbsoluteNBO`); possibly
209 * unaligned!)
210 * 4) address (address-length bytes; possibly unaligned!)
211 */
212struct GNUNET_HELLO_Message
213{
214 /**
215 * Type will be #GNUNET_MESSAGE_TYPE_HELLO.
216 */
217 struct GNUNET_MessageHeader header;
218
219 /**
220 * Use in F2F mode: Do not gossip this HELLO message
221 */
222 uint32_t friend_only GNUNET_PACKED;
223
224 /**
225 * The public key of the peer.
226 */
227 struct GNUNET_CRYPTO_EddsaPublicKey publicKey;
228};
229GNUNET_NETWORK_STRUCT_END
230
231
232/**
233 * Return HELLO type
234 *
235 * @param h HELLO Message to test
236 * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise
237 */
238int
239GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h);
240
241
242/**
243 * Copy the given address information into
244 * the given buffer using the format of HELLOs.
245 *
246 * @param address address to add
247 * @param expiration expiration for the address
248 * @param target where to copy the address
249 * @param max maximum number of bytes to copy to @a target
250 * @return number of bytes copied, 0 if
251 * the target buffer was not big enough.
252 */
253size_t
254GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
255 struct GNUNET_TIME_Absolute expiration,
256 char *target,
257 size_t max);
258
259
260/**
261 * Callback function used to fill a buffer of max bytes with a list of
262 * addresses in the format used by HELLOs. Should use
263 * #GNUNET_HELLO_add_address() as a helper function.
264 *
265 * @param cls closure
266 * @param max maximum number of bytes that can be written to @a buf
267 * @param buf where to write the address information
268 * @return number of bytes written or 0, #GNUNET_SYSERR to signal the
269 * end of the iteration.
270 */
271typedef ssize_t
272(*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
273 size_t max,
274 void *buf);
275
276
277/**
278 * Construct a HELLO message given the public key,
279 * expiration time and an iterator that spews the
280 * transport addresses.
281 *
282 * If friend only is set to #GNUNET_YES we create a FRIEND_HELLO which
283 * will not be gossiped to other peers.
284 *
285 * @param public_key public key to include in the HELLO
286 * @param addrgen callback to invoke to get addresses
287 * @param addrgen_cls closure for @a addrgen
288 * @param friend_only should the returned HELLO be only visible to friends?
289 * @return the hello message
290 */
291struct GNUNET_HELLO_Message *
292GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
293 GNUNET_HELLO_GenerateAddressListCallback addrgen,
294 void *addrgen_cls,
295 int friend_only);
296
297
298/**
299 * Return the size of the given HELLO message.
300 *
301 * @param hello to inspect
302 * @return the size, 0 if HELLO is invalid
303 */
304uint16_t
305GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
306
307
308/**
309 * Construct a HELLO message by merging the
310 * addresses in two existing HELLOs (which
311 * must be for the same peer).
312 *
313 * @param h1 first HELLO message
314 * @param h2 the second HELLO message
315 * @return the combined hello message
316 */
317struct GNUNET_HELLO_Message *
318GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
319 const struct GNUNET_HELLO_Message *h2);
320
321
322/**
323 * Test if two HELLO messages contain the same addresses.
324 * If they only differ in expiration time, the lowest
325 * expiration time larger than 'now' where they differ
326 * is returned.
327 *
328 * @param h1 first HELLO message
329 * @param h2 the second HELLO message
330 * @param now time to use for deciding which addresses have
331 * expired and should not be considered at all
332 * @return absolute time forever if the two HELLOs are
333 * totally identical; smallest timestamp >= now if
334 * they only differ in timestamps;
335 * zero if the some addresses with expirations >= now
336 * do not match at all
337 */
338struct GNUNET_TIME_Absolute
339GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
340 const struct GNUNET_HELLO_Message *h2,
341 struct GNUNET_TIME_Absolute now);
342
343
344/**
345 * Iterator callback to go over all addresses.
346 *
347 * @param cls closure
348 * @param address the address
349 * @param expiration expiration time
350 * @return #GNUNET_OK to keep the address,
351 * #GNUNET_NO to delete it from the HELLO
352 * #GNUNET_SYSERR to stop iterating (but keep current address)
353 */
354typedef int (*GNUNET_HELLO_AddressIterator) (
355 void *cls,
356 const struct GNUNET_HELLO_Address *address,
357 struct GNUNET_TIME_Absolute expiration);
358
359
360/**
361 * When does the last address in the given HELLO expire?
362 *
363 * @param msg HELLO to inspect
364 * @return time the last address expires, 0 if there are no addresses in the HELLO
365 */
366struct GNUNET_TIME_Absolute
367GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
368
369
370/**
371 * Iterate over all of the addresses in the HELLO.
372 *
373 * @param msg HELLO to iterate over; client does not need to
374 * have verified that msg is well-formed (beyond starting
375 * with a GNUNET_MessageHeader of the right type).
376 * @param return_modified if a modified copy should be returned,
377 * otherwise NULL will be returned
378 * @param it iterator to call on each address
379 * @param it_cls closure for @a it
380 * @return the modified HELLO or NULL
381 */
382struct GNUNET_HELLO_Message *
383GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
384 int return_modified,
385 GNUNET_HELLO_AddressIterator it,
386 void *it_cls);
387
388
389/**
390 * Iterate over addresses in @a new_hello that are NOT already present
391 * in @a old_hello. Note that if the address is present in @a old_hello
392 * but the expiration time in @a new_hello is more recent, the
393 * iterator is also called.
394 *
395 * @param new_hello a HELLO message
396 * @param old_hello a HELLO message
397 * @param expiration_limit ignore addresses in old_hello
398 * that expired before the given time stamp
399 * @param it iterator to call on each address
400 * @param it_cls closure for @a it
401 */
402void
403GNUNET_HELLO_iterate_new_addresses (
404 const struct GNUNET_HELLO_Message *new_hello,
405 const struct GNUNET_HELLO_Message *old_hello,
406 struct GNUNET_TIME_Absolute expiration_limit,
407 GNUNET_HELLO_AddressIterator it,
408 void *it_cls);
409
410
411/**
412 * Get the peer identity from a HELLO message.
413 *
414 * @param hello the hello message
415 * @param peer where to store the peer's identity
416 * @return #GNUNET_SYSERR if the HELLO was malformed
417 */
418int
419GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
420 struct GNUNET_PeerIdentity *peer);
421
422
423/**
424 * Get the header from a HELLO message, used so other code
425 * can correctly send HELLO messages.
426 *
427 * @param hello the hello message
428 *
429 * @return header or NULL if the HELLO was malformed
430 */
431struct GNUNET_MessageHeader *
432GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
433
434
435/**
436 * Helper function to load/access transport plugins.
437 * FIXME: pass closure!
438 *
439 * @param name name of the transport plugin to load
440 * @return NULL if a plugin with name @a name is not known/loadable
441 */
442typedef struct GNUNET_TRANSPORT_PluginFunctions *(
443*GNUNET_HELLO_TransportPluginsFind) (const char *name);
444
445
446/**
447 * Compose a hello URI string from a hello message.
448 *
449 * @param hello Hello message
450 * @param plugins_find Function to find transport plugins by name
451 * @return Hello URI string
452 */
453char *
454GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
455 GNUNET_HELLO_TransportPluginsFind plugins_find);
456
457
458/**
459 * Parse a hello URI string to a hello message.
460 *
461 * @param uri URI string to parse
462 * @param pubkey Pointer to struct where public key is parsed
463 * @param hello Pointer to struct where hello message is parsed
464 * @param plugins_find Function to find transport plugins by name
465 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors
466 */
467int
468GNUNET_HELLO_parse_uri (const char *uri,
469 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey,
470 struct GNUNET_HELLO_Message **hello,
471 GNUNET_HELLO_TransportPluginsFind plugins_find);
472
473
474/* NG API */
475#include "gnunet_nt_lib.h"
476
477
478/**
479 * Build address record by signing raw information with private key.
480 *
481 * @param address text address to sign
482 * @param nt network type of @a address
483 * @param mono_time when was @a address valid
484 * @param private_key signing key to use
485 * @param result[out] where to write address record (allocated)
486 * @param result_size[out] set to size of @a result
487 */
488void
489GNUNET_HELLO_sign_address (
490 const char *address,
491 enum GNUNET_NetworkType nt,
492 struct GNUNET_TIME_Absolute mono_time,
493 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
494 void **result,
495 size_t *result_size);
496
497
498/**
499 * Check signature and extract address record.
500 *
501 * @param raw raw signed address
502 * @param raw_size size of @a raw
503 * @param pid public key to use for signature verification
504 * @param nt[out] set to network type
505 * @param mono_time[out] when was the address generated
506 * @return NULL on error, otherwise the address
507 */
508char *
509GNUNET_HELLO_extract_address (const void *raw,
510 size_t raw_size,
511 const struct GNUNET_PeerIdentity *pid,
512 enum GNUNET_NetworkType *nt,
513 struct GNUNET_TIME_Absolute *mono_time);
514
515
516/**
517 * Given an address as a string, extract the prefix that identifies
518 * the communicator offering transmissions to that address.
519 *
520 * @param address a peer's address
521 * @return NULL if the address is mal-formed, otherwise the prefix
522 */
523char *
524GNUNET_HELLO_address_to_prefix (const char *address);
525
526
527#if 0 /* keep Emacsens' auto-indent happy */
528{
529#endif
530#ifdef __cplusplus
531}
532#endif
533
534/* ifndef GNUNET_HELLO_LIB_H */
535#endif
536
537/** @} */ /* end of group */
538
539/* end of gnunet_hello_lib.h */
diff --git a/src/include/gnunet_hello_uri_lib.h b/src/include/gnunet_hello_uri_lib.h
new file mode 100644
index 000000000..aecda0885
--- /dev/null
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -0,0 +1,304 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 * @file
27 * Helper library for handling HELLO URIs
28 *
29 * @defgroup hello_uri Hello_Uri library
30 * Helper library for handling HELLO URIs
31 *
32 * @{
33 */
34
35#ifndef GNUNET_HELLO_URI_LIB_H
36#define GNUNET_HELLO_URI_LIB_H
37
38#ifdef __cplusplus
39extern "C" {
40#if 0 /* keep Emacsens' auto-indent happy */
41}
42#endif
43#endif
44
45
46#include "gnunet_util_lib.h"
47
48
49/**
50 * Context for building (or parsing) HELLO URIs.
51 */
52struct GNUNET_HELLO_Builder;
53
54
55/**
56 * For how long are HELLO signatures valid?
57 */
58#define GNUNET_HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \
59 GNUNET_TIME_UNIT_DAYS, 2)
60
61
62/**
63 * Allocate builder.
64 *
65 * @param pid peer the builder is for
66 * @return new builder
67 */
68struct GNUNET_HELLO_Builder *
69GNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid);
70
71
72/**
73 * Get the PeerIdentity for this builder.
74 */
75const struct GNUNET_PeerIdentity *
76GNUNET_HELLO_builder_get_id (const struct GNUNET_HELLO_Builder *builder);
77
78
79/**
80 * Release resources of a @a builder.
81 *
82 * @param[in] builder to free
83 */
84void
85GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder);
86
87
88/**
89 * Parse @a msg into builder.
90 *
91 * @param msg message to parse
92 * @return builder, NULL on failure
93 */
94struct GNUNET_HELLO_Builder *
95GNUNET_HELLO_builder_from_msg (const struct GNUNET_MessageHeader *msg);
96
97
98/**
99 * Parse @a block into builder.
100 *
101 * @param block DHT block to parse
102 * @param block_size number of bytes in @a block
103 * @return builder, NULL on failure
104 */
105struct GNUNET_HELLO_Builder *
106GNUNET_HELLO_builder_from_block (const void *block,
107 size_t block_size);
108
109
110/**
111 * Parse GNUnet HELLO @a url into builder.
112 *
113 * @param url URL to parse
114 * @return builder, NULL on failure
115 */
116struct GNUNET_HELLO_Builder *
117GNUNET_HELLO_builder_from_url (const char *url);
118
119
120/**
121 * Get the expiration time for this HELLO.
122 *
123 * @param msg The hello msg.
124 * @return The expiration time.
125 */
126struct GNUNET_TIME_Absolute
127GNUNET_HELLO_builder_get_expiration_time (const struct
128 GNUNET_MessageHeader *msg);
129
130
131/**
132 * Generate envelope with GNUnet HELLO message (including
133 * peer ID) from a @a builder
134 *
135 * @param builder builder to serialize
136 * @param priv private key to use to sign the result
137 * @return HELLO message matching @a builder
138 */
139struct GNUNET_MQ_Envelope *
140GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
141 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
142 struct GNUNET_TIME_Relative expiration_time);
143
144
145/**
146 * Generate DHT HELLO message (without peer ID) from a @a builder
147 *
148 * @param builder builder to serialize
149 * @param priv private key to use to sign the result
150 * @return HELLO message matching @a builder
151 */
152struct GNUNET_MessageHeader *
153GNUNET_HELLO_builder_to_dht_hello_msg (
154 const struct GNUNET_HELLO_Builder *builder,
155 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
156 struct GNUNET_TIME_Relative expiration_time);
157
158
159/**
160 * Generate GNUnet HELLO URI from a @a builder
161 *
162 * @param builder builder to serialize
163 * @param priv private key to use to sign the result
164 * @return hello URI
165 */
166char *
167GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder,
168 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
169
170/**
171 * Generate DHT block from a @a builder
172 *
173 * @param builder the builder to serialize
174 * @param priv private key to use to sign the result
175 * @param[out] block where to write the block, NULL to only calculate @a block_size
176 * @param[in,out] block_size input is number of bytes available in @a block,
177 * output is number of bytes needed in @a block
178 * @return #GNUNET_OK on success, #GNUNET_NO if @a block_size was too small
179 * or if @a block was NULL
180 */
181enum GNUNET_GenericReturnValue
182GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder,
183 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
184 void *block,
185 size_t *block_size,
186 struct GNUNET_TIME_Relative expiration_time);
187
188
189/**
190 * Add individual @a address to the @a builder
191 *
192 * @param[in,out] builder to update
193 * @param address address URI to add
194 * @return #GNUNET_OK on success, #GNUNET_NO if @a address was already
195 * in @a builder
196 */
197enum GNUNET_GenericReturnValue
198GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder,
199 const char *address);
200
201
202/**
203 * Remove individual @a address from the @a builder
204 *
205 * @param[in,out] builder to update
206 * @param address address URI to remove
207 * @return #GNUNET_OK on success, #GNUNET_NO if @a address was not
208 * in @a builder
209 */
210enum GNUNET_GenericReturnValue
211GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder,
212 const char *address);
213
214
215/**
216 * Callback function used to extract URIs from a builder.
217 *
218 * @param cls closure
219 * @param uri one of the URIs
220 */
221typedef void
222(*GNUNET_HELLO_UriCallback) (void *cls,
223 const struct GNUNET_PeerIdentity* pid,
224 const char *uri);
225
226
227/**
228 * Iterate over URIs in a builder.
229 *
230 * @param builder builder to iterate over
231 * @param uc callback invoked for each URI, can be NULL
232 * @param uc_cls closure for @a addrgen
233 * @return pid of the peer the @a builder is for, can be NULL
234 */
235const struct GNUNET_PeerIdentity *
236GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
237 GNUNET_HELLO_UriCallback uc,
238 void *uc_cls);
239
240
241/**
242 * Convert a DHT @a hello message to a HELLO @a block.
243 *
244 * @param hello the HELLO message
245 * @param pid peer that created the @a hello
246 * @param[out] block set to the HELLO block
247 * @param[out] block_size set to number of bytes in @a block
248 * @param[out] block_expiration set to expiration time of @a block
249 * @return #GNUNET_OK on success,
250 * #GNUNET_NO if the @a hello is expired (@a block is set!)
251 * #GNUNET_SYSERR if @a hello is invalid (@a block will be set to NULL)
252 */
253enum GNUNET_GenericReturnValue
254GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello,
255 const struct GNUNET_PeerIdentity *pid,
256 void **block,
257 size_t *block_size,
258 struct GNUNET_TIME_Absolute *block_expiration);
259
260
261/**
262 * Given an address as a string, extract the prefix that identifies
263 * the communicator offering transmissions to that address.
264 *
265 * @param address a peer's address
266 * @return NULL if the address is mal-formed, otherwise the prefix
267 */
268char *
269GNUNET_HELLO_address_to_prefix (const char *address);
270
271/**
272 * Build address record by signing raw information with private key.
273 *
274 * @param address text address to sign
275 * @param nt network type of @a address
276 * @param mono_time when was @a address valid
277 * @param private_key signing key to use
278 * @param[out] result where to write address record (allocated)
279 * @param[out] result_size set to size of @a result
280 */
281void
282GNUNET_HELLO_sign_address (
283 const char *address,
284 enum GNUNET_NetworkType nt,
285 struct GNUNET_TIME_Absolute mono_time,
286 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
287 void **result,
288 size_t *result_size);
289
290#if 0 /* keep Emacsens' auto-indent happy */
291{
292#endif
293#ifdef __cplusplus
294}
295#endif
296
297/* ifndef GNUNET_HELLO_URI_LIB_H */
298#endif
299
300/** @} */ /* end of group */
301
302/** @} */ /* end of group addition */
303
304/* end of gnunet_hello_uri_lib.h */
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h
index b54120204..c329c4a33 100644
--- a/src/include/gnunet_helper_lib.h
+++ b/src/include/gnunet_helper_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Philipp Toelke 26 * @author Philipp Toelke
23 * @author Christian Grothoff 27 * @author Christian Grothoff
24 * 28 *
@@ -34,10 +38,14 @@
34 * @{ 38 * @{
35 */ 39 */
36 40
41#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
42#error "Only <gnunet_util_lib.h> can be included directly."
43#endif
44
37#ifndef GNUNET_HELPER_LIB_H 45#ifndef GNUNET_HELPER_LIB_H
38#define GNUNET_HELPER_LIB_H 46#define GNUNET_HELPER_LIB_H
39 47
40#include "gnunet_scheduler_lib.h" 48
41#include "gnunet_mst_lib.h" 49#include "gnunet_mst_lib.h"
42 50
43 51
@@ -91,8 +99,9 @@ GNUNET_HELPER_start (int with_control_pipe,
91 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper 99 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
92 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 100 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
93 */ 101 */
94int 102enum GNUNET_GenericReturnValue
95GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill); 103GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
104 int soft_kill);
96 105
97 106
98/** 107/**
@@ -103,7 +112,7 @@ GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
103 * @param h the helper handle 112 * @param h the helper handle
104 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 113 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
105 */ 114 */
106int 115enum GNUNET_GenericReturnValue
107GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h); 116GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
108 117
109 118
@@ -136,8 +145,10 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
136 * #GNUNET_NO if helper process died 145 * #GNUNET_NO if helper process died
137 * #GNUNET_SYSERR during GNUNET_HELPER_destroy 146 * #GNUNET_SYSERR during GNUNET_HELPER_destroy
138 */ 147 */
139typedef void (*GNUNET_HELPER_Continuation)(void *cls, 148typedef void
140 int result); 149(*GNUNET_HELPER_Continuation)(
150 void *cls,
151 enum GNUNET_GenericReturnValue result);
141 152
142 153
143/** 154/**
@@ -181,3 +192,5 @@ GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
181/* end of include guard: GNUNET_HELPER_LIB_H */ 192/* end of include guard: GNUNET_HELPER_LIB_H */
182 193
183/** @} */ /* end of group */ 194/** @} */ /* end of group */
195
196/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index c123983e2..270f4d26f 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013--2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup egos Ego management
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -42,6 +45,7 @@
42#ifndef GNUNET_IDENTITY_SERVICE_H 45#ifndef GNUNET_IDENTITY_SERVICE_H
43#define GNUNET_IDENTITY_SERVICE_H 46#define GNUNET_IDENTITY_SERVICE_H
44 47
48#include "gnunet_common.h"
45#ifdef __cplusplus 49#ifdef __cplusplus
46extern "C" { 50extern "C" {
47#if 0 /* keep Emacsens' auto-indent happy */ 51#if 0 /* keep Emacsens' auto-indent happy */
@@ -49,6 +53,7 @@ extern "C" {
49#endif 53#endif
50#endif 54#endif
51 55
56
52#include "gnunet_util_lib.h" 57#include "gnunet_util_lib.h"
53 58
54 59
@@ -57,20 +62,6 @@ extern "C" {
57 */ 62 */
58#define GNUNET_IDENTITY_VERSION 0x00000100 63#define GNUNET_IDENTITY_VERSION 0x00000100
59 64
60enum GNUNET_IDENTITY_KeyType
61{
62 /**
63 * The identity type. The value is the same as the
64 * PKEY record type.
65 */
66 GNUNET_IDENTITY_TYPE_ECDSA = 65536,
67
68 /**
69 * EDDSA identity. The value is the same as the EDKEY
70 * record type.
71 */
72 GNUNET_IDENTITY_TYPE_EDDSA = 65556
73};
74 65
75/** 66/**
76 * Handle to access the identity service. 67 * Handle to access the identity service.
@@ -82,88 +73,6 @@ struct GNUNET_IDENTITY_Handle;
82 */ 73 */
83struct GNUNET_IDENTITY_Ego; 74struct GNUNET_IDENTITY_Ego;
84 75
85
86/**
87 * A private key for an identity as per LSD0001.
88 */
89struct GNUNET_IDENTITY_PrivateKey
90{
91 /**
92 * Type of public key.
93 * Defined by the GNS zone type value.
94 * In NBO.
95 */
96 uint32_t type;
97
98 union
99 {
100 /**
101 * An ECDSA identity key.
102 */
103 struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key;
104
105 /**
106 * AN EdDSA identtiy key
107 */
108 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key;
109 };
110};
111
112
113/**
114 * An identity key as per LSD0001.
115 */
116struct GNUNET_IDENTITY_PublicKey
117{
118 /**
119 * Type of public key.
120 * Defined by the GNS zone type value.
121 * In NBO.
122 */
123 uint32_t type;
124
125 union
126 {
127 /**
128 * An ECDSA identity key.
129 */
130 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key;
131
132 /**
133 * AN EdDSA identtiy key
134 */
135 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key;
136 };
137};
138
139
140/**
141 * An identity signature as per LSD0001.
142 */
143struct GNUNET_IDENTITY_Signature
144{
145 /**
146 * Type of signature.
147 * Defined by the GNS zone type value.
148 * In NBO.
149 */
150 uint32_t type;
151
152 union
153 {
154 /**
155 * An ECDSA signature
156 */
157 struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature;
158
159 /**
160 * AN EdDSA signature
161 */
162 struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
163 };
164};
165
166
167/** 76/**
168 * Handle for an operation with the identity service. 77 * Handle for an operation with the identity service.
169 */ 78 */
@@ -176,7 +85,7 @@ struct GNUNET_IDENTITY_Operation;
176 * @param ego the ego 85 * @param ego the ego
177 * @return associated ECC key, valid as long as the ego is valid 86 * @return associated ECC key, valid as long as the ego is valid
178 */ 87 */
179const struct GNUNET_IDENTITY_PrivateKey * 88const struct GNUNET_CRYPTO_PrivateKey *
180GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); 89GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego);
181 90
182 91
@@ -197,7 +106,17 @@ GNUNET_IDENTITY_ego_get_anonymous (void);
197 */ 106 */
198void 107void
199GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, 108GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
200 struct GNUNET_IDENTITY_PublicKey *pk); 109 struct GNUNET_CRYPTO_PublicKey *pk);
110
111
112/**
113 * Obtain the name associated with an ego.
114 *
115 * @param ego the ego
116 * @return associated name, valid as long as the ego is valid
117 */
118const char*
119GNUNET_IDENTITY_ego_get_name (const struct GNUNET_IDENTITY_Ego *ego);
201 120
202 121
203/** 122/**
@@ -275,11 +194,11 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
275 * been completed. 194 * been completed.
276 * 195 *
277 * @param cls closure 196 * @param cls closure
278 * @param emsg NULL on success, otherwise an error message 197 * @param ec the #GNUNET_ErrorCode
279 */ 198 */
280typedef void 199typedef void
281(*GNUNET_IDENTITY_Continuation) (void *cls, 200(*GNUNET_IDENTITY_Continuation) (void *cls,
282 const char *emsg); 201 enum GNUNET_ErrorCode ec);
283 202
284 203
285/** 204/**
@@ -315,13 +234,13 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
315 * 234 *
316 * @param cls closure 235 * @param cls closure
317 * @param pk private key, NULL on error 236 * @param pk private key, NULL on error
318 * @param emsg error message, NULL on success 237 * @param ec the #GNUNET_ErrorCode
319 */ 238 */
320typedef void 239typedef void
321(*GNUNET_IDENTITY_CreateContinuation) ( 240(*GNUNET_IDENTITY_CreateContinuation) (
322 void *cls, 241 void *cls,
323 const struct GNUNET_IDENTITY_PrivateKey *pk, 242 const struct GNUNET_CRYPTO_PrivateKey *pk,
324 const char *emsg); 243 enum GNUNET_ErrorCode ec);
325 244
326 245
327/** 246/**
@@ -338,8 +257,8 @@ typedef void
338struct GNUNET_IDENTITY_Operation * 257struct GNUNET_IDENTITY_Operation *
339GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, 258GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
340 const char *name, 259 const char *name,
341 const struct GNUNET_IDENTITY_PrivateKey *privkey, 260 const struct GNUNET_CRYPTO_PrivateKey *privkey,
342 enum GNUNET_IDENTITY_KeyType ktype, 261 enum GNUNET_CRYPTO_KeyType ktype,
343 GNUNET_IDENTITY_CreateContinuation cont, 262 GNUNET_IDENTITY_CreateContinuation cont,
344 void *cont_cls); 263 void *cont_cls);
345 264
@@ -390,319 +309,6 @@ void
390GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); 309GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
391 310
392 311
393/**
394 * Get the compacted length of a #GNUNET_IDENTITY_PublicKey.
395 * Compacted means that it returns the minimum number of bytes this
396 * key is long, as opposed to the union structure inside
397 * #GNUNET_IDENTITY_PublicKey.
398 * Useful for compact serializations.
399 *
400 * @param key the key.
401 * @return -1 on error, else the compacted length of the key.
402 */
403ssize_t
404GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
405
406
407/**
408 * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
409 * The buffer has to contain at least the compacted length of
410 * a #GNUNET_IDENTITY_PublicKey in bytes.
411 * If the buffer is too small, the function returns -1 as error.
412 * If the buffer does not contain a valid key, it returns -2 as error.
413 *
414 * @param key the key
415 * @param buffer the buffer
416 * @param len the length of buffer
417 * @return -1 or -2 on error, else the amount of bytes read from the buffer
418 */
419ssize_t
420GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
421 const void*buffer,
422 size_t len);
423
424
425/**
426 * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer.
427 * The buffer requires space for at least the compacted length of
428 * a #GNUNET_IDENTITY_PublicKey in bytes.
429 * If the buffer is too small, the function returns -1 as error.
430 * If the key is not valid, it returns -2 as error.
431 *
432 * @param key the key
433 * @param buffer the buffer
434 * @param len the length of buffer
435 * @return -1 or -2 on error, else the amount of bytes written to the buffer
436 */
437ssize_t
438GNUNET_IDENTITY_write_key_to_buffer (const struct
439 GNUNET_IDENTITY_PublicKey *key,
440 void*buffer,
441 size_t len);
442
443
444/**
445 * Get the compacted length of a #GNUNET_IDENTITY_Signature.
446 * Compacted means that it returns the minimum number of bytes this
447 * signature is long, as opposed to the union structure inside
448 * #GNUNET_IDENTITY_Signature.
449 * Useful for compact serializations.
450 *
451 * @param sig the signature.
452 * @return -1 on error, else the compacted length of the signature.
453 */
454ssize_t
455GNUNET_IDENTITY_signature_get_length (const struct
456 GNUNET_IDENTITY_Signature *sig);
457
458
459/**
460 * Reads a #GNUNET_IDENTITY_Signature from a compact buffer.
461 * The buffer has to contain at least the compacted length of
462 * a #GNUNET_IDENTITY_Signature in bytes.
463 * If the buffer is too small, the function returns -1 as error.
464 * If the buffer does not contain a valid key, it returns -2 as error.
465 *
466 * @param sig the signature
467 * @param buffer the buffer
468 * @param len the length of buffer
469 * @return -1 or -2 on error, else the amount of bytes read from the buffer
470 */
471ssize_t
472GNUNET_IDENTITY_read_signature_from_buffer (struct
473 GNUNET_IDENTITY_Signature *sig,
474 const void*buffer,
475 size_t len);
476
477
478/**
479 * Writes a #GNUNET_IDENTITY_Signature to a compact buffer.
480 * The buffer requires space for at least the compacted length of
481 * a #GNUNET_IDENTITY_Signature in bytes.
482 * If the buffer is too small, the function returns -1 as error.
483 * If the key is not valid, it returns -2 as error.
484 *
485 * @param sig the signature
486 * @param buffer the buffer
487 * @param len the length of buffer
488 * @return -1 or -2 on error, else the amount of bytes written to the buffer
489 */
490ssize_t
491GNUNET_IDENTITY_write_signature_to_buffer (const struct
492 GNUNET_IDENTITY_Signature *sig,
493 void*buffer,
494 size_t len);
495
496
497/**
498 * @brief Sign a given block.
499 *
500 * The @a purpose data is the beginning of the data of which the signature is
501 * to be created. The `size` field in @a purpose must correctly indicate the
502 * number of bytes of the data structure, including its header. If possible,
503 * use #GNUNET_IDENTITY_sign() instead of this function.
504 *
505 * @param priv private key to use for the signing
506 * @param purpose what to sign (size, purpose)
507 * @param[out] sig where to write the signature
508 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
509 */
510int
511GNUNET_IDENTITY_sign_ (const struct
512 GNUNET_IDENTITY_PrivateKey *priv,
513 const struct
514 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
515 struct GNUNET_IDENTITY_Signature *sig);
516
517
518/**
519 * @brief Sign a given block with #GNUNET_IDENTITY_PrivateKey.
520 *
521 * The @a ps data must be a fixed-size struct for which the signature is to be
522 * created. The `size` field in @a ps->purpose must correctly indicate the
523 * number of bytes of the data structure, including its header.
524 *
525 * @param priv private key to use for the signing
526 * @param ps packed struct with what to sign, MUST begin with a purpose
527 * @param[out] sig where to write the signature
528 */
529#define GNUNET_IDENTITY_sign(priv,ps,sig) do { \
530 /* check size is set correctly */ \
531 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
532 /* check 'ps' begins with the purpose */ \
533 GNUNET_static_assert (((void*) (ps)) == \
534 ((void*) &(ps)->purpose)); \
535 GNUNET_assert (GNUNET_OK == \
536 GNUNET_IDENTITY_sign_ (priv, \
537 &(ps)->purpose, \
538 sig)); \
539} while (0)
540
541
542/**
543 * @brief Verify a given signature.
544 *
545 * The @a validate data is the beginning of the data of which the signature
546 * is to be verified. The `size` field in @a validate must correctly indicate
547 * the number of bytes of the data structure, including its header. If @a
548 * purpose does not match the purpose given in @a validate (the latter must be
549 * in big endian), signature verification fails. If possible,
550 * use #GNUNET_IDENTITY_signature_verify() instead of this function (only if @a validate
551 * is not fixed-size, you must use this function directly).
552 *
553 * @param purpose what is the purpose that the signature should have?
554 * @param validate block to validate (size, purpose, data)
555 * @param sig signature that is being validated
556 * @param pub public key of the signer
557 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
558 */
559int
560GNUNET_IDENTITY_signature_verify_ (uint32_t purpose,
561 const struct
562 GNUNET_CRYPTO_EccSignaturePurpose *validate,
563 const struct GNUNET_IDENTITY_Signature *sig,
564 const struct
565 GNUNET_IDENTITY_PublicKey *pub);
566
567
568/**
569 * @brief Verify a given signature with #GNUNET_IDENTITY_PublicKey.
570 *
571 * The @a ps data must be a fixed-size struct for which the signature is to be
572 * created. The `size` field in @a ps->purpose must correctly indicate the
573 * number of bytes of the data structure, including its header.
574 *
575 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
576 * (except in host byte order)
577 * @param ps packed struct with what to sign, MUST begin with a purpose
578 * @param sig where to read the signature from
579 * @param pub public key to use for the verifying
580 */
581#define GNUNET_IDENTITY_signature_verify(purp,ps,sig,pub) ({ \
582 /* check size is set correctly */ \
583 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
584 /* check 'ps' begins with the purpose */ \
585 GNUNET_static_assert (((void*) (ps)) == \
586 ((void*) &(ps)->purpose)); \
587 GNUNET_IDENTITY_signature_verify_ (purp, \
588 &(ps)->purpose, \
589 sig, \
590 pub); \
591 })
592
593
594/**
595 * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a
596 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
597 * using ecdh to derive a symmetric key.
598 *
599 * @param block the block to encrypt
600 * @param size the size of the @a block
601 * @param pub public key to use for ecdh
602 * @param ecc where to write the ecc public key
603 * @param result the output parameter in which to store the encrypted result
604 * can be the same or overlap with @c block
605 * @returns the size of the encrypted block, -1 for errors.
606 * Due to the use of CFB and therefore an effective stream cipher,
607 * this size should be the same as @c len.
608 */
609ssize_t
610GNUNET_IDENTITY_encrypt (const void *block,
611 size_t size,
612 const struct GNUNET_IDENTITY_PublicKey *pub,
613 struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
614 void *result);
615
616
617/**
618 * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given
619 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
620 *
621 * @param block the data to decrypt, encoded as returned by encrypt
622 * @param size the size of the @a block to decrypt
623 * @param priv private key to use for ecdh
624 * @param ecc the ecc public key
625 * @param result address to store the result at
626 * can be the same or overlap with @c block
627 * @return -1 on failure, size of decrypted block on success.
628 * Due to the use of CFB and therefore an effective stream cipher,
629 * this size should be the same as @c size.
630 */
631ssize_t
632GNUNET_IDENTITY_decrypt (const void *block,
633 size_t size,
634 const struct
635 GNUNET_IDENTITY_PrivateKey *priv,
636 const struct
637 GNUNET_CRYPTO_EcdhePublicKey *ecc,
638 void *result);
639
640
641/**
642 * Creates a (Base32) string representation of the public key.
643 * The resulting string encodes a compacted representation of the key.
644 * See also #GNUNET_IDENTITY_key_get_length.
645 *
646 * @param key the key.
647 * @return the string representation of the key, or NULL on error.
648 */
649char *
650GNUNET_IDENTITY_public_key_to_string (const struct
651 GNUNET_IDENTITY_PublicKey *key);
652
653
654/**
655 * Creates a (Base32) string representation of the private key.
656 * The resulting string encodes a compacted representation of the key.
657 * See also #GNUNET_IDENTITY_key_get_length.
658 *
659 * @param key the key.
660 * @return the string representation of the key, or NULL on error.
661 */
662char *
663GNUNET_IDENTITY_private_key_to_string (const struct
664 GNUNET_IDENTITY_PrivateKey *key);
665
666
667/**
668 * Parses a (Base32) string representation of the public key.
669 * See also #GNUNET_IDENTITY_public_key_to_string.
670 *
671 * @param str the encoded key.
672 * @param key where to write the key.
673 * @return GNUNET_SYSERR on error.
674 */
675enum GNUNET_GenericReturnValue
676GNUNET_IDENTITY_public_key_from_string (const char*str,
677 struct GNUNET_IDENTITY_PublicKey *key);
678
679
680/**
681 * Parses a (Base32) string representation of the private key.
682 * See also #GNUNET_IDENTITY_private_key_to_string.
683 *
684 * @param str the encoded key.
685 * @param key where to write the key.
686 * @return GNUNET_SYSERR on error.
687 */
688enum GNUNET_GenericReturnValue
689GNUNET_IDENTITY_private_key_from_string (const char*str,
690 struct GNUNET_IDENTITY_PrivateKey *key);
691
692
693/**
694 * Retrieves the public key representation of a private key.
695 *
696 * @param privkey the private key.
697 * @param key the public key result.
698 * @return GNUNET_SYSERR on error.
699 */
700enum GNUNET_GenericReturnValue
701GNUNET_IDENTITY_key_get_public (const struct
702 GNUNET_IDENTITY_PrivateKey *privkey,
703 struct GNUNET_IDENTITY_PublicKey *key);
704
705
706/* ************* convenience API to lookup an ego ***************** */ 312/* ************* convenience API to lookup an ego ***************** */
707 313
708/** 314/**
@@ -755,7 +361,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
755typedef void 361typedef void
756(*GNUNET_IDENTITY_EgoSuffixCallback) ( 362(*GNUNET_IDENTITY_EgoSuffixCallback) (
757 void *cls, 363 void *cls,
758 const struct GNUNET_IDENTITY_PrivateKey *priv, 364 const struct GNUNET_CRYPTO_PrivateKey *priv,
759 const char *ego_name); 365 const char *ego_name);
760 366
761 367
@@ -778,11 +384,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup;
778 * @return handle to abort the operation 384 * @return handle to abort the operation
779 */ 385 */
780struct GNUNET_IDENTITY_EgoSuffixLookup * 386struct GNUNET_IDENTITY_EgoSuffixLookup *
781GNUNET_IDENTITY_ego_lookup_by_suffix (const struct 387GNUNET_IDENTITY_ego_lookup_by_suffix (
782 GNUNET_CONFIGURATION_Handle *cfg, 388 const struct GNUNET_CONFIGURATION_Handle *cfg,
783 const char *suffix, 389 const char *suffix,
784 GNUNET_IDENTITY_EgoSuffixCallback cb, 390 GNUNET_IDENTITY_EgoSuffixCallback cb,
785 void *cb_cls); 391 void *cb_cls);
786 392
787 393
788/** 394/**
@@ -807,4 +413,6 @@ GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (
807 413
808/** @} */ /* end of group identity */ 414/** @} */ /* end of group identity */
809 415
416/** @} */ /* end of group addition */
417
810/* end of gnunet_identity_service.h */ 418/* end of gnunet_identity_service.h */
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 5ef4592e5..0b6b299d1 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -27,6 +27,7 @@
27#ifndef GNUNET_JSON_LIB_H 27#ifndef GNUNET_JSON_LIB_H
28#define GNUNET_JSON_LIB_H 28#define GNUNET_JSON_LIB_H
29 29
30
30#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
31#include <jansson.h> 32#include <jansson.h>
32#include <microhttpd.h> 33#include <microhttpd.h>
@@ -48,10 +49,10 @@ struct GNUNET_JSON_Specification;
48 * @return #GNUNET_SYSERR on error, 49 * @return #GNUNET_SYSERR on error,
49 * #GNUNET_OK on success 50 * #GNUNET_OK on success
50 */ 51 */
51typedef int 52typedef enum GNUNET_GenericReturnValue
52(*GNUNET_JSON_Parser) (void *cls, 53(*GNUNET_JSON_Parser)(void *cls,
53 json_t *root, 54 json_t *root,
54 struct GNUNET_JSON_Specification *spec); 55 struct GNUNET_JSON_Specification *spec);
55 56
56 57
57/** 58/**
@@ -97,9 +98,10 @@ struct GNUNET_JSON_Specification
97 void *ptr; 98 void *ptr;
98 99
99 /** 100 /**
100 * Number of bytes available in @e ptr. 101 * Pointer to set to true if this argument is
102 * indeed missing. Can be NULL.
101 */ 103 */
102 size_t ptr_size; 104 bool *missing;
103 105
104 /** 106 /**
105 * Where should we store the final size of @e ptr. 107 * Where should we store the final size of @e ptr.
@@ -107,6 +109,11 @@ struct GNUNET_JSON_Specification
107 size_t *size_ptr; 109 size_t *size_ptr;
108 110
109 /** 111 /**
112 * Number of bytes available in @e ptr.
113 */
114 size_t ptr_size;
115
116 /**
110 * Set to true if this component is optional. 117 * Set to true if this component is optional.
111 */ 118 */
112 bool is_optional; 119 bool is_optional;
@@ -123,7 +130,7 @@ struct GNUNET_JSON_Specification
123 * @param root the JSON node to start the navigation at. 130 * @param root the JSON node to start the navigation at.
124 * @param spec parse specification array 131 * @param spec parse specification array
125 * @param[out] error_json_name which JSON field was problematic 132 * @param[out] error_json_name which JSON field was problematic
126 * @param[out] which index into @a spec did we encounter an error 133 * @param[out] error_line which index into @a spec did we encounter an error
127 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 134 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
128 */ 135 */
129enum GNUNET_GenericReturnValue 136enum GNUNET_GenericReturnValue
@@ -135,7 +142,13 @@ GNUNET_JSON_parse (const json_t *root,
135 142
136/** 143/**
137 * Frees all elements allocated during a #GNUNET_JSON_parse() 144 * Frees all elements allocated during a #GNUNET_JSON_parse()
138 * operation. 145 * operation. Convenience function to be called if cleaning
146 * up all heap-allocated data from a #GNUNET_JSON_parse() is
147 * desired. The function does not have to be called if no data
148 * was heap-allocated (e.g. only integers, strings and fixed-sized
149 * data was used), or if the application calls the respective
150 * code to free the heap (not always #GNUNET_free(), depends
151 * on the data type!) on the returned heap-allocated data itself.
139 * 152 *
140 * @param spec specification of the parse operation 153 * @param spec specification of the parse operation
141 */ 154 */
@@ -157,10 +170,12 @@ GNUNET_JSON_spec_end (void);
157 * Set the "optional" flag for a parser specification entry. 170 * Set the "optional" flag for a parser specification entry.
158 * 171 *
159 * @param spec specification to modify 172 * @param spec specification to modify
173 * @param[out] missing set to true if the argument is missing, NULL is allowed.
160 * @return spec copy of @a spec with optional bit set 174 * @return spec copy of @a spec with optional bit set
161 */ 175 */
162struct GNUNET_JSON_Specification 176struct GNUNET_JSON_Specification
163GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec); 177GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec,
178 bool *missing);
164 179
165 180
166/** 181/**
@@ -189,6 +204,29 @@ GNUNET_JSON_spec_fixed (const char *name,
189 204
190 205
191/** 206/**
207 * Variable size object (in network byte order, encoded using base64 encoding).
208 *
209 * @param name name of the JSON field
210 * @param[out] obj pointer where to write the data, must have @a size bytes
211 * @param size number of bytes expected in @a obj
212 */
213struct GNUNET_JSON_Specification
214GNUNET_JSON_spec_fixed64 (const char *name,
215 void *obj,
216 size_t size);
217
218
219/**
220 * Fixed size object (in network byte order, encoded using base64 encoding).
221 *
222 * @param name name of the JSON field
223 * @param obj pointer where to write the data (type of `*obj` will determine size)
224 */
225#define GNUNET_JSON_spec_fixed64_auto(name, obj) \
226 GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))
227
228
229/**
192 * Variable size object (in network byte order, encoded using 230 * Variable size object (in network byte order, encoded using
193 * Crockford Base32hex encoding). 231 * Crockford Base32hex encoding).
194 * 232 *
@@ -214,7 +252,8 @@ GNUNET_JSON_spec_string (const char *name,
214 252
215 253
216/** 254/**
217 * JSON object. 255 * JSON object or array. Reference counter is
256 * incremented.
218 * 257 *
219 * @param name name of the JSON field 258 * @param name name of the JSON field
220 * @param[out] jsonp where to store the JSON found under @a name 259 * @param[out] jsonp where to store the JSON found under @a name
@@ -225,6 +264,28 @@ GNUNET_JSON_spec_json (const char *name,
225 264
226 265
227/** 266/**
267 * JSON object, reference counter not incremented.
268 *
269 * @param name name of the JSON field
270 * @param[out] jsonp where to store the JSON found under @a name
271 */
272struct GNUNET_JSON_Specification
273GNUNET_JSON_spec_object_const (const char *name,
274 const json_t **jsonp);
275
276
277/**
278 * JSON array, reference counter not incremented.
279 *
280 * @param name name of the JSON field
281 * @param[out] jsonp where to store the JSON found under @a name
282 */
283struct GNUNET_JSON_Specification
284GNUNET_JSON_spec_array_const (const char *name,
285 const json_t **jsonp);
286
287
288/**
228 * boolean. 289 * boolean.
229 * 290 *
230 * @param name name of the JSON field 291 * @param name name of the JSON field
@@ -236,6 +297,17 @@ GNUNET_JSON_spec_bool (const char *name,
236 297
237 298
238/** 299/**
300 * double.
301 *
302 * @param name name of the JSON field
303 * @param[out] f where to store the double found under @a name
304 */
305struct GNUNET_JSON_Specification
306GNUNET_JSON_spec_double (const char *name,
307 double *f);
308
309
310/**
239 * 8-bit integer. 311 * 8-bit integer.
240 * 312 *
241 * @param name name of the JSON field 313 * @param name name of the JSON field
@@ -304,25 +376,25 @@ GNUNET_JSON_spec_boolean (const char *name,
304/* ************ GNUnet-specific parser specifications ******************* */ 376/* ************ GNUnet-specific parser specifications ******************* */
305 377
306/** 378/**
307 * Absolute time. 379 * Timestamp.
308 * 380 *
309 * @param name name of the JSON field 381 * @param name name of the JSON field
310 * @param[out] at where to store the absolute time found under @a name 382 * @param[out] t at where to store the absolute time found under @a name
311 */ 383 */
312struct GNUNET_JSON_Specification 384struct GNUNET_JSON_Specification
313GNUNET_JSON_spec_absolute_time (const char *name, 385GNUNET_JSON_spec_timestamp (const char *name,
314 struct GNUNET_TIME_Absolute *at); 386 struct GNUNET_TIME_Timestamp *t);
315 387
316 388
317/** 389/**
318 * Absolute time in network byte order. 390 * Timestamp in network byte order.
319 * 391 *
320 * @param name name of the JSON field 392 * @param name name of the JSON field
321 * @param[out] at where to store the absolute time found under @a name 393 * @param[out] tn where to store the absolute time found under @a name
322 */ 394 */
323struct GNUNET_JSON_Specification 395struct GNUNET_JSON_Specification
324GNUNET_JSON_spec_absolute_time_nbo (const char *name, 396GNUNET_JSON_spec_timestamp_nbo (const char *name,
325 struct GNUNET_TIME_AbsoluteNBO *at); 397 struct GNUNET_TIME_TimestampNBO *tn);
326 398
327 399
328/** 400/**
@@ -370,7 +442,21 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
370 * @return json string that encodes @a data 442 * @return json string that encodes @a data
371 */ 443 */
372json_t * 444json_t *
373GNUNET_JSON_from_data (const void *data, size_t size); 445GNUNET_JSON_from_data (const void *data,
446 size_t size);
447
448
449/**
450 * Convert binary data to a JSON string with base64
451 * encoding.
452 *
453 * @param data binary data
454 * @param size size of @a data in bytes
455 * @return json string that encodes @a data
456 */
457json_t *
458GNUNET_JSON_from_data64 (const void *data,
459 size_t size);
374 460
375 461
376/** 462/**
@@ -385,23 +471,34 @@ GNUNET_JSON_from_data (const void *data, size_t size);
385 471
386 472
387/** 473/**
388 * Convert absolute timestamp to a json string. 474 * Convert binary data to a JSON string with base64
475 * encoding.
476 *
477 * @param ptr binary data, sizeof (*ptr) must yield correct size
478 * @return json string that encodes @a data
479 */
480#define GNUNET_JSON_from_data64_auto(ptr) \
481 GNUNET_JSON_from_data64 (ptr, sizeof(*ptr))
482
483
484/**
485 * Convert timestamp to a json string.
389 * 486 *
390 * @param stamp the time stamp 487 * @param stamp the time stamp
391 * @return a json string with the timestamp in @a stamp 488 * @return a json string with the timestamp in @a stamp
392 */ 489 */
393json_t * 490json_t *
394GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); 491GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp);
395 492
396 493
397/** 494/**
398 * Convert absolute timestamp to a json string. 495 * Convert timestamp to a json string.
399 * 496 *
400 * @param stamp the time stamp 497 * @param stamp the time stamp
401 * @return a json string with the timestamp in @a stamp 498 * @return a json string with the timestamp in @a stamp
402 */ 499 */
403json_t * 500json_t *
404GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); 501GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp);
405 502
406 503
407/** 504/**
@@ -624,6 +721,19 @@ GNUNET_JSON_pack_bool (const char *name,
624 721
625/** 722/**
626 * Generate packer instruction for a JSON field of type 723 * Generate packer instruction for a JSON field of type
724 * double.
725 *
726 * @param name name of the field to add to the object
727 * @param f double value
728 * @return json pack specification
729 */
730struct GNUNET_JSON_PackSpec
731GNUNET_JSON_pack_double (const char *name,
732 double f);
733
734
735/**
736 * Generate packer instruction for a JSON field of type
627 * string. 737 * string.
628 * 738 *
629 * @param name name of the field to add to the object 739 * @param name name of the field to add to the object
@@ -747,30 +857,61 @@ GNUNET_JSON_pack_data_varsize (const char *name,
747 857
748/** 858/**
749 * Generate packer instruction for a JSON field of type 859 * Generate packer instruction for a JSON field of type
750 * absolute time. 860 * variable size binary blob.
861 * Use base64-encoding, instead of the more common
862 * Crockford base32-encoding.
751 * 863 *
752 * @param name name of the field to add to the object 864 * @param name name of the field to add to the object
753 * @param at absolute time to pack, a value of 0 is only 865 * @param blob binary data to pack
866 * @param blob_size number of bytes in @a blob
867 * @return json pack specification
868 */
869struct GNUNET_JSON_PackSpec
870GNUNET_JSON_pack_data64_varsize (const char *name,
871 const void *blob,
872 size_t blob_size);
873
874
875/**
876 * Generate packer instruction for a JSON field where the
877 * size is automatically determined from the argument.
878 * Use base64-encoding, instead of the more common
879 * Crockford base32-encoding.
880 *
881 * @param name name of the field to add to the object
882 * @param blob data to pack, must not be an array
883 * @return json pack specification
884 */
885#define GNUNET_JSON_pack_data64_auto(name,blob) \
886 GNUNET_JSON_pack_data64_varsize (name, blob, sizeof (*blob))
887
888
889/**
890 * Generate packer instruction for a JSON field of type
891 * timestamp.
892 *
893 * @param name name of the field to add to the object
894 * @param at timestamp pack, a value of 0 is only
754 * allowed with #GNUNET_JSON_pack_allow_null()! 895 * allowed with #GNUNET_JSON_pack_allow_null()!
755 * @return json pack specification 896 * @return json pack specification
756 */ 897 */
757struct GNUNET_JSON_PackSpec 898struct GNUNET_JSON_PackSpec
758GNUNET_JSON_pack_time_abs (const char *name, 899GNUNET_JSON_pack_timestamp (const char *name,
759 struct GNUNET_TIME_Absolute at); 900 struct GNUNET_TIME_Timestamp at);
760 901
761 902
762/** 903/**
763 * Generate packer instruction for a JSON field of type 904 * Generate packer instruction for a JSON field of type
764 * absolute time in network byte order. 905 * timestamp in network byte order.
765 * 906 *
766 * @param name name of the field to add to the object 907 * @param name name of the field to add to the object
767 * @param at absolute time to pack, a value of 0 is only 908 * @param at timestamp to pack, a value of 0 is only
768 * allowed with #GNUNET_JSON_pack_allow_null()! 909 * allowed with #GNUNET_JSON_pack_allow_null()!
769 * @return json pack specification 910 * @return json pack specification
770 */ 911 */
771struct GNUNET_JSON_PackSpec 912struct GNUNET_JSON_PackSpec
772GNUNET_JSON_pack_time_abs_nbo (const char *name, 913GNUNET_JSON_pack_timestamp_nbo (const char *name,
773 struct GNUNET_TIME_AbsoluteNBO at); 914 struct GNUNET_TIME_TimestampNBO at);
774 915
775 916
776/** 917/**
@@ -825,6 +966,19 @@ GNUNET_JSON_pack_rsa_signature (const char *name,
825 const struct GNUNET_CRYPTO_RsaSignature *sig); 966 const struct GNUNET_CRYPTO_RsaSignature *sig);
826 967
827 968
969/**
970 * Generate packer instruction for a JSON field of type
971 * unblinded signature.
972 *
973 * @param name name of the field to add to the object
974 * @param sig unblinded signature
975 * @return json pack specification
976 */
977struct GNUNET_JSON_PackSpec
978GNUNET_JSON_pack_unblinded_signature (const char *name,
979 const struct GNUNET_CRYPTO_UnblindedSignature *sig);
980
981
828#endif 982#endif
829 983
830/* end of gnunet_json_lib.h */ 984/* end of gnunet_json_lib.h */
diff --git a/src/include/gnunet_load_lib.h b/src/include/gnunet_load_lib.h
index ef596807a..56cacfbbb 100644
--- a/src/include/gnunet_load_lib.h
+++ b/src/include/gnunet_load_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 48#include "gnunet_time_lib.h"
45 49
@@ -124,4 +128,6 @@ GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
124 128
125/** @} */ /* end of group */ 129/** @} */ /* end of group */
126 130
131/** @} */ /* end of group addition to libgnunetutil */
132
127/* end of gnunet_load_lib.h */ 133/* end of gnunet_load_lib.h */
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index 96d48b411..1bc68b87b 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2024 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -39,21 +39,21 @@ extern "C" {
39#endif 39#endif
40#endif 40#endif
41 41
42#include "platform.h" 42#include "gnunet_common.h"
43#include "gnunet_configuration_lib.h" 43#include "gnunet_configuration_lib.h"
44#include "gnunet_crypto_lib.h"
45#include "gnunet_identity_service.h" 44#include "gnunet_identity_service.h"
46#include "gnunet_mq_lib.h" 45#include "gnunet_reclaim_lib.h"
47#include "gnunet_protocols.h" 46#include "gnunet_reclaim_service.h"
48#include "gnunet_scheduler_lib.h" 47#include "gnunet_scheduler_lib.h"
49#include "gnunet_time_lib.h" 48#include "gnunet_time_lib.h"
49#include "gnunet_util_lib.h"
50 50
51/** 51/**
52 * Version number of GNUnet Messenger API. 52 * Version number of GNUnet Messenger API.
53 * 53 *
54 * Current version of the Messenger: 0.1 54 * Current version of the Messenger: 0.3
55 */ 55 */
56#define GNUNET_MESSENGER_VERSION 0x00000001 56#define GNUNET_MESSENGER_VERSION 0x00000003
57 57
58/** 58/**
59 * Identifier of GNUnet MESSENGER Service. 59 * Identifier of GNUnet MESSENGER Service.
@@ -96,6 +96,27 @@ struct GNUNET_MESSENGER_RoomEntryRecord
96 96
97GNUNET_NETWORK_STRUCT_END 97GNUNET_NETWORK_STRUCT_END
98 98
99 GNUNET_NETWORK_STRUCT_BEGIN
100
101/**
102 * A room details record specifies a custom name for a given room and
103 * some additional space for flags.
104 */
105struct GNUNET_MESSENGER_RoomDetailsRecord
106{
107 /**
108 * The custom name for the room.
109 */
110 char name[256];
111
112 /**
113 * The flags of the room.
114 */
115 uint32_t flags;
116};
117
118GNUNET_NETWORK_STRUCT_END
119
99/** 120/**
100 * Enum for the different supported kinds of messages 121 * Enum for the different supported kinds of messages
101 */ 122 */
@@ -177,6 +198,26 @@ enum GNUNET_MESSENGER_MessageKind
177 GNUNET_MESSENGER_KIND_DELETE = 15, 198 GNUNET_MESSENGER_KIND_DELETE = 15,
178 199
179 /** 200 /**
201 * The connection kind. The message contains a #GNUNET_MESSENGER_MessageConnection body.
202 */
203 GNUNET_MESSENGER_KIND_CONNECTION = 16,
204
205 /**
206 * The ticket kind. The message contains a #GNUNET_MESSENGER_MessageTicket body.
207 */
208 GNUNET_MESSENGER_KIND_TICKET = 17,
209
210 /**
211 * The transcript kind. The message contains a #GNUNET_MESSENGER_MessageTranscript body.
212 */
213 GNUNET_MESSENGER_KIND_TRANSCRIPT = 18,
214
215 /**
216 * The tag kind. The message contains a #GNUNET_MESSENGER_MessageTag body.
217 */
218 GNUNET_MESSENGER_KIND_TAG = 19,
219
220 /**
180 * The unknown kind. The message contains an unknown body. 221 * The unknown kind. The message contains an unknown body.
181 */ 222 */
182 GNUNET_MESSENGER_KIND_UNKNOWN = 0 223 GNUNET_MESSENGER_KIND_UNKNOWN = 0
@@ -204,7 +245,7 @@ struct GNUNET_MESSENGER_MessageHeader
204 /** 245 /**
205 * The signature of the senders private key. 246 * The signature of the senders private key.
206 */ 247 */
207 struct GNUNET_IDENTITY_Signature signature; 248 struct GNUNET_CRYPTO_Signature signature;
208 249
209 /** 250 /**
210 * The timestamp of the message. 251 * The timestamp of the message.
@@ -236,11 +277,6 @@ struct GNUNET_MESSENGER_MessageHeader
236struct GNUNET_MESSENGER_MessageInfo 277struct GNUNET_MESSENGER_MessageInfo
237{ 278{
238 /** 279 /**
239 * The senders key to verify its signatures.
240 */
241 struct GNUNET_IDENTITY_PublicKey host_key;
242
243 /**
244 * The version of GNUnet Messenger API. 280 * The version of GNUnet Messenger API.
245 * 281 *
246 * The sixteen lower bits represent the lower version number while the sixteen higher bits 282 * The sixteen lower bits represent the lower version number while the sixteen higher bits
@@ -261,7 +297,7 @@ struct GNUNET_MESSENGER_MessageJoin
261 /** 297 /**
262 * The senders public key to verify its signatures. 298 * The senders public key to verify its signatures.
263 */ 299 */
264 struct GNUNET_IDENTITY_PublicKey key; 300 struct GNUNET_CRYPTO_PublicKey key;
265}; 301};
266 302
267/** 303/**
@@ -299,7 +335,7 @@ struct GNUNET_MESSENGER_MessageKey
299 /** 335 /**
300 * The new public key which replaces the current senders public key. 336 * The new public key which replaces the current senders public key.
301 */ 337 */
302 struct GNUNET_IDENTITY_PublicKey key; 338 struct GNUNET_CRYPTO_PublicKey key;
303}; 339};
304 340
305/** 341/**
@@ -478,6 +514,87 @@ struct GNUNET_MESSENGER_MessageDelete
478}; 514};
479 515
480/** 516/**
517 * A connection message body
518 * This allows to tell others about connection information about a peer.
519 *
520 * Message-body-size: 8 bytes
521 */
522struct GNUNET_MESSENGER_MessageConnection
523{
524 /**
525 * The amount of connections of a peer.
526 */
527 uint32_t amount;
528
529 /**
530 * The flags about the connections of a peer.
531 */
532 uint32_t flags;
533};
534
535/**
536 * A ticket message body
537 * This allows to exchange ticket identifiers with an audience.
538 *
539 * Message-body-size: 32 bytes
540 */
541struct GNUNET_MESSENGER_MessageTicket
542{
543 /**
544 * The identifier of a RECLAIM ticket.
545 */
546 struct GNUNET_RECLAIM_Identifier identifier;
547};
548
549/**
550 * A transcript message body
551 * This allows reading the content of a sent private message.
552 *
553 * Message-body-size: 68+
554 */
555struct GNUNET_MESSENGER_MessageTranscript
556{
557 /**
558 * The hash of the original message.
559 */
560 struct GNUNET_HashCode hash;
561
562 /**
563 * The key from the recipient of the original message.
564 */
565 struct GNUNET_CRYPTO_PublicKey key;
566
567 /**
568 * The length of the transcribed message.
569 */
570 uint16_t length;
571
572 /**
573 * The data of the transcribed message.
574 */
575 char *data;
576};
577
578/**
579 * A tag message body
580 * This allows tagging a message with a custom tag.
581 *
582 * Message-body-size: 32+
583 */
584struct GNUNET_MESSENGER_MessageTag
585{
586 /**
587 * The hash of the message to tag.
588 */
589 struct GNUNET_HashCode hash;
590
591 /**
592 * The custom tag.
593 */
594 char *tag;
595};
596
597/**
481 * The unified body of a #GNUNET_MESSENGER_Message. 598 * The unified body of a #GNUNET_MESSENGER_Message.
482 */ 599 */
483struct GNUNET_MESSENGER_MessageBody 600struct GNUNET_MESSENGER_MessageBody
@@ -499,6 +616,10 @@ struct GNUNET_MESSENGER_MessageBody
499 struct GNUNET_MESSENGER_MessageFile file; 616 struct GNUNET_MESSENGER_MessageFile file;
500 struct GNUNET_MESSENGER_MessagePrivate privacy; 617 struct GNUNET_MESSENGER_MessagePrivate privacy;
501 struct GNUNET_MESSENGER_MessageDelete deletion; 618 struct GNUNET_MESSENGER_MessageDelete deletion;
619 struct GNUNET_MESSENGER_MessageConnection connection;
620 struct GNUNET_MESSENGER_MessageTicket ticket;
621 struct GNUNET_MESSENGER_MessageTranscript transcript;
622 struct GNUNET_MESSENGER_MessageTag tag;
502 }; 623 };
503}; 624};
504 625
@@ -519,7 +640,7 @@ struct GNUNET_MESSENGER_Message
519}; 640};
520 641
521/** 642/**
522 * Enum for the different supported flags used by message handling 643 * Enum for the different supported flags used by message handling.
523 * Compatible flags can be OR'ed together. 644 * Compatible flags can be OR'ed together.
524 */ 645 */
525enum GNUNET_MESSENGER_MessageFlags 646enum GNUNET_MESSENGER_MessageFlags
@@ -538,18 +659,44 @@ enum GNUNET_MESSENGER_MessageFlags
538 * The private flag. The flag indicates that the message was privately encrypted. 659 * The private flag. The flag indicates that the message was privately encrypted.
539 */ 660 */
540 GNUNET_MESSENGER_FLAG_PRIVATE = 2, 661 GNUNET_MESSENGER_FLAG_PRIVATE = 2,
662
663 /**
664 * The peer flag. The flag indicates that the message was sent by a peer and not a member.
665 */
666 GNUNET_MESSENGER_FLAG_PEER = 4,
667
668 /**
669 * The recent flag. The flag indicates that the message was recently handled by the service.
670 */
671 GNUNET_MESSENGER_FLAG_RECENT = 8,
672
673 /**
674 * The update flag. The flag indicates that the message was updated by the client.
675 */
676 GNUNET_MESSENGER_FLAG_UPDATE = 16,
677
678 /**
679 * The delete flag. The flag indicates that the message was deleted by the service.
680 */
681 GNUNET_MESSENGER_FLAG_DELETE = 32,
541}; 682};
542 683
543/** 684/**
544 * Method called whenever the EGO of a <i>handle</i> changes or if the first connection fails 685 * Enum for the different supported flags used to specify connection handling.
545 * to load a valid EGO and the anonymous key pair will be used instead. 686 * Compatible flags can be OR'ed together.
546 *
547 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
548 * @param[in/out] handle Messenger handle
549 */ 687 */
550typedef void 688enum GNUNET_MESSENGER_ConnectionFlags
551(*GNUNET_MESSENGER_IdentityCallback) (void *cls, 689{
552 struct GNUNET_MESSENGER_Handle *handle); 690 /**
691 * The none flag. The flag indicates that the connection is not affected by any modifications.
692 */
693 GNUNET_MESSENGER_FLAG_CONNECTION_NONE = 0,/**< GNUNET_MESSENGER_FLAG_CONNECTION_NONE */
694
695 /**
696 * The auto flag. The flag indicates that a peer will automatically handle routing.
697 */
698 GNUNET_MESSENGER_FLAG_CONNECTION_AUTO = 1,/**< GNUNET_MESSENGER_FLAG_CONNECTION_AUTO */
699};
553 700
554/** 701/**
555 * Method called whenever a message is sent or received from a <i>room</i>. 702 * Method called whenever a message is sent or received from a <i>room</i>.
@@ -560,6 +707,7 @@ typedef void
560 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect 707 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
561 * @param[in] room Room handle 708 * @param[in] room Room handle
562 * @param[in] sender Sender of message 709 * @param[in] sender Sender of message
710 * @param[in] recipient Recipient of message
563 * @param[in] message Newly received or sent message 711 * @param[in] message Newly received or sent message
564 * @param[in] hash Hash identifying the message 712 * @param[in] hash Hash identifying the message
565 * @param[in] flags Flags of the message 713 * @param[in] flags Flags of the message
@@ -567,8 +715,12 @@ typedef void
567typedef void 715typedef void
568(*GNUNET_MESSENGER_MessageCallback) (void *cls, 716(*GNUNET_MESSENGER_MessageCallback) (void *cls,
569 struct GNUNET_MESSENGER_Room *room, 717 struct GNUNET_MESSENGER_Room *room,
570 const struct GNUNET_MESSENGER_Contact *sender, 718 const struct
571 const struct GNUNET_MESSENGER_Message *message, 719 GNUNET_MESSENGER_Contact *sender,
720 const struct
721 GNUNET_MESSENGER_Contact *recipient,
722 const struct
723 GNUNET_MESSENGER_Message *message,
572 const struct GNUNET_HashCode *hash, 724 const struct GNUNET_HashCode *hash,
573 enum GNUNET_MESSENGER_MessageFlags flags); 725 enum GNUNET_MESSENGER_MessageFlags flags);
574 726
@@ -580,49 +732,34 @@ typedef void
580 * @param[in] room Room handle 732 * @param[in] room Room handle
581 * @param[in] contact Contact handle 733 * @param[in] contact Contact handle
582 */ 734 */
583typedef int 735typedef enum GNUNET_GenericReturnValue
584(*GNUNET_MESSENGER_MemberCallback) (void* cls, 736(*GNUNET_MESSENGER_MemberCallback) (void *cls,
585 struct GNUNET_MESSENGER_Room *room, 737 struct GNUNET_MESSENGER_Room *room,
586 const struct GNUNET_MESSENGER_Contact *contact); 738 const struct
739 GNUNET_MESSENGER_Contact *contact);
587 740
588/** 741/**
589 * Set up a handle for the messenger related functions and connects to all necessary services. It will look up the ego 742 * Set up a handle for the messenger related functions and connects to all necessary services. It will use the
590 * key identified by its <i>name</i> and use it for signing all messages from the handle. 743 * a custom name in combination of a private key provided for signing all messages from the handle.
591 * 744 *
592 * @param[in] cfg Configuration to use 745 * @param[in] cfg Configuration to use
593 * @param[in] name Name to look up an ego or NULL to stay anonymous 746 * @param[in] name Name or NULL
594 * @param[in] identity_callback Function called when the EGO of the handle changes 747 * @param[in] key Private key or NULL to stay anonymous
595 * @param[in/out] identity_cls Closure for the <i>identity_callback</i> handler
596 * @param[in] msg_callback Function called when a new message is sent or received 748 * @param[in] msg_callback Function called when a new message is sent or received
597 * @param[in/out] msg_cls Closure for the <i>msg_callback</i> handler 749 * @param[in,out] msg_cls Closure for the <i>msg_callback</i> handler
598 * @return Messenger handle to use, NULL on error 750 * @return Messenger handle to use, NULL on error
599 */ 751 */
600struct GNUNET_MESSENGER_Handle* 752struct GNUNET_MESSENGER_Handle*
601GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 753GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
602 const char *name, 754 const char *name,
603 GNUNET_MESSENGER_IdentityCallback identity_callback, 755 const struct GNUNET_CRYPTO_PrivateKey *key,
604 void *identity_cls,
605 GNUNET_MESSENGER_MessageCallback msg_callback, 756 GNUNET_MESSENGER_MessageCallback msg_callback,
606 void *msg_cls); 757 void *msg_cls);
607 758
608/** 759/**
609 * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All
610 * participated rooms get informed about the key renewal. The handle requires a set name for this function to work and
611 * it needs to be unused by other egos.
612 *
613 * Keep in mind that this will fully delete the old ego key (if any is used) even if any other service wants to use it
614 * as default.
615 *
616 * @param[in/out] handle Messenger handle to use
617 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
618 */
619int
620GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle);
621
622/**
623 * Disconnect all of the messengers used services and clears up its used memory. 760 * Disconnect all of the messengers used services and clears up its used memory.
624 * 761 *
625 * @param[in/out] handle Messenger handle to use 762 * @param[in,out] handle Messenger handle to use
626 */ 763 */
627void 764void
628GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle); 765GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle);
@@ -637,15 +774,14 @@ const char*
637GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle); 774GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle);
638 775
639/** 776/**
640 * Set the name for the messenger. This will rename the currently used ego and move all stored files related to the current 777 * Set the name for the messenger handle and sends messages renaming your contact in currently
641 * name to its new directory. If anything fails during this process the function returns #GNUNET_NO and the name for 778 * open rooms.
642 * the messenger won't change as specified.
643 * 779 *
644 * @param[in/out] handle Messenger handle to use 780 * @param[in,out] handle Messenger handle to use
645 * @param[in] name Name for the messenger to change to 781 * @param[in] name Name for the messenger to change to
646 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL 782 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL
647 */ 783 */
648int 784enum GNUNET_GenericReturnValue
649GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, 785GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
650 const char *name); 786 const char *name);
651 787
@@ -653,12 +789,25 @@ GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
653 * Get the public key used by the messenger or NULL if the anonymous key was used. 789 * Get the public key used by the messenger or NULL if the anonymous key was used.
654 * 790 *
655 * @param[in] handle Messenger handle to use 791 * @param[in] handle Messenger handle to use
656 * @return Used ego's public key or NULL 792 * @return Used public key or NULL
657 */ 793 */
658const struct GNUNET_IDENTITY_PublicKey* 794const struct GNUNET_CRYPTO_PublicKey*
659GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle); 795GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
660 796
661/** 797/**
798 * Set the private key used by the messenger or NULL if the anonymous key should be
799 * used instead. The currently used key will be replaced and the change will get signed
800 * accordingly to be verified by all contacts.
801 *
802 * @param[in,out] handle Messenger handle to use
803 * @param[in] key Private key to change to or NULL
804 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL
805 */
806enum GNUNET_GenericReturnValue
807GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle,
808 const struct GNUNET_CRYPTO_PrivateKey *key);
809
810/**
662 * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet 811 * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet
663 * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>. 812 * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>.
664 * 813 *
@@ -670,7 +819,7 @@ GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
670 * 819 *
671 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) 820 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
672 * 821 *
673 * @param[in/out] handle Messenger handle to use 822 * @param[in,out] handle Messenger handle to use
674 * @param[in] key Hash identifying the port 823 * @param[in] key Hash identifying the port
675 * @return Room handle, NULL on error 824 * @return Room handle, NULL on error
676 */ 825 */
@@ -691,7 +840,7 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle,
691 * 840 *
692 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) 841 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
693 * 842 *
694 * @param[in/out] handle Messenger handle to use 843 * @param[in,out] handle Messenger handle to use
695 * @param[in] door Peer identity of an open <b>door</b> 844 * @param[in] door Peer identity of an open <b>door</b>
696 * @param[in] key Hash identifying the port 845 * @param[in] key Hash identifying the port
697 * @return Room handle, NULL on error 846 * @return Room handle, NULL on error
@@ -708,7 +857,7 @@ GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle,
708 * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one 857 * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one
709 * or open the room on their own. ) 858 * or open the room on their own. )
710 * 859 *
711 * @param[in/out] room Room handle 860 * @param[in,out] room Room handle
712 */ 861 */
713void 862void
714GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room); 863GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room);
@@ -753,25 +902,51 @@ GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room,
753 const struct GNUNET_HashCode *hash); 902 const struct GNUNET_HashCode *hash);
754 903
755/** 904/**
905 * Get the contact of a member in a <i>room</i> which has been targeted as recipient of a specific message identified
906 * with a given <i>hash</i>.
907 *
908 * Notice that contacts are independent of rooms but will be removed if all rooms containing these contacts get closed.
909 *
910 * @param[in] room Room handle
911 * @param[in] hash Hash identifying a message
912 * @return Contact handle, NULL otherwise
913 */
914const struct GNUNET_MESSENGER_Contact*
915GNUNET_MESSENGER_get_recipient (const struct GNUNET_MESSENGER_Room *room,
916 const struct GNUNET_HashCode *hash);
917
918/**
756 * Get the name used by the <i>contact</i>. 919 * Get the name used by the <i>contact</i>.
757 * 920 *
758 * @param[in] contact Contact handle 921 * @param[in] contact Contact handle
759 * @return Name of <i>contact</i> or NULL 922 * @return Name of <i>contact</i> or NULL
760 */ 923 */
761const char* 924const char*
762GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact); 925GNUNET_MESSENGER_contact_get_name (const struct
926 GNUNET_MESSENGER_Contact *contact);
763 927
764/** 928/**
765 * Get the public key used by the <i>contact</i> or NULL if the anonymous key was used. 929 * Get the public key used by the <i>contact</i> or NULL if the anonymous key was used.
766 * 930 *
767 * @param[in] contact Contact handle 931 * @param[in] contact Contact handle
768 * @return Public key of the ego used by <i>contact</i> or NULL 932 * @return Public key used by <i>contact</i> or NULL
769 */ 933 */
770const struct GNUNET_IDENTITY_PublicKey* 934const struct GNUNET_CRYPTO_PublicKey*
771GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); 935GNUNET_MESSENGER_contact_get_key (const struct
936 GNUNET_MESSENGER_Contact *contact);
772 937
773/** 938/**
774 * Send a <i>message</i> into a </i>room</i>. If you opened the <i>room</i> all entered members will receive the 939 * Get the locally unique id of the <i>contact</i>.
940 *
941 * @param[in] contact Contact handle
942 * @return Locally unique contact id or zero
943 */
944size_t
945GNUNET_MESSENGER_contact_get_id (const struct
946 GNUNET_MESSENGER_Contact *contact);
947
948/**
949 * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the
775 * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the 950 * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the
776 * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively 951 * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively
777 * as long as the <i>message</i> is unknown to them. 952 * as long as the <i>message</i> is unknown to them.
@@ -784,14 +959,30 @@ GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact
784 * 959 *
785 * Sending a message to all members in a given room can be done by providing NULL as contact. 960 * Sending a message to all members in a given room can be done by providing NULL as contact.
786 * 961 *
787 * @param[in/out] room Room handle 962 * @param[in,out] room Room handle
788 * @param[in] message New message to send 963 * @param[in,out] message New message to send
789 * @param[in] contact Contact or NULL 964 * @param[in] contact Contact or NULL
790 */ 965 */
791void 966void
792GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, 967GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
793 const struct GNUNET_MESSENGER_Message *message, 968 const struct GNUNET_MESSENGER_Message *message,
794 const struct GNUNET_MESSENGER_Contact* contact); 969 const struct GNUNET_MESSENGER_Contact *contact);
970
971/**
972 * Delete a message identified by its <i>hash</i> from a <i>room</i>. A deletion will be propagated to all members
973 * of the room as with any other sent message. Notice that a deletion will only request other members of the room
974 * to delete the selected message. If you are not permitted to delete the message, the deletion will be ignored.
975 *
976 * Depending on the implementation other clients may also ignore your deletion request in other circumstances.
977 *
978 * @param[in,out] room Room handle
979 * @param[in] message Message to delete
980 * @param[in] delay Delay to delete the message
981 */
982void
983GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room,
984 const struct GNUNET_HashCode *hash,
985 const struct GNUNET_TIME_Relative delay);
795 986
796/** 987/**
797 * Get the message in a <i>room</i> identified by its <i>hash</i>. 988 * Get the message in a <i>room</i> identified by its <i>hash</i>.
@@ -817,7 +1008,23 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room,
817int 1008int
818GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, 1009GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room,
819 GNUNET_MESSENGER_MemberCallback callback, 1010 GNUNET_MESSENGER_MemberCallback callback,
820 void* cls); 1011 void *cls);
1012
1013/**
1014 * Send a <i>ticket</i> into a <i>room</i>. The ticket will automatically be converted
1015 * into a message to be sent only to its audience as a private message.
1016 *
1017 * A ticket can only be sent with this function if its issuer's public key is the one
1018 * being used by the messenger. The audience's public key is not allowed to be the
1019 * anonymous public key. The room needs to contain a member using the audience's public
1020 * key.
1021 *
1022 * @param[in,out] room Room handle
1023 * @param[in] ticket Ticket to send
1024 */
1025void
1026GNUNET_MESSENGER_send_ticket (struct GNUNET_MESSENGER_Room *room,
1027 const struct GNUNET_RECLAIM_Ticket *ticket);
821 1028
822#if 0 /* keep Emacsens' auto-indent happy */ 1029#if 0 /* keep Emacsens' auto-indent happy */
823{ 1030{
diff --git a/src/include/gnunet_mhd_compat.h b/src/include/gnunet_mhd_compat.h
index 0cfcc6445..7ef297c2f 100644
--- a/src/include/gnunet_mhd_compat.h
+++ b/src/include/gnunet_mhd_compat.h
@@ -25,6 +25,7 @@
25 * MHD compatibility definitions for warning-less compile of 25 * MHD compatibility definitions for warning-less compile of
26 * our code against MHD before and after #MHD_VERSION 0x00097002. 26 * our code against MHD before and after #MHD_VERSION 0x00097002.
27 */ 27 */
28
28#include <microhttpd.h> 29#include <microhttpd.h>
29 30
30#if MHD_VERSION >= 0x00097002 31#if MHD_VERSION >= 0x00097002
@@ -35,7 +36,7 @@
35 36
36#else 37#else
37 38
38/** 39**
39 * Data type to use for functions return an "MHD result". 40 * Data type to use for functions return an "MHD result".
40 */ 41 */
41#define MHD_RESULT int 42#define MHD_RESULT int
diff --git a/src/include/gnunet_microphone_lib.h b/src/include/gnunet_microphone_lib.h
index 2b08bcd71..394caed68 100644
--- a/src/include/gnunet_microphone_lib.h
+++ b/src/include/gnunet_microphone_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_util_lib.h" 48#include "gnunet_util_lib.h"
45 49
46/** 50/**
@@ -141,4 +145,6 @@ GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone);
141 145
142/** @} */ /* end of group */ 146/** @} */ /* end of group */
143 147
148/** @} */ /* end of group addition */
149
144/* end of gnunet_microphone_lib.h */ 150/* end of gnunet_microphone_lib.h */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index a1c5c4957..3eca71f0f 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -18,7 +18,17 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#include "gnunet_common.h"
22#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
26
21/** 27/**
28 * @addtogroup libgnunetutil
29 * Multi-function utilities library for GNUnet programs
30 * @{
31 *
22 * @author Florian Dold 32 * @author Florian Dold
23 * @author Christian Grothoff 33 * @author Christian Grothoff
24 * 34 *
@@ -35,6 +45,7 @@
35#ifndef GNUNET_MQ_LIB_H 45#ifndef GNUNET_MQ_LIB_H
36#define GNUNET_MQ_LIB_H 46#define GNUNET_MQ_LIB_H
37 47
48
38#include "gnunet_scheduler_lib.h" 49#include "gnunet_scheduler_lib.h"
39 50
40/** 51/**
@@ -386,9 +397,9 @@ typedef void
386 * FIFO of envelopes independent of MQ itself and wants to 397 * FIFO of envelopes independent of MQ itself and wants to
387 * re-use the pointers internal to @a env. Use with caution. 398 * re-use the pointers internal to @a env. Use with caution.
388 * 399 *
389 * @param[in|out] env_head of envelope DLL 400 * @param[in,out] env_head of envelope DLL
390 * @param[in|out] env_tail tail of envelope DLL 401 * @param[in,out] env_tail tail of envelope DLL
391 * @param[in|out] env element to insert at the tail 402 * @param[in,out] env element to insert at the tail
392 */ 403 */
393void 404void
394GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, 405GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
@@ -404,9 +415,9 @@ GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
404 * FIFO of envelopes independent of MQ itself and wants to 415 * FIFO of envelopes independent of MQ itself and wants to
405 * re-use the pointers internal to @a env. Use with caution. 416 * re-use the pointers internal to @a env. Use with caution.
406 * 417 *
407 * @param[in|out] env_head of envelope DLL 418 * @param[in,out] env_head of envelope DLL
408 * @param[in|out] env_tail tail of envelope DLL 419 * @param[in,out] env_tail tail of envelope DLL
409 * @param[in|out] env element to insert at the tail 420 * @param[in,out] env element to insert at the tail
410 */ 421 */
411void 422void
412GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 423GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
@@ -422,9 +433,9 @@ GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
422 * FIFO of envelopes independent of MQ itself and wants to 433 * FIFO of envelopes independent of MQ itself and wants to
423 * re-use the pointers internal to @a env. Use with caution. 434 * re-use the pointers internal to @a env. Use with caution.
424 * 435 *
425 * @param[in|out] env_head of envelope DLL 436 * @param[in,out] env_head of envelope DLL
426 * @param[in|out] env_tail tail of envelope DLL 437 * @param[in,out] env_tail tail of envelope DLL
427 * @param[in|out] env element to remove from the DLL 438 * @param[in,out] env element to remove from the DLL
428 */ 439 */
429void 440void
430GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head, 441GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
@@ -597,6 +608,7 @@ struct GNUNET_MQ_MessageHandler
597 * "context"), 608 * "context"),
598 * GNUNET_MQ_handler_end() 609 * GNUNET_MQ_handler_end()
599 * }; 610 * };
611 * </code>
600 * 612 *
601 * @param name unique basename for the functions 613 * @param name unique basename for the functions
602 * @param code message type constant 614 * @param code message type constant
@@ -680,7 +692,7 @@ struct GNUNET_MQ_MessageHandler
680 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched, 692 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched,
681 * #GNUNET_SYSERR if message was rejected by check function 693 * #GNUNET_SYSERR if message was rejected by check function
682 */ 694 */
683int 695enum GNUNET_GenericReturnValue
684GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, 696GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
685 const struct GNUNET_MessageHeader *mh); 697 const struct GNUNET_MessageHeader *mh);
686 698
@@ -983,7 +995,7 @@ GNUNET_MQ_destroy_notify_cancel (
983 * Call the message message handler that was registered 995 * Call the message message handler that was registered
984 * for the type of the given message in the given message queue. 996 * for the type of the given message in the given message queue.
985 * 997 *
986 * This function is indented to be used for the implementation 998 * This function is intended to be used for the implementation
987 * of message queues. 999 * of message queues.
988 * 1000 *
989 * @param mq message queue with the handlers 1001 * @param mq message queue with the handlers
@@ -1120,3 +1132,5 @@ GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
1120#endif 1132#endif
1121 1133
1122/** @} */ /* end of group mq */ 1134/** @} */ /* end of group mq */
1135
1136/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_mst_lib.h b/src/include/gnunet_mst_lib.h
index 9f3431b98..5b848bbd6 100644
--- a/src/include/gnunet_mst_lib.h
+++ b/src/include/gnunet_mst_lib.h
@@ -19,6 +19,13 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -32,6 +39,10 @@
32 * @{ 39 * @{
33 */ 40 */
34 41
42#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
43#error "Only <gnunet_util_lib.h> can be included directly."
44#endif
45
35#ifndef GNUNET_MST_LIB_H 46#ifndef GNUNET_MST_LIB_H
36#define GNUNET_MST_LIB_H 47#define GNUNET_MST_LIB_H
37 48
@@ -43,8 +54,6 @@ extern "C"
43#endif 54#endif
44#endif 55#endif
45 56
46#include "gnunet_common.h"
47
48 57
49/** 58/**
50 * Handle to a message stream tokenizer. 59 * Handle to a message stream tokenizer.
@@ -96,7 +105,7 @@ GNUNET_MST_create (GNUNET_MessageTokenizerCallback cb,
96 * #GNUNET_NO if one_shot was set and we have another message ready 105 * #GNUNET_NO if one_shot was set and we have another message ready
97 * #GNUNET_SYSERR if the data stream is corrupt 106 * #GNUNET_SYSERR if the data stream is corrupt
98 */ 107 */
99int 108enum GNUNET_GenericReturnValue
100GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, 109GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
101 const char *buf, 110 const char *buf,
102 size_t size, 111 size_t size,
@@ -118,7 +127,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
118 * #GNUNET_NO if one_shot was set and we have another message ready 127 * #GNUNET_NO if one_shot was set and we have another message ready
119 * #GNUNET_SYSERR if the data stream is corrupt 128 * #GNUNET_SYSERR if the data stream is corrupt
120 */ 129 */
121int 130enum GNUNET_GenericReturnValue
122GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, 131GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
123 struct GNUNET_NETWORK_Handle *sock, 132 struct GNUNET_NETWORK_Handle *sock,
124 int purge, 133 int purge,
@@ -136,7 +145,7 @@ GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
136 * #GNUNET_NO if one_shot was set and we have another message ready 145 * #GNUNET_NO if one_shot was set and we have another message ready
137 * #GNUNET_SYSERR if the data stream is corrupt 146 * #GNUNET_SYSERR if the data stream is corrupt
138 */ 147 */
139int 148enum GNUNET_GenericReturnValue
140GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst, 149GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst,
141 int one_shot); 150 int one_shot);
142 151
@@ -161,4 +170,8 @@ GNUNET_MST_destroy (struct GNUNET_MessageStreamTokenizer *mst);
161 170
162/** @} */ /* end of group server */ 171/** @} */ /* end of group server */
163 172
173/** @} */ /* end of group addition to networking */
174
175/** @} */ /* end of group addition to libgnunetutil*/
176
164/* end of gnunet_mst_lib.h */ 177/* end of gnunet_mst_lib.h */
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h
deleted file mode 100644
index 0c95d50d0..000000000
--- a/src/include/gnunet_my_lib.h
+++ /dev/null
@@ -1,500 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 * @author Christophe Genevey
23 *
24 * @file
25 * Helper library to access a MySQL database
26 *
27 * @defgroup mysql MySQL library
28 * Helper library to access a MySQL database.
29 * @{
30 */
31#ifndef GNUNET_MY_LIB_H
32#define GNUNET_MY_LIB_H
33
34#include "gnunet_util_lib.h"
35#include "gnunet_mysql_lib.h"
36#include <mysql/mysql.h>
37
38#ifdef __cplusplus
39extern "C"
40{
41#if 0 /* keep Emacsens' auto-indent happy */
42}
43#endif
44#endif
45
46
47/**
48 * Information we pass to #GNUNET_MY_exec_prepared() to
49 * initialize the arguments of the prepared statement.
50 */
51struct GNUNET_MY_QueryParam;
52
53
54/**
55 * Function called to convert input argument into SQL parameters.
56 *
57 * @param cls closure
58 * @param pq data about the query
59 * @param qbind array of parameters to initialize
60 * @return -1 on error
61 */
62typedef int
63(*GNUNET_MY_QueryConverter)(void *cls,
64 const struct GNUNET_MY_QueryParam *qp,
65 MYSQL_BIND *qbind);
66
67
68/**
69 * Function called to cleanup result data.
70 *
71 * @param cls closure
72 * @param rs spec to clean up
73 */
74typedef void
75(*GNUNET_MY_QueryCleanup)(void *cls,
76 MYSQL_BIND *qbind);
77/**
78 * Information we pass to #GNUNET_MY_exec_prepared() to
79 * initialize the arguments of the prepared statement.
80 */
81
82
83struct GNUNET_MY_QueryParam
84{
85 /**
86 * Function to call for the type conversion.
87 */
88 GNUNET_MY_QueryConverter conv;
89
90 /**
91 * Function to call for cleaning up the query. Can be NULL.
92 */
93 GNUNET_MY_QueryCleanup cleaner;
94
95 /**
96 * Closure for @e conv.
97 */
98 void *conv_cls;
99
100 /**
101 * Number of arguments the @a conv converter expects to initialize.
102 */
103 unsigned int num_params;
104
105 /**
106 * Information to pass to @e conv.
107 */
108 const void *data;
109
110 /**
111 * Information to pass to @e conv. Size of @a data.
112 */
113 unsigned long data_len;
114};
115
116/**
117 * End of query parameter specification.
118 *
119 * @return array last entry for the result specification to use
120 */
121#define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
122
123
124/**
125 * Generate query parameter for a buffer @a ptr of
126 * @a ptr_size bytes.FG
127 *
128 * @param ptr pointer to the query parameter to pass
129 * @oaran ptr_size number of bytes in @a ptr
130 */
131struct GNUNET_MY_QueryParam
132GNUNET_MY_query_param_fixed_size (const void *ptr,
133 size_t ptr_size);
134
135
136/**
137 * Run a prepared SELECT statement.
138 *
139 * @param mc mysql context
140 * @param sh handle to SELECT statement
141 * @param params parameters to the statement
142 * @return TBD
143 */
144int
145GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
146 struct GNUNET_MYSQL_StatementHandle *sh,
147 struct GNUNET_MY_QueryParam *params);
148
149
150/**
151 * Information we pass to #GNUNET_MY_extract_result() to
152 * initialize the arguments of the prepared statement.
153 */
154struct GNUNET_MY_ResultParam;
155
156/**
157 * Information we pass to #GNUNET_MY_extract_result() to
158 * initialize the arguments of the prepared statement.
159 */
160struct GNUNET_MY_ResultSpec;
161
162/**
163 * Function called to convert input argument into SQL parameters.
164 *
165 * @param cls closure
166 * @param[in,out] rs
167 * @param stmt the mysql statement that is being run
168 * @param column the column that is being processed
169 * @param[out] results
170 * @return -1 on error
171 */
172typedef int
173(*GNUNET_MY_ResultConverter)(void *cls,
174 struct GNUNET_MY_ResultSpec *rs,
175 MYSQL_STMT *stmt,
176 unsigned int column,
177 MYSQL_BIND *results);
178
179/**
180 * Function called to cleanup result data.
181 *
182 * @param cls closure
183 * @param rs spec to clean up
184 */
185typedef void
186(*GNUNET_MY_ResultCleanup)(void *cls,
187 struct GNUNET_MY_ResultSpec *rs);
188
189
190/**
191 * Information we pass to #GNUNET_MY_extract_result() to
192 * initialize the arguments of the prepared statement.
193 */
194struct GNUNET_MY_ResultSpec
195{
196 /**
197 * Function to call to initialize the MYSQL_BIND array.
198 */
199 GNUNET_MY_ResultConverter pre_conv;
200
201 /**
202 * Function to call for converting the result. Can be NULL.
203 */
204 GNUNET_MY_ResultConverter post_conv;
205
206 /**
207 * Function to call for cleaning up the result. Can be NULL.
208 */
209 GNUNET_MY_ResultCleanup cleaner;
210
211 /**
212 * Closure for @e conv.
213 */
214 void *conv_cls;
215
216 /**
217 * Destination for the data.
218 */
219 void *dst;
220
221 /**
222 * Allowed size for the data, 0 for variable-size
223 * (in this case, the type of @e dst is a `void **`
224 * and we need to allocate a buffer of the right size).
225 */
226 size_t dst_size;
227
228 /**
229 * Where to store actual size of the result.
230 */
231 size_t *result_size;
232
233 /**
234 * How many fields does this result specification occupy
235 * in the result returned by MySQL.
236 */
237 unsigned int num_fields;
238
239 /**
240 * Location where we temporarily store the output buffer
241 * length from MySQL. Internal to libgnunetmy.
242 */
243 unsigned long mysql_bind_output_length;
244
245 /**
246 * Memory for MySQL to notify us about NULL values.
247 */
248 MYSQL_BOOL is_null;
249};
250
251
252/**
253 * End of result speceter specification.
254 *
255 * @return array last entry for the result specification to use
256 */
257#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
258
259
260/**
261 * Obtain fixed size result of @a ptr_size bytes from
262 * MySQL, store in already allocated buffer at @a ptr.
263 *
264 * @spec ptr where to write the result
265 * @oaran ptr_size number of bytes available at @a ptr
266 */
267struct GNUNET_MY_ResultSpec
268GNUNET_MY_result_spec_fixed_size (void *ptr,
269 size_t ptr_size);
270
271/**
272 * Generate query parameter for a string
273 *
274 *@param ptr pointer to the string query parameter to pass
275 */
276struct GNUNET_MY_QueryParam
277GNUNET_MY_query_param_string (const char *ptr);
278
279/**
280 * Generate fixed-size query parameter with size determined
281 * by variable type.
282 *
283 * @param x pointer to the query parameter to pass
284 */
285#define GNUNET_MY_query_param_auto_from_type( \
286 x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
287
288/**
289 * Generate query parameter for an RSA public key. The
290 * database must contain a BLOB type in the respective position.
291 *
292 * @param x the query parameter to pass
293 * @return array entry for the query parameters to use
294 */
295struct GNUNET_MY_QueryParam
296GNUNET_MY_query_param_rsa_public_key (const struct
297 GNUNET_CRYPTO_RsaPublicKey *x);
298
299/**
300 * Generate query parameter for an RSA signature. The
301 * database must contain a BLOB type in the respective position
302 *
303 *@param x the query parameter to pass
304 *@return array entry for the query parameters to use
305 */
306struct GNUNET_MY_QueryParam
307GNUNET_MY_query_param_rsa_signature (const struct
308 GNUNET_CRYPTO_RsaSignature *x);
309
310/**
311 * Generate query parameter for an absolute time value.
312 * The database must store a 64-bit integer.
313 *
314 *@param x pointer to the query parameter to pass
315 *@return array entry for the query parameters to use
316 */
317struct GNUNET_MY_QueryParam
318GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
319
320
321/**
322 * Generate query parameter for an absolute time value.
323 * The database must store a 64-bit integer.
324 *
325 *@param x pointer to the query parameter to pass
326 */
327struct GNUNET_MY_QueryParam
328GNUNET_MY_query_param_absolute_time_nbo (const struct
329 GNUNET_TIME_AbsoluteNBO *x);
330
331/**
332 * Generate query parameter for an uint16_t in host byte order.
333 *
334 * @param x pointer to the query parameter to pass
335 */
336struct GNUNET_MY_QueryParam
337GNUNET_MY_query_param_uint16 (const uint16_t *x);
338
339/**
340 * Generate query parameter for an uint32_t in host byte order
341 *
342 *@param x pointer to the query parameter to pass
343 */
344struct GNUNET_MY_QueryParam
345GNUNET_MY_query_param_uint32 (const uint32_t *x);
346
347/**
348 * Generate query parameter for an uint64_t in host byte order
349 *
350 *@param x pointer to the query parameter to pass
351 */
352struct GNUNET_MY_QueryParam
353GNUNET_MY_query_param_uint64 (const uint64_t *x);
354
355/**
356 * We expect a fixed-size result, with size determined by the type of `* dst`
357 *
358 * @spec name name of the field in the table
359 * @spec dst point to where to store the result, type fits expected result size
360 * @return array entry for the result specification to use
361 */
362#define GNUNET_MY_result_spec_auto_from_type( \
363 dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
364
365
366/**
367 * Variable-size result expected
368 *
369 * @param[out] dst where to store the result, allocated
370 * @param[out] sptr where to store the size of @a dst
371 * @return array entru for the result specification to use
372 */
373struct GNUNET_MY_ResultSpec
374GNUNET_MY_result_spec_variable_size (void **dst,
375 size_t *ptr_size);
376
377/**
378 * RSA public key expected
379 *
380 * @param name name of the field in the table
381 * @param[out] rsa where to store the result
382 * @return array entry for the result specification to use
383 */
384struct GNUNET_MY_ResultSpec
385GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
386
387
388/**
389 * RSA signature expected.
390 *
391 * @param[out] sig where to store the result;
392 * @return array entry for the result specification to use
393 */
394struct GNUNET_MY_ResultSpec
395GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
396
397/**
398 * 0- terminated string exprected.
399 *
400 * @param[out] dst where to store the result, allocated
401 * @return array entry for the result specification to use
402 */
403struct GNUNET_MY_ResultSpec
404GNUNET_MY_result_spec_string (char **dst);
405
406/**
407 * Absolute time expected
408 *
409 * @param name name of the field in the table
410 * @param[out] at where to store the result
411 * @return array entry for the result specification to use
412 */
413struct GNUNET_MY_ResultSpec
414GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
415
416/**
417 * Absolute time in network byte order expected
418 *
419 * @param[out] at where to store the result
420 * @return array entry for the result specification to use
421 */
422struct GNUNET_MY_ResultSpec
423GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
424
425/**
426 * uint16_t expected
427 *
428 * @param[out] u16 where to store the result
429 * @return array entry for the result specification to use
430 */
431struct GNUNET_MY_ResultSpec
432GNUNET_MY_result_spec_uint16 (uint16_t *u16);
433
434/**
435 * uint32_t expected
436 *
437 * @param[out] u32 where to store the result
438 * @return array entry for the result specification to use
439 */
440struct GNUNET_MY_ResultSpec
441GNUNET_MY_result_spec_uint32 (uint32_t *u32);
442
443/**
444 * uint64_t expected.
445 *
446 * @param[out] u64 where to store the result
447 * @return array entry for the result specification to use
448 */
449struct GNUNET_MY_ResultSpec
450GNUNET_MY_result_spec_uint64 (uint64_t *u64);
451
452
453/**
454 * Extract results from a query result according to the given
455 * specification. Always fetches the next row.
456 *
457 * @param sh statement that returned results
458 * @param rs specification to extract for
459 * @return
460 * #GNUNET_YES if all results could be extracted
461 * #GNUNET_NO if there is no more data in the result set
462 * #GNUNET_SYSERR if a result was invalid
463 */
464int
465GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
466 struct GNUNET_MY_ResultSpec *specs);
467
468
469/**
470 * Free all memory that was allocated in @a qp during
471 * #GNUNET_MY_exect_prepared().
472 *
473 * @param qp query specification to clean up
474 * @param qbind mysql query
475 */
476void
477GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
478 MYSQL_BIND *qbind);
479
480
481/**
482 * Free all memory that was allocated in @a rs during
483 * #GNUNET_MY_extract_result().
484 *
485 * @param rs reult specification to clean up
486 */
487void
488GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs);
489
490
491#if 0 /* keep Emacsens' auto-indent happy */
492{
493#endif
494#ifdef __cplusplus
495}
496#endif
497
498#endif
499
500/** @} */ /* end of group */
diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h
deleted file mode 100644
index 843d3ccb3..000000000
--- a/src/include/gnunet_mysql_lib.h
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Helper library to access a MySQL database
25 *
26 * @defgroup mysql MySQL library
27 * Helper library to access a MySQL database.
28 * @{
29 */
30#ifndef GNUNET_MYSQL_LIB_H
31#define GNUNET_MYSQL_LIB_H
32
33#include "gnunet_util_lib.h"
34#include <mysql/mysql.h>
35
36#ifdef __cplusplus
37extern "C"
38{
39#if 0 /* keep Emacsens' auto-indent happy */
40}
41#endif
42#endif
43
44#ifdef HAVE_MYSQL8
45 typedef bool MYSQL_BOOL;
46#else
47 typedef my_bool MYSQL_BOOL; //MySQL < 8 wants this
48#endif
49
50
51/**
52 * Mysql context.
53 */
54struct GNUNET_MYSQL_Context;
55
56
57/**
58 * Handle for a prepared statement.
59 */
60struct GNUNET_MYSQL_StatementHandle;
61
62
63/**
64 * Type of a callback that will be called for each
65 * data set returned from MySQL.
66 *
67 * @param cls user-defined argument
68 * @param num_values number of elements in values
69 * @param values values returned by MySQL
70 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
71 */
72typedef int
73(*GNUNET_MYSQL_DataProcessor) (void *cls,
74 unsigned int num_values,
75 MYSQL_BIND *values);
76
77
78/**
79 * Create a mysql context.
80 *
81 * @param cfg configuration
82 * @param section configuration section to use to get MySQL configuration options
83 * @return the mysql context
84 */
85struct GNUNET_MYSQL_Context *
86GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
87 const char *section);
88
89
90/**
91 * Destroy a mysql context. Also frees all associated prepared statements.
92 *
93 * @param mc context to destroy
94 */
95void
96GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc);
97
98
99/**
100 * Close database connection and all prepared statements (we got a DB
101 * error). The connection will automatically be re-opened and
102 * statements will be re-prepared if they are needed again later.
103 *
104 * @param mc mysql context
105 */
106void
107GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc);
108
109
110/**
111 * Get internal handle for a prepared statement. This function should rarely
112 * be used, and if, with caution! On failures during the interaction with
113 * the handle, you must call #GNUNET_MYSQL_statements_invalidate()!
114 *
115 * @param sh prepared statement to introspect
116 * @return MySQL statement handle, NULL on error
117 */
118MYSQL_STMT *
119GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh);
120
121
122/**
123 * Prepare a statement. Prepared statements are automatically discarded
124 * when the MySQL context is destroyed.
125 *
126 * @param mc mysql context
127 * @param query query text
128 * @return prepared statement, NULL on error
129 */
130struct GNUNET_MYSQL_StatementHandle *
131GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
132 const char *query);
133
134
135/**
136 * Run a SQL statement.
137 *
138 * @param mc mysql context
139 * @param sql SQL statement to run
140 * @return #GNUNET_OK on success
141 * #GNUNET_SYSERR if there was a problem
142 */
143int
144GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
145 const char *sql);
146
147
148#if 0 /* keep Emacsens' auto-indent happy */
149{
150#endif
151#ifdef __cplusplus
152}
153#endif
154
155#endif
156
157/** @} */ /* end of group */
diff --git a/src/include/gnunet_namecache_plugin.h b/src/include/gnunet_namecache_plugin.h
index 7c218fbeb..a3848bf4e 100644
--- a/src/include/gnunet_namecache_plugin.h
+++ b/src/include/gnunet_namecache_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,7 @@
34#ifndef GNUNET_NAMECACHE_PLUGIN_H 37#ifndef GNUNET_NAMECACHE_PLUGIN_H
35#define GNUNET_NAMECACHE_PLUGIN_H 38#define GNUNET_NAMECACHE_PLUGIN_H
36 39
40
37#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
38#include "gnunet_namecache_service.h" 42#include "gnunet_namecache_service.h"
39#include "gnunet_namestore_service.h" 43#include "gnunet_namestore_service.h"
@@ -106,3 +110,5 @@ struct GNUNET_NAMECACHE_PluginFunctions
106#endif 110#endif
107 111
108/** @} */ /* end of group */ 112/** @} */ /* end of group */
113
114/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namecache_service.h b/src/include/gnunet_namecache_service.h
index 07b26aec3..669386c37 100644
--- a/src/include/gnunet_namecache_service.h
+++ b/src/include/gnunet_namecache_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -38,6 +41,7 @@
38#ifndef GNUNET_NAMECACHE_SERVICE_H 41#ifndef GNUNET_NAMECACHE_SERVICE_H
39#define GNUNET_NAMECACHE_SERVICE_H 42#define GNUNET_NAMECACHE_SERVICE_H
40 43
44
41#include "gnunet_util_lib.h" 45#include "gnunet_util_lib.h"
42#include "gnunet_block_lib.h" 46#include "gnunet_block_lib.h"
43#include "gnunet_namestore_service.h" 47#include "gnunet_namestore_service.h"
@@ -173,3 +177,5 @@ GNUNET_NAMECACHE_cancel (struct GNUNET_NAMECACHE_QueueEntry *qe);
173#endif 177#endif
174 178
175/** @} */ /* end of group */ 179/** @} */ /* end of group */
180
181/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h
index 9cc8abc6e..b7bcc4eb6 100644
--- a/src/include/gnunet_namestore_plugin.h
+++ b/src/include/gnunet_namestore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_NAMESTORE_PLUGIN_H 34#ifndef GNUNET_NAMESTORE_PLUGIN_H
32#define GNUNET_NAMESTORE_PLUGIN_H 35#define GNUNET_NAMESTORE_PLUGIN_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_namestore_service.h" 39#include "gnunet_namestore_service.h"
36 40
@@ -49,6 +53,7 @@ extern "C"
49 * @param cls closure 53 * @param cls closure
50 * @param serial unique serial number of the record, MUST NOT BE ZERO, 54 * @param serial unique serial number of the record, MUST NOT BE ZERO,
51 * and must be monotonically increasing while iterating 55 * and must be monotonically increasing while iterating
56 * @param editor_hint content of the editor field when record was read (may be NULL)
52 * @param zone_key private key of the zone 57 * @param zone_key private key of the zone
53 * @param label name that is being mapped (at most 255 characters long) 58 * @param label name that is being mapped (at most 255 characters long)
54 * @param rd_count number of entries in @a rd array 59 * @param rd_count number of entries in @a rd array
@@ -57,8 +62,9 @@ extern "C"
57typedef void 62typedef void
58(*GNUNET_NAMESTORE_RecordIterator) (void *cls, 63(*GNUNET_NAMESTORE_RecordIterator) (void *cls,
59 uint64_t serial, 64 uint64_t serial,
65 const char *editor_hint,
60 const struct 66 const struct
61 GNUNET_IDENTITY_PrivateKey *private_key, 67 GNUNET_CRYPTO_PrivateKey *private_key,
62 const char *label, 68 const char *label,
63 unsigned int rd_count, 69 unsigned int rd_count,
64 const struct GNUNET_GNSRECORD_Data *rd); 70 const struct GNUNET_GNSRECORD_Data *rd);
@@ -85,12 +91,12 @@ struct GNUNET_NAMESTORE_PluginFunctions
85 * @param rd array of records with data to store 91 * @param rd array of records with data to store
86 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 92 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
87 */ 93 */
88 int 94 enum GNUNET_GenericReturnValue
89 (*store_records) (void *cls, 95 (*store_records)(void *cls,
90 const struct GNUNET_IDENTITY_PrivateKey *zone, 96 const struct GNUNET_CRYPTO_PrivateKey *zone,
91 const char *label, 97 const char *label,
92 unsigned int rd_count, 98 unsigned int rd_count,
93 const struct GNUNET_GNSRECORD_Data *rd); 99 const struct GNUNET_GNSRECORD_Data *rd);
94 100
95 /** 101 /**
96 * Lookup records in the datastore for which we are the authority. 102 * Lookup records in the datastore for which we are the authority.
@@ -102,12 +108,12 @@ struct GNUNET_NAMESTORE_PluginFunctions
102 * @param iter_cls closure for @a iter 108 * @param iter_cls closure for @a iter
103 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 109 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
104 */ 110 */
105 int 111 enum GNUNET_GenericReturnValue
106 (*lookup_records) (void *cls, 112 (*lookup_records)(void *cls,
107 const struct GNUNET_IDENTITY_PrivateKey *zone, 113 const struct GNUNET_CRYPTO_PrivateKey *zone,
108 const char *label, 114 const char *label,
109 GNUNET_NAMESTORE_RecordIterator iter, 115 GNUNET_NAMESTORE_RecordIterator iter,
110 void *iter_cls); 116 void *iter_cls);
111 117
112 118
113 /** 119 /**
@@ -124,13 +130,13 @@ struct GNUNET_NAMESTORE_PluginFunctions
124 * @param iter_cls closure for @a iter 130 * @param iter_cls closure for @a iter
125 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error 131 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
126 */ 132 */
127 int 133 enum GNUNET_GenericReturnValue
128 (*iterate_records) (void *cls, 134 (*iterate_records)(void *cls,
129 const struct GNUNET_IDENTITY_PrivateKey *zone, 135 const struct GNUNET_CRYPTO_PrivateKey *zone,
130 uint64_t serial, 136 uint64_t serial,
131 uint64_t limit, 137 uint64_t limit,
132 GNUNET_NAMESTORE_RecordIterator iter, 138 GNUNET_NAMESTORE_RecordIterator iter,
133 void *iter_cls); 139 void *iter_cls);
134 140
135 141
136 /** 142 /**
@@ -144,12 +150,77 @@ struct GNUNET_NAMESTORE_PluginFunctions
144 * @param iter_cls closure for @a iter 150 * @param iter_cls closure for @a iter
145 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 151 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
146 */ 152 */
147 int 153 enum GNUNET_GenericReturnValue
148 (*zone_to_name) (void *cls, 154 (*zone_to_name)(void *cls,
149 const struct GNUNET_IDENTITY_PrivateKey *zone, 155 const struct GNUNET_CRYPTO_PrivateKey *zone,
150 const struct GNUNET_IDENTITY_PublicKey *value_zone, 156 const struct GNUNET_CRYPTO_PublicKey *value_zone,
151 GNUNET_NAMESTORE_RecordIterator iter, 157 GNUNET_NAMESTORE_RecordIterator iter,
152 void *iter_cls); 158 void *iter_cls);
159
160 /** Transaction-based API draft **/
161
162 /**
163 * Edit records in the namestore.
164 * This modifies the editor hint, an advisory lock entry.
165 * The record iterator will be called with the old editor hint (if any).
166 *
167 * @param cls closure (internal context for the plugin)
168 * @param zone private key of the zone
169 * @param editor_hint the new value for the advisory lock field
170 * @param label name of the record in the zone
171 * @param iter function to call with the result
172 * @param iter_cls closure for @a iter
173 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
174 */
175 enum GNUNET_GenericReturnValue
176 (*edit_records)(void *cls,
177 const char *editor_hint,
178 const struct GNUNET_CRYPTO_PrivateKey *zone,
179 const char *label,
180 GNUNET_NAMESTORE_RecordIterator iter,
181 void *iter_cls);
182
183 /**
184 * This clears the editor hint, unless it does not match the
185 * given editor hint, in which case this is a NOP.
186 * If a replacement hint is given, it hint is not cleared, but
187 * set to the replacement.
188 *
189 * @param cls closure (internal context for the plugin)
190 * @param zone private key of the zone
191 * @param editor_hint the new value for the advisory lock field
192 * @param editor_hint_replacement an optional value to use instead of a clear
193 * @param label name of the record in the zone
194 * @param iter function to call with the result
195 * @param iter_cls closure for @a iter
196 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
197 */
198 enum GNUNET_GenericReturnValue
199 (*clear_editor_hint)(void *cls,
200 const char *editor_hint,
201 const char *editor_hint_replacement,
202 const struct GNUNET_CRYPTO_PrivateKey *zone,
203 const char *label);
204
205 /**
206 * Setup the database.
207 *
208 * @param cls closure (internal context for the plugin)
209 * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR
210 */
211 enum GNUNET_GenericReturnValue
212 (*create_tables)(void *cls);
213
214
215 /**
216 * Drop existing tables.
217 * DANGEROUS: All existing data in the dabase will be lost!
218 *
219 * @param cls closure (internal context for the plugin)
220 * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR
221 */
222 enum GNUNET_GenericReturnValue
223 (*drop_tables)(void *cls);
153}; 224};
154 225
155 226
@@ -163,3 +234,5 @@ struct GNUNET_NAMESTORE_PluginFunctions
163#endif 234#endif
164 235
165/** @} */ /* end of group */ 236/** @} */ /* end of group */
237
238/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 2482b97a5..0f9be8b10 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -38,10 +41,10 @@
38#ifndef GNUNET_NAMESTORE_SERVICE_H 41#ifndef GNUNET_NAMESTORE_SERVICE_H
39#define GNUNET_NAMESTORE_SERVICE_H 42#define GNUNET_NAMESTORE_SERVICE_H
40 43
44
45#include "gnunet_error_codes.h"
41#include "gnunet_util_lib.h" 46#include "gnunet_util_lib.h"
42#include "gnunet_block_lib.h"
43#include "gnunet_gnsrecord_lib.h" 47#include "gnunet_gnsrecord_lib.h"
44#include "gnunet_identity_service.h"
45 48
46#ifdef __cplusplus 49#ifdef __cplusplus
47extern "C" 50extern "C"
@@ -67,6 +70,28 @@ struct GNUNET_NAMESTORE_Handle;
67 */ 70 */
68struct GNUNET_NAMESTORE_ZoneIterator; 71struct GNUNET_NAMESTORE_ZoneIterator;
69 72
73/**
74 * Transaction control types.
75 * They roughly correspond to DB transaction controls
76 */
77enum GNUNET_NAMESTORE_TxControl
78{
79 GNUNET_NAMESTORE_TX_BEGIN = 0,
80 GNUNET_NAMESTORE_TX_COMMIT = 1,
81 GNUNET_NAMESTORE_TX_ROLLBACK = 2,
82};
83
84/**
85 * A struct for record bulk import.
86 * The fields are arrays pointing to individual GNS records and names.
87 */
88struct GNUNET_NAMESTORE_RecordInfo
89{
90 const char *a_label;
91 unsigned int a_rd_count;
92 struct GNUNET_GNSRECORD_Data *a_rd;
93};
94
70 95
71/** 96/**
72 * Connect to the namestore service. 97 * Connect to the namestore service.
@@ -97,12 +122,11 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
97 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) 122 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
98 * #GNUNET_NO if content was already there or not found 123 * #GNUNET_NO if content was already there or not found
99 * #GNUNET_YES (or other positive value) on success 124 * #GNUNET_YES (or other positive value) on success
100 * @param emsg NULL on success, otherwise an error message 125 * @param ec the #GNUNET_ErrorCode, #GNUNET_EC_NONE on success.
101 */ 126 */
102typedef void 127typedef void
103(*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, 128(*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
104 int32_t success, 129 enum GNUNET_ErrorCode ec);
105 const char *emsg);
106 130
107 131
108/** 132/**
@@ -116,6 +140,9 @@ typedef void
116 * keep up with the changes, calling @a cont will be delayed until the 140 * keep up with the changes, calling @a cont will be delayed until the
117 * monitors do keep up. 141 * monitors do keep up.
118 * 142 *
143 * This always overwrites the record set and unsets any advisory
144 * lock inrrespective of the currently set editor hint/advisory lock value.
145 *
119 * @param h handle to the namestore 146 * @param h handle to the namestore
120 * @param pkey private key of the zone 147 * @param pkey private key of the zone
121 * @param label name that is being mapped 148 * @param label name that is being mapped
@@ -126,13 +153,81 @@ typedef void
126 * @return handle to abort the request 153 * @return handle to abort the request
127 */ 154 */
128struct GNUNET_NAMESTORE_QueueEntry * 155struct GNUNET_NAMESTORE_QueueEntry *
129GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, 156GNUNET_NAMESTORE_record_set_store (struct GNUNET_NAMESTORE_Handle *h,
130 const struct GNUNET_IDENTITY_PrivateKey *pkey, 157 const struct GNUNET_CRYPTO_PrivateKey *pkey,
131 const char *label, 158 const char *label,
132 unsigned int rd_count, 159 unsigned int rd_count,
133 const struct GNUNET_GNSRECORD_Data *rd, 160 const struct GNUNET_GNSRECORD_Data *rd,
134 GNUNET_NAMESTORE_ContinuationWithStatus cont, 161 GNUNET_NAMESTORE_ContinuationWithStatus cont,
135 void *cont_cls); 162 void *cont_cls);
163
164/**
165 * Store one or more record sets in the namestore. If any item is already present,
166 * it is replaced with the new record. Use an empty array to
167 * remove all records under the given name.
168 *
169 * The continuation is called after the records have been stored in the
170 * database. They may not yet have been commited. Monitors may be notified
171 * asynchronously (basically with a buffer when commited).
172 * However, if any monitor is consistently too slow to
173 * keep up with the changes, calling @a cont will be delayed until the
174 * monitors do keep up.
175 * Uncommited store requests within a transaction (GNUNET_NAMESTORE_transaction_begin)
176 * cause @a cont to be called immediately before the commit and before
177 * notification of monitors.
178 *
179 * This always overwrites the record set and unsets any advisory
180 * lock inrrespective of the currently set editor hint/advisory lock value.
181 *
182 * @param h handle to the namestore
183 * @param pkey private key of the zone
184 * @param rd_set_count the number of record sets
185 * @param record_info the records to add containing @a rd_set_count records
186 * @param cont continuation to call when done
187 * @param rds_sent set to how many record sets could actually be sent
188 * @param cont_cls closure for @a cont
189 * @return handle to abort the request
190 */
191struct GNUNET_NAMESTORE_QueueEntry *
192GNUNET_NAMESTORE_records_store (
193 struct GNUNET_NAMESTORE_Handle *h,
194 const struct GNUNET_CRYPTO_PrivateKey *pkey,
195 unsigned int rd_set_count,
196 const struct GNUNET_NAMESTORE_RecordInfo *record_info,
197 unsigned int *rds_sent,
198 GNUNET_NAMESTORE_ContinuationWithStatus cont,
199 void *cont_cls);
200
201/**
202 * Store an item in the namestore. If the item is already present,
203 * it is replaced with the new record. Use an empty array to
204 * remove all records under the given name.
205 *
206 * The continuation is called after the value has been stored in the
207 * database. Monitors may be notified asynchronously (basically with
208 * a buffer). However, if any monitor is consistently too slow to
209 * keep up with the changes, calling @a cont will be delayed until the
210 * monitors do keep up.
211 *
212 * @param h handle to the namestore
213 * @param pkey private key of the zone
214 * @param label name that is being mapped
215 * @param rd_count number of records in the 'rd' array
216 * @param rd array of records with data to store
217 * @param is_zonemaster update tombstones, do not process monitors
218 * @param cont continuation to call when done
219 * @param cont_cls closure for @a cont
220 * @return handle to abort the request
221 */
222struct GNUNET_NAMESTORE_QueueEntry *
223GNUNET_NAMESTORE_record_set_store_ (struct GNUNET_NAMESTORE_Handle *h,
224 const struct GNUNET_CRYPTO_PrivateKey *pkey,
225 const char *label,
226 unsigned int rd_count,
227 const struct GNUNET_GNSRECORD_Data *rd,
228 int is_zonemaster,
229 GNUNET_NAMESTORE_ContinuationWithStatus cont,
230 void *cont_cls);
136 231
137 232
138/** 233/**
@@ -147,10 +242,48 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
147typedef void 242typedef void
148(*GNUNET_NAMESTORE_RecordMonitor) (void *cls, 243(*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
149 const struct 244 const struct
150 GNUNET_IDENTITY_PrivateKey *zone, 245 GNUNET_CRYPTO_PrivateKey *zone,
151 const char *label, 246 const char *label,
152 unsigned int rd_count, 247 unsigned int rd_count,
153 const struct GNUNET_GNSRECORD_Data *rd); 248 const struct GNUNET_GNSRECORD_Data *rd);
249/**
250 * Process a record that was stored in the namestore.
251 *
252 * @param cls closure
253 * @param ec the error code. #GNUNET_EC_NONE on success.
254 * @param rd_count number of entries in @a rd array, 0 if label was deleted
255 * @param rd array of records with data to store
256 * @param editor_hint the advisory lock value that was replaced. NULL of not advisory lock
257 was set or if lock was equal to provided editor hint.
258 */
259typedef void
260(*GNUNET_NAMESTORE_EditRecordSetBeginCallback) (void *cls,
261 enum GNUNET_ErrorCode ec,
262 unsigned int rd_count,
263 const struct
264 GNUNET_GNSRECORD_Data *rd,
265 const char *editor_hint);
266
267/**
268 * Process a record set that was stored in the namestore.
269 * The record set expiration value takes existing TOMBSTONE records
270 * into account even if those are not returned.
271 *
272 * @param cls closure
273 * @param zone private key of the zone
274 * @param label label of the records
275 * @param rd_count number of entries in @a rd array, 0 if label was deleted
276 * @param rd array of records with data to store
277 * @param expiry the expiration of this record set.
278 */
279typedef void
280(*GNUNET_NAMESTORE_RecordSetMonitor) (void *cls,
281 const struct
282 GNUNET_CRYPTO_PrivateKey *zone,
283 const char *label,
284 unsigned int rd_count,
285 const struct GNUNET_GNSRECORD_Data *rd,
286 struct GNUNET_TIME_Absolute expiry);
154 287
155 288
156/** 289/**
@@ -170,13 +303,39 @@ typedef void
170struct GNUNET_NAMESTORE_QueueEntry * 303struct GNUNET_NAMESTORE_QueueEntry *
171GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, 304GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
172 const struct 305 const struct
173 GNUNET_IDENTITY_PrivateKey *pkey, 306 GNUNET_CRYPTO_PrivateKey *pkey,
174 const char *label, 307 const char *label,
175 GNUNET_SCHEDULER_TaskCallback error_cb, 308 GNUNET_SCHEDULER_TaskCallback error_cb,
176 void *error_cb_cls, 309 void *error_cb_cls,
177 GNUNET_NAMESTORE_RecordMonitor rm, 310 GNUNET_NAMESTORE_RecordMonitor rm,
178 void *rm_cls); 311 void *rm_cls);
179 312
313/**
314 * Lookup an item in the namestore with GNSRECORD filter.
315 *
316 * @param h handle to the namestore
317 * @param pkey private key of the zone
318 * @param label name that is being mapped
319 * @param error_cb function to call on error (i.e. disconnect)
320 * the handle is afterwards invalid
321 * @param error_cb_cls closure for @a error_cb
322 * @param rm function to call with the result (with 0 records if we don't have that label);
323 * the handle is afterwards invalid
324 * @param rm_cls closure for @a rm
325 * @param filter the record set filter to use
326 * @return handle to abort the request
327 */
328struct GNUNET_NAMESTORE_QueueEntry *
329GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
330 const struct
331 GNUNET_CRYPTO_PrivateKey *pkey,
332 const char *label,
333 GNUNET_SCHEDULER_TaskCallback error_cb,
334 void *error_cb_cls,
335 GNUNET_NAMESTORE_RecordMonitor rm,
336 void *rm_cls,
337 enum GNUNET_GNSRECORD_Filter filter);
338
180 339
181/** 340/**
182 * Look for an existing PKEY delegation record for a given public key. 341 * Look for an existing PKEY delegation record for a given public key.
@@ -197,9 +356,9 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
197 */ 356 */
198struct GNUNET_NAMESTORE_QueueEntry * 357struct GNUNET_NAMESTORE_QueueEntry *
199GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 358GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
200 const struct GNUNET_IDENTITY_PrivateKey *zone, 359 const struct GNUNET_CRYPTO_PrivateKey *zone,
201 const struct 360 const struct
202 GNUNET_IDENTITY_PublicKey *value_zone, 361 GNUNET_CRYPTO_PublicKey *value_zone,
203 GNUNET_SCHEDULER_TaskCallback error_cb, 362 GNUNET_SCHEDULER_TaskCallback error_cb,
204 void *error_cb_cls, 363 void *error_cb_cls,
205 GNUNET_NAMESTORE_RecordMonitor proc, 364 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -219,6 +378,9 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
219 378
220 379
221/** 380/**
381 * @deprecated since 0.16.7 will be replaced in 0.18
382 * @see GNUNET_NAMESTORE_zone_iteration_start2()
383 *
222 * Starts a new zone iteration (used to periodically PUT all of our 384 * Starts a new zone iteration (used to periodically PUT all of our
223 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle` 385 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
224 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and 386 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
@@ -246,7 +408,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
246struct GNUNET_NAMESTORE_ZoneIterator * 408struct GNUNET_NAMESTORE_ZoneIterator *
247GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 409GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
248 const struct 410 const struct
249 GNUNET_IDENTITY_PrivateKey *zone, 411 GNUNET_CRYPTO_PrivateKey *zone,
250 GNUNET_SCHEDULER_TaskCallback error_cb, 412 GNUNET_SCHEDULER_TaskCallback error_cb,
251 void *error_cb_cls, 413 void *error_cb_cls,
252 GNUNET_NAMESTORE_RecordMonitor proc, 414 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -254,6 +416,44 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
254 GNUNET_SCHEDULER_TaskCallback finish_cb, 416 GNUNET_SCHEDULER_TaskCallback finish_cb,
255 void *finish_cb_cls); 417 void *finish_cb_cls);
256 418
419/**
420 * Starts a new zone iteration (used to periodically PUT all of our
421 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
422 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
423 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
424 * immediately, and then again after
425 * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
426 *
427 * On error (disconnect), @a error_cb will be invoked.
428 * On normal completion, @a finish_cb proc will be
429 * invoked.
430 *
431 * @param h handle to the namestore
432 * @param zone zone to access, NULL for all zones
433 * @param error_cb function to call on error (i.e. disconnect),
434 * the handle is afterwards invalid
435 * @param error_cb_cls closure for @a error_cb
436 * @param proc function to call on each name from the zone; it
437 * will be called repeatedly with a value (if available)
438 * @param proc_cls closure for @a proc
439 * @param finish_cb function to call on completion
440 * the handle is afterwards invalid
441 * @param finish_cb_cls closure for @a finish_cb
442 * @param filter the record set filter to use
443 * @return an iterator handle to use for iteration
444 */
445struct GNUNET_NAMESTORE_ZoneIterator *
446GNUNET_NAMESTORE_zone_iteration_start2 (struct GNUNET_NAMESTORE_Handle *h,
447 const struct
448 GNUNET_CRYPTO_PrivateKey *zone,
449 GNUNET_SCHEDULER_TaskCallback error_cb,
450 void *error_cb_cls,
451 GNUNET_NAMESTORE_RecordSetMonitor proc,
452 void *proc_cls,
453 GNUNET_SCHEDULER_TaskCallback finish_cb,
454 void *finish_cb_cls,
455 enum GNUNET_GNSRECORD_Filter filter);
456
257 457
258/** 458/**
259 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start 459 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
@@ -286,6 +486,9 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
286 486
287 487
288/** 488/**
489 * @deprecated since 0.16.7 will be replaced in 0.18
490 * @see GNUNET_NAMESTORE_zone_monitor_start2()
491 *
289 * Begin monitoring a zone for changes. Will first call the @a 492 * Begin monitoring a zone for changes. Will first call the @a
290 * monitor function on all existing records in the selected zone(s) if 493 * monitor function on all existing records in the selected zone(s) if
291 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a 494 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
@@ -315,7 +518,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
315struct GNUNET_NAMESTORE_ZoneMonitor * 518struct GNUNET_NAMESTORE_ZoneMonitor *
316GNUNET_NAMESTORE_zone_monitor_start ( 519GNUNET_NAMESTORE_zone_monitor_start (
317 const struct GNUNET_CONFIGURATION_Handle *cfg, 520 const struct GNUNET_CONFIGURATION_Handle *cfg,
318 const struct GNUNET_IDENTITY_PrivateKey *zone, 521 const struct GNUNET_CRYPTO_PrivateKey *zone,
319 int iterate_first, 522 int iterate_first,
320 GNUNET_SCHEDULER_TaskCallback error_cb, 523 GNUNET_SCHEDULER_TaskCallback error_cb,
321 void *error_cb_cls, 524 void *error_cb_cls,
@@ -324,6 +527,47 @@ GNUNET_NAMESTORE_zone_monitor_start (
324 GNUNET_SCHEDULER_TaskCallback sync_cb, 527 GNUNET_SCHEDULER_TaskCallback sync_cb,
325 void *sync_cb_cls); 528 void *sync_cb_cls);
326 529
530/**
531 * Begin monitoring a zone for changes. Will first call the @a
532 * monitor function on all existing records in the selected zone(s) if
533 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
534 * sync_cb, and then afterwards call the @a monitor whenever a record
535 * changes. If the namestore disconnects, the @a error_cb function is
536 * called with a disconnect event. Once the connection is
537 * re-established, the process begins from the start (depending on @a
538 * iterate_first, we will again first do all existing records, then @a
539 * sync, then updates).
540 *
541 * @param cfg configuration to use to connect to namestore
542 * @param zone zone to monitor, NULL for all zones
543 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
544 * #GNUNET_NO to only return changes that happen from now on
545 * @param error_cb function to call on error (i.e. disconnect); note that
546 * unlike the other error callbacks in this API, a call to this
547 * function does NOT destroy the monitor handle, it merely signals
548 * that monitoring is down. You need to still explicitly call
549 * #GNUNET_NAMESTORE_zone_monitor_stop().
550 * @param error_cb_cls closure for @a error_cb
551 * @param monitor function to call on zone changes, with an initial limit of 1
552 * @param monitor_cls closure for @a monitor
553 * @param sync_cb function called when we're in sync with the namestore
554 * @param sync_cb_cls closure for @a sync_cb
555 * @param filter the record set filter to use
556 * @return handle to stop monitoring
557 */
558struct GNUNET_NAMESTORE_ZoneMonitor *
559GNUNET_NAMESTORE_zone_monitor_start2 (
560 const struct GNUNET_CONFIGURATION_Handle *cfg,
561 const struct GNUNET_CRYPTO_PrivateKey *zone,
562 int iterate_first,
563 GNUNET_SCHEDULER_TaskCallback error_cb,
564 void *error_cb_cls,
565 GNUNET_NAMESTORE_RecordSetMonitor monitor,
566 void *monitor_cls,
567 GNUNET_SCHEDULER_TaskCallback sync_cb,
568 void *sync_cb_cls,
569 enum GNUNET_GNSRECORD_Filter filter);
570
327 571
328/** 572/**
329 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start 573 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start
@@ -360,6 +604,68 @@ void
360GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); 604GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
361 605
362 606
607/**
608 * New API draft. Experimental
609 */
610
611/**
612 * This function is used to initiate the editing
613 * of a record set under #label.
614 * It will set the editor hint of the record set to #editor_hint.
615 * The editor hint serves as an advisory lock that is used in
616 * #GNUNET_NAMESTORE_EdtirRecordSetBeginCallback if #editor_hint
617 * differs from the currently set advisory lock in the database.
618 *
619 * @param h handle to the namestore
620 * @param pkey the private key of the zone to edit
621 * @param label the label of the record set to edit
622 * @param editor_hint the editor hint to set as advisory lock
623 * @param error_cb the error callback
624 * @param error_cb_cls closure to #error_cb
625 * @param edit_cb the #GNUNET_NAMESTORE_EditRecordSetBeginCallback
626 * @param edit_cb_cls closure to #edit_cb
627 * @return handle to the operation
628 */
629struct GNUNET_NAMESTORE_QueueEntry *
630GNUNET_NAMESTORE_record_set_edit_begin (struct GNUNET_NAMESTORE_Handle *h,
631 const struct
632 GNUNET_CRYPTO_PrivateKey *pkey,
633 const char *label,
634 const char *editor_hint,
635 GNUNET_NAMESTORE_EditRecordSetBeginCallback
636 edit_cb,
637 void *edit_cb_cls);
638
639/**
640 * If the current advisory lock is set to the provided editor hint,
641 * this API cancels the editing of a record set and unsets the advisory lock in database.
642 * Optionally, a new editor hint can be provided: For example,
643 * the value that was returned in in the callback to
644 * #GNUNET_NAMESTORE_record_set_edit_begin.
645 *
646 * If provided editor hint does not match the current advisory lock,
647 * this function is not doing anything (NOP).
648 *
649 * @param h handle to the namestore
650 * @param pkey the private key of the zone to edit
651 * @param label the label of the record set to edit
652 * @param editor_hint the editor hint to set as advisory lock
653 * @param editor_hint_replacement the editor hint to set as advisory lock instead of clearing it
654 * @param finished_cb the callback called when cancelled
655 * @param finished_cb_cls closure to #finished_cb
656 * @return handle to the operation
657 */
658struct GNUNET_NAMESTORE_QueueEntry *
659GNUNET_NAMESTORE_record_set_edit_cancel (struct GNUNET_NAMESTORE_Handle *h,
660 const struct
661 GNUNET_CRYPTO_PrivateKey *pkey,
662 const char *label,
663 const char *editor_hint,
664 const char *editor_hint_replacement,
665 GNUNET_NAMESTORE_ContinuationWithStatus
666 finished_cb,
667 void *finished_cls);
668
363#if 0 /* keep Emacsens' auto-indent happy */ 669#if 0 /* keep Emacsens' auto-indent happy */
364{ 670{
365#endif 671#endif
@@ -370,3 +676,5 @@ GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
370#endif 676#endif
371 677
372/** @} */ /* end of group */ 678/** @} */ /* end of group */
679
680/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_nat_auto_service.h b/src/include/gnunet_nat_auto_service.h
index 78284dc01..1c511cac3 100644
--- a/src/include/gnunet_nat_auto_service.h
+++ b/src/include/gnunet_nat_auto_service.h
@@ -26,7 +26,7 @@
26 * Service for testing and autoconfiguration of 26 * Service for testing and autoconfiguration of
27 * NAT traversal functionality 27 * NAT traversal functionality
28 * 28 *
29 * @defgroup nat NAT testing library 29 * @defgroup nat NAT library
30 * 30 *
31 * @{ 31 * @{
32 */ 32 */
@@ -34,6 +34,7 @@
34#ifndef GNUNET_NAT_AUTO_SERVICE_H 34#ifndef GNUNET_NAT_AUTO_SERVICE_H
35#define GNUNET_NAT_AUTO_SERVICE_H 35#define GNUNET_NAT_AUTO_SERVICE_H
36 36
37
37#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
38#include "gnunet_nat_service.h" 39#include "gnunet_nat_service.h"
39 40
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index e39e2c016..ba9f252a0 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -36,6 +36,7 @@
36#ifndef GNUNET_NAT_SERVICE_H 36#ifndef GNUNET_NAT_SERVICE_H
37#define GNUNET_NAT_SERVICE_H 37#define GNUNET_NAT_SERVICE_H
38 38
39
39#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
40 41
41 42
@@ -344,6 +345,19 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
344 345
345 346
346/** 347/**
348 * Add global address to the list of addresses and notify clients.
349 *
350 * @param nh the handle returned by register
351 * @param addr IP address to add.
352 * @param address_length number of bytes in @a addr
353 */
354void
355GNUNET_NAT_add_global_address (struct GNUNET_NAT_Handle *nh,
356 char *addr,
357 unsigned int address_length);
358
359
360/**
347 * Test if the given address is (currently) a plausible IP address for 361 * Test if the given address is (currently) a plausible IP address for
348 * this peer. Mostly a convenience function so that clients do not 362 * this peer. Mostly a convenience function so that clients do not
349 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback 363 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback
@@ -385,6 +399,12 @@ GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh,
385 * handle. This frees the handle, after having sent the needed 399 * handle. This frees the handle, after having sent the needed
386 * commands to close open ports. 400 * commands to close open ports.
387 * 401 *
402 * FIXME: No, the implementation of this API does not do anything beyond
403 * cleaning up the handle.
404 * This is a problem for applications that use #GNUNET_NAT_AddressCallback
405 * and use the app_ctx to store objects, because the callback will never be
406 * called for cleanup on unregister.
407 *
388 * @param nh the handle to unregister 408 * @param nh the handle to unregister
389 */ 409 */
390void 410void
diff --git a/src/include/gnunet_nc_lib.h b/src/include/gnunet_nc_lib.h
index bd22fd6e2..8f4d9a16f 100644
--- a/src/include/gnunet_nc_lib.h
+++ b/src/include/gnunet_nc_lib.h
@@ -17,7 +17,17 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21
22#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
20/** 26/**
27 * @addtogroup libgnunetutil
28 * Multi-function utilities library for GNUnet programs
29 * @{
30 *
21 * @author Christian Grothoff 31 * @author Christian Grothoff
22 * 32 *
23 * @file 33 * @file
@@ -99,3 +109,7 @@ unsigned int
99GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc); 109GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc);
100 110
101#endif 111#endif
112
113/** @} */ /* end of group mq */
114
115/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index ff1e853f5..764b7b29d 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V. 3 Copyright (C) 2009-2013, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,7 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Nils Durner 29 * @author Nils Durner
30 * @author Tobias Frisch
23 * 31 *
24 * @file 32 * @file
25 * Basic low-level networking interface 33 * Basic low-level networking interface
@@ -31,6 +39,7 @@
31#ifndef GNUNET_NETWORK_LIB_H 39#ifndef GNUNET_NETWORK_LIB_H
32#define GNUNET_NETWORK_LIB_H 40#define GNUNET_NETWORK_LIB_H
33 41
42#include "gnunet_common.h"
34#ifdef __cplusplus 43#ifdef __cplusplus
35extern "C" 44extern "C"
36{ 45{
@@ -39,6 +48,14 @@ extern "C"
39#endif 48#endif
40#endif 49#endif
41 50
51//#ifdef HAVE_SYS_SELECT_H
52/*
53 * Include "sys/select.h" because it is required to use
54 * "fd_set" in "struct GNUNET_NETWORK_FDSet"!
55 */
56
57#include <sys/select.h>
58//#endif
42#ifdef HAVE_SYS_SOCKET_H 59#ifdef HAVE_SYS_SOCKET_H
43#include <sys/socket.h> 60#include <sys/socket.h>
44#endif 61#endif
@@ -141,7 +158,7 @@ GNUNET_NETWORK_socket_box_native (int fd);
141 * @param doBlock blocking mode 158 * @param doBlock blocking mode
142 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 159 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
143 */ 160 */
144int 161enum GNUNET_GenericReturnValue
145GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, 162GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
146 int doBlock); 163 int doBlock);
147 164
@@ -580,3 +597,7 @@ GNUNET_NETWORK_test_port_free (int ipproto,
580#endif /* GNUNET_NETWORK_LIB_H */ 597#endif /* GNUNET_NETWORK_LIB_H */
581 598
582/** @} */ /* end of group */ 599/** @} */ /* end of group */
600
601/** @} */ /* end of group addition */
602
603/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_nse_service.h b/src/include/gnunet_nse_service.h
index 0401e0cbc..fe9e1f853 100644
--- a/src/include/gnunet_nse_service.h
+++ b/src/include/gnunet_nse_service.h
@@ -22,6 +22,9 @@
22#define GNUNET_NSE_SERVICE_H_ 22#define GNUNET_NSE_SERVICE_H_
23 23
24/** 24/**
25 * @addtogroup Backbone
26 * @{
27 *
25 * @author Nathan Evans 28 * @author Nathan Evans
26 * 29 *
27 * @file 30 * @file
@@ -47,6 +50,7 @@ extern "C"
47#endif 50#endif
48#endif 51#endif
49 52
53
50#include "gnunet_util_lib.h" 54#include "gnunet_util_lib.h"
51 55
52/** 56/**
@@ -116,4 +120,6 @@ GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
116 120
117/** @} */ /* end of group nse */ 121/** @} */ /* end of group nse */
118 122
123/** @} */ /* end of group addition */
124
119#endif /* GNUNET_NSE_SERVICE_H_ */ 125#endif /* GNUNET_NSE_SERVICE_H_ */
diff --git a/src/include/gnunet_nt_lib.h b/src/include/gnunet_nt_lib.h
index 18419a7b8..014b4fbe0 100644
--- a/src/include/gnunet_nt_lib.h
+++ b/src/include/gnunet_nt_lib.h
@@ -17,12 +17,20 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
20/** 25/**
26 * @addtogroup Backbone
27 * @{
28 *
21 * @file network type characterization 29 * @file network type characterization
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Matthias Wachs 31 * @author Matthias Wachs
24 * 32 *
25 * @defgroup nt network type characterization 33 * @defgroup nt Network type characterization
26 * 34 *
27 * @{ 35 * @{
28 */ 36 */
@@ -122,3 +130,5 @@ GNUNET_NT_scanner_done (struct GNUNET_NT_InterfaceScanner *is);
122#endif 130#endif
123 131
124/** @} */ /* end of group */ 132/** @} */ /* end of group */
133
134/** @} */ /* end of group addition to backbone */
diff --git a/src/include/gnunet_op_lib.h b/src/include/gnunet_op_lib.h
index 77fa7f955..e028fb7fb 100644
--- a/src/include/gnunet_op_lib.h
+++ b/src/include/gnunet_op_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @file 30 * @file
23 * Asynchronous operations; register callbacks for operations and call them when a response arrives. 31 * Asynchronous operations; register callbacks for operations and call them when a response arrives.
24 * 32 *
@@ -28,6 +36,7 @@
28#ifndef GNUNET_OP_H 36#ifndef GNUNET_OP_H
29#define GNUNET_OP_H 37#define GNUNET_OP_H
30 38
39
31#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
32 41
33/** 42/**
@@ -153,3 +162,5 @@ GNUNET_OP_remove (struct GNUNET_OP_Handle *h,
153 162
154 163
155#endif // GNUNET_OP_H 164#endif // GNUNET_OP_H
165
166/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index eddf97dab..c1e193720 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Krista Bennett 31 * @author Krista Bennett
24 * @author Gerd Knorr <kraxel@bytesex.org> 32 * @author Gerd Knorr <kraxel@bytesex.org>
@@ -56,10 +64,6 @@ extern "C"
56#endif 64#endif
57#endif 65#endif
58 66
59#include "gnunet_common.h"
60#include "gnunet_configuration_lib.h"
61#include "gnunet_scheduler_lib.h"
62
63 67
64/** 68/**
65 * Flags that determine which of the standard streams 69 * Flags that determine which of the standard streams
@@ -379,14 +383,14 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
379 * @param addrlen length of the address 383 * @param addrlen length of the address
380 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 384 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
381 */ 385 */
382typedef int 386typedef enum GNUNET_GenericReturnValue
383(*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, 387(*GNUNET_OS_NetworkInterfaceProcessor)(void *cls,
384 const char *name, 388 const char *name,
385 int isDefault, 389 int isDefault,
386 const struct sockaddr *addr, 390 const struct sockaddr *addr,
387 const struct sockaddr *broadcast_addr, 391 const struct sockaddr *broadcast_addr,
388 const struct sockaddr *netmask, 392 const struct sockaddr *netmask,
389 socklen_t addrlen); 393 socklen_t addrlen);
390 394
391 395
392/** 396/**
@@ -608,7 +612,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
608 * @param code return code/signal number 612 * @param code return code/signal number
609 * @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
610 */ 614 */
611int 615enum GNUNET_GenericReturnValue
612GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, 616GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
613 enum GNUNET_OS_ProcessStatusType *type, 617 enum GNUNET_OS_ProcessStatusType *type,
614 unsigned long *code); 618 unsigned long *code);
@@ -624,7 +628,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
624 * @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
625 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 629 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
626 */ 630 */
627int 631enum GNUNET_GenericReturnValue
628GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); 632GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
629 633
630 634
@@ -637,7 +641,7 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
637 * @param code return code/signal number 641 * @param code return code/signal number
638 * @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
639 */ 643 */
640int 644enum GNUNET_GenericReturnValue
641GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, 645GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
642 enum GNUNET_OS_ProcessStatusType *type, 646 enum GNUNET_OS_ProcessStatusType *type,
643 unsigned long *code); 647 unsigned long *code);
@@ -690,4 +694,6 @@ GNUNET_OS_check_helper_binary (const char *binary,
690 694
691/** @} */ /* end of group */ 695/** @} */ /* end of group */
692 696
697/** @} */ /* end of group addition */
698
693/* end of gnunet_os_lib.h */ 699/* end of gnunet_os_lib.h */
diff --git a/src/include/gnunet_peer_lib.h b/src/include/gnunet_peer_lib.h
index f94b883f8..4a67878b9 100644
--- a/src/include/gnunet_peer_lib.h
+++ b/src/include/gnunet_peer_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -32,6 +40,7 @@
32#ifndef GNUNET_PEER_LIB_H 40#ifndef GNUNET_PEER_LIB_H
33#define GNUNET_PEER_LIB_H 41#define GNUNET_PEER_LIB_H
34 42
43
35#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
36 45
37#ifdef __cplusplus 46#ifdef __cplusplus
@@ -126,4 +135,6 @@ GNUNET_PEER_resolve2 (GNUNET_PEER_Id id);
126 135
127/** @} */ /* end of group */ 136/** @} */ /* end of group */
128 137
138/** @} */ /* end of group addition */
139
129/* end of gnunet_peer_lib.h */ 140/* end of gnunet_peer_lib.h */
diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h
deleted file mode 100644
index cdea1a95f..000000000
--- a/src/include/gnunet_peerinfo_service.h
+++ /dev/null
@@ -1,210 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009, 2010 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Maintain the list of currently known hosts
25 *
26 * @defgroup peerinfo Peer Info service
27 * Maintain the list of currently known hosts.
28 *
29 * Holds an in-memory structure of data/hosts.
30 *
31 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
32 *
33 * @{
34 */
35
36#ifndef GNUNET_PEERINFO_SERVICE_H
37#define GNUNET_PEERINFO_SERVICE_H
38
39#include "gnunet_common.h"
40#include "gnunet_configuration_lib.h"
41#include "gnunet_crypto_lib.h"
42#include "gnunet_hello_lib.h"
43
44#ifdef __cplusplus
45extern "C"
46{
47#if 0 /* keep Emacsens' auto-indent happy */
48}
49#endif
50#endif
51
52
53/**
54 * Handle to the peerinfo service.
55 */
56struct GNUNET_PEERINFO_Handle;
57
58
59/**
60 * Connect to the peerinfo service.
61 *
62 * @param cfg configuration to use
63 * @return NULL on error (configuration related, actual connection
64 * etablishment may happen asynchronously).
65 */
66struct GNUNET_PEERINFO_Handle *
67GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
68
69
70/**
71 * Disconnect from the peerinfo service. Note that all iterators must
72 * have completed or have been cancelled by the time this function is
73 * called (otherwise, calling this function is a serious error).
74 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
75 * pending, they will be cancelled silently on disconnect.
76 *
77 * @param h handle to disconnect
78 */
79void
80GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
81
82
83/**
84 * Add a host to the persistent list. This method operates in
85 * semi-reliable mode: if the transmission is not completed by
86 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
87 * aborted. Furthermore, if a second HELLO is added for the
88 * same peer before the first one was transmitted, PEERINFO may
89 * merge the two HELLOs prior to transmission to the service.
90 *
91 * @param h handle to the peerinfo service
92 * @param hello the verified (!) HELLO message
93 * @param cont continuation to call when done, NULL is allowed
94 * @param cont_cls closure for @a cont
95 * @return handle to cancel add operation; all pending
96 * 'add' operations will be cancelled automatically
97 * on disconnect, so it is not necessary to keep this
98 * handle (unless @a cont is non-NULL and at some point
99 * calling @a cont must be prevented)
100 */
101struct GNUNET_MQ_Envelope *
102GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
103 const struct GNUNET_HELLO_Message *hello,
104 GNUNET_SCHEDULER_TaskCallback cont,
105 void *cont_cls);
106
107
108/**
109 * Type of an iterator over the hosts. Note that each
110 * host will be called with each available protocol.
111 *
112 * @param cls closure
113 * @param peer id of the peer, NULL for last call
114 * @param hello hello message for the peer (can be NULL)
115 * @param error message
116 */
117typedef void
118(*GNUNET_PEERINFO_Processor) (void *cls,
119 const struct GNUNET_PeerIdentity *peer,
120 const struct GNUNET_HELLO_Message *hello,
121 const char *err_msg);
122
123
124/**
125 * Handle for cancellation of iteration over peers.
126 */
127struct GNUNET_PEERINFO_IteratorContext;
128
129
130/**
131 * Call a method for each known matching host. The callback method
132 * will be invoked once for each matching host and then finally once
133 * with a NULL pointer. After that final invocation, the iterator
134 * context must no longer be used.
135 *
136 * Instead of calling this function with `peer == NULL` it is often
137 * better to use #GNUNET_PEERINFO_notify().
138 *
139 * @param h handle to the peerinfo service
140 * @param include_friend_only include HELLO messages for friends only
141 * @param peer restrict iteration to this peer only (can be NULL)
142 * @param timeout how long to wait until timing out
143 * @param callback the method to call for each peer
144 * @param callback_cls closure for @a callback
145 * @return iterator context
146 */
147struct GNUNET_PEERINFO_IteratorContext *
148GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
149 int include_friend_only,
150 const struct GNUNET_PeerIdentity *peer,
151 GNUNET_PEERINFO_Processor callback,
152 void *callback_cls);
153
154
155/**
156 * Cancel an iteration over peer information.
157 *
158 * @param ic context of the iterator to cancel
159 */
160void
161GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
162
163
164/**
165 * Handle for notifications about changes to the set of known peers.
166 */
167struct GNUNET_PEERINFO_NotifyContext;
168
169
170/**
171 * Call a method whenever our known information about peers
172 * changes. Initially calls the given function for all known
173 * peers and then only signals changes.
174 *
175 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
176 * messages which are intended for friend to friend mode and which do not
177 * have to be gossiped. Otherwise these messages are skipped.
178 *
179 * @param cfg configuration to use
180 * @param include_friend_only include HELLO messages for friends only
181 * @param callback the method to call for each peer
182 * @param callback_cls closure for @a callback
183 * @return NULL on error
184 */
185struct GNUNET_PEERINFO_NotifyContext *
186GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
187 int include_friend_only,
188 GNUNET_PEERINFO_Processor callback,
189 void *callback_cls);
190
191
192/**
193 * Stop notifying about changes.
194 *
195 * @param nc context to stop notifying
196 */
197void
198GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
199
200
201#if 0 /* keep Emacsens' auto-indent happy */
202{
203#endif
204#ifdef __cplusplus
205}
206#endif
207
208#endif
209
210/** @} */ /* end of group */
diff --git a/src/include/gnunet_peerstore_plugin.h b/src/include/gnunet_peerstore_plugin.h
index 90190e5b5..6ecb9135a 100644
--- a/src/include/gnunet_peerstore_plugin.h
+++ b/src/include/gnunet_peerstore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Omar Tarabai 25 * @author Omar Tarabai
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_PEERSTORE_PLUGIN_H 34#ifndef GNUNET_PEERSTORE_PLUGIN_H
32#define GNUNET_PEERSTORE_PLUGIN_H 35#define GNUNET_PEERSTORE_PLUGIN_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_peerstore_service.h" 39#include "gnunet_peerstore_service.h"
36 40
@@ -42,6 +46,19 @@ extern "C"
42#endif 46#endif
43#endif 47#endif
44 48
49/**
50 * Function called by PEERSTORE for each matching record.
51 *
52 * @param cls closure
53 * @param seq sequence in interation
54 * @param record peerstore record information
55 * @param emsg error message, or NULL if no errors
56 */
57typedef void (*GNUNET_PEERSTORE_PluginProcessor) (
58 void *cls,
59 uint64_t seq,
60 const struct GNUNET_PEERSTORE_Record *record,
61 const char *emsg);
45 62
46/** 63/**
47 * @brief struct returned by the initialization function of the plugin 64 * @brief struct returned by the initialization function of the plugin
@@ -89,6 +106,7 @@ struct GNUNET_PEERSTORE_PluginFunctions
89 * @param sub_system name of sub system 106 * @param sub_system name of sub system
90 * @param peer Peer identity (can be NULL) 107 * @param peer Peer identity (can be NULL)
91 * @param key entry key string (can be NULL) 108 * @param key entry key string (can be NULL)
109 * @param limit max number of results to give
92 * @param iter function to call asynchronously with the results, terminated 110 * @param iter function to call asynchronously with the results, terminated
93 * by a NULL result 111 * by a NULL result
94 * @param iter_cls closure for @a iter 112 * @param iter_cls closure for @a iter
@@ -100,7 +118,9 @@ struct GNUNET_PEERSTORE_PluginFunctions
100 const char *sub_system, 118 const char *sub_system,
101 const struct GNUNET_PeerIdentity *peer, 119 const struct GNUNET_PeerIdentity *peer,
102 const char *key, 120 const char *key,
103 GNUNET_PEERSTORE_Processor iter, 121 uint64_t serial,
122 uint64_t limit,
123 GNUNET_PEERSTORE_PluginProcessor iter,
104 void *iter_cls); 124 void *iter_cls);
105 125
106 /** 126 /**
@@ -131,3 +151,5 @@ struct GNUNET_PEERSTORE_PluginFunctions
131#endif 151#endif
132 152
133/** @} */ /* end of group */ 153/** @} */ /* end of group */
154
155/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 91a8f2e66..3fb9df82a 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Omar Tarabai 25 * @author Omar Tarabai
23 * 26 *
24 * @file 27 * @file
@@ -33,6 +36,7 @@
33#ifndef GNUNET_PEERSTORE_SERVICE_H 36#ifndef GNUNET_PEERSTORE_SERVICE_H
34#define GNUNET_PEERSTORE_SERVICE_H 37#define GNUNET_PEERSTORE_SERVICE_H
35 38
39
36#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
37 41
38#ifdef __cplusplus 42#ifdef __cplusplus
@@ -42,6 +46,10 @@ extern "C" {
42#endif 46#endif
43#endif 47#endif
44 48
49/**
50 * Key used for storing HELLO in the peerstore
51 */
52#define GNUNET_PEERSTORE_HELLO_KEY "peerstore-peer-hello-uri"
45 53
46/** 54/**
47 * Key used for storing addresses in URL format in the peerstore 55 * Key used for storing addresses in URL format in the peerstore
@@ -58,32 +66,32 @@ extern "C" {
58 * messages. 66 * messages.
59 */ 67 */
60#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \ 68#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \
61 "transport-backchannel-monotonic-time" 69 "transport-backchannel-monotonic-time"
62 70
63/** 71/**
64 * Key used to store sender's monotonic time from DV learn 72 * Key used to store sender's monotonic time from DV learn
65 * messages. 73 * messages.
66 */ 74 */
67#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \ 75#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \
68 "transport-dv-learn-monotonic-time" 76 "transport-dv-learn-monotonic-time"
69 77
70/** 78/**
71 * Key used to store sender's monotonic time from handshake message. 79 * Key used to store sender's monotonic time from handshake message.
72 */ 80 */
73#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \ 81#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \
74 "transport-tcp-communicator-handshake" 82 "transport-tcp-communicator-handshake"
75 83
76/** 84/**
77 * Key used to store sender's monotonic time from handshake ack message. 85 * Key used to store sender's monotonic time from handshake ack message.
78 */ 86 */
79#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \ 87#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \
80 "transport-tcp-communicator-handshake-ack" 88 "transport-tcp-communicator-handshake-ack"
81 89
82/** 90/**
83 * Key used to store sender's monotonic time from rekey message. 91 * Key used to store sender's monotonic time from rekey message.
84 */ 92 */
85#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \ 93#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \
86 "transport-tcp-communicator-rekey" 94 "transport-tcp-communicator-rekey"
87 95
88 96
89/** 97/**
@@ -100,7 +108,8 @@ enum GNUNET_PEERSTORE_StoreOption
100 * Delete any previous values for the given key before 108 * Delete any previous values for the given key before
101 * storing the given value. 109 * storing the given value.
102 */ 110 */
103 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1 111 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1,
112
104}; 113};
105 114
106/** 115/**
@@ -114,6 +123,11 @@ struct GNUNET_PEERSTORE_Handle;
114struct GNUNET_PEERSTORE_StoreContext; 123struct GNUNET_PEERSTORE_StoreContext;
115 124
116/** 125/**
126 * Context for the info handler.
127 */
128struct GNUNET_PEERSTORE_NotifyContext;
129
130/**
117 * Single PEERSTORE record 131 * Single PEERSTORE record
118 */ 132 */
119struct GNUNET_PEERSTORE_Record 133struct GNUNET_PEERSTORE_Record
@@ -148,11 +162,6 @@ struct GNUNET_PEERSTORE_Record
148 */ 162 */
149 struct GNUNET_TIME_Absolute expiry; 163 struct GNUNET_TIME_Absolute expiry;
150 164
151 /**
152 * Client from which this record originated.
153 * NOTE: This is internal to the service.
154 */
155 struct GNUNET_SERVICE_Client *client;
156}; 165};
157 166
158 167
@@ -166,9 +175,16 @@ typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success);
166 175
167 176
168/** 177/**
178 * Context for a add hello uri request.
179 */
180struct GNUNET_PEERSTORE_StoreHelloContext;
181
182
183/**
169 * Function called by PEERSTORE for each matching record. 184 * Function called by PEERSTORE for each matching record.
170 * 185 *
171 * @param cls closure 186 * @param cls closure
187 * @param seq sequence in interation
172 * @param record peerstore record information 188 * @param record peerstore record information
173 * @param emsg error message, or NULL if no errors 189 * @param emsg error message, or NULL if no errors
174 */ 190 */
@@ -177,6 +193,43 @@ typedef void (*GNUNET_PEERSTORE_Processor) (
177 const struct GNUNET_PEERSTORE_Record *record, 193 const struct GNUNET_PEERSTORE_Record *record,
178 const char *emsg); 194 const char *emsg);
179 195
196/**
197 * Function called by PEERSTORE when notifying a client about a changed hello.
198 *
199 * @param cls closure
200 * @param hello_uri Hello uri.
201 */
202typedef void (*GNUNET_PEERSTORE_hello_notify_cb) (
203 void *cls,
204 const struct GNUNET_PeerIdentity *peer,
205 const struct GNUNET_MessageHeader *hello,
206 const char *err_msg);
207
208/**
209 * Add hello to peerstore.
210 *
211 * @param h handle for peerstore.
212 * @param msg The hello to add.
213 * @param cont The continuation function to execute after storing.
214 * @param cont_cls The continuation function closure.
215 * @return The context for storing.
216 */
217struct GNUNET_PEERSTORE_StoreHelloContext *
218GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h,
219 const struct GNUNET_MessageHeader *msg,
220 GNUNET_PEERSTORE_Continuation cont,
221 void *cont_cls);
222
223
224/**
225 * Cancel the request to add a hello.
226 *
227 * @param huc The context for storing a hello.
228 */
229void
230GNUNET_PEERSTORE_hello_add_cancel (struct
231 GNUNET_PEERSTORE_StoreHelloContext *huc);
232
180 233
181/** 234/**
182 * Connect to the PEERSTORE service. 235 * Connect to the PEERSTORE service.
@@ -188,15 +241,13 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
188 241
189 242
190/** 243/**
191 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests 244 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH and
192 * will be canceled. 245 * STORE requests will be canceled.
193 * Any pending STORE requests will depend on @e snyc_first flag.
194 * 246 *
195 * @param h handle to disconnect 247 * @param h handle to disconnect
196 * @param sync_first send any pending STORE requests before disconnecting
197 */ 248 */
198void 249void
199GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first); 250GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h);
200 251
201 252
202/** 253/**
@@ -238,63 +289,130 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
238 289
239 290
240/** 291/**
241 * Iterate over records matching supplied key information 292 * Iterate over peerstore entries.
293 * The iteration can be filtered to contain only records
294 * matching @a peer and/or @a key.
295 * The @a sub_system to match must be provided.
296 * @a callback will be called with (each) matching record.
297 * #GNUNET_PEERSTORE_iteration_next() must be invoked
298 * to continue processing until the end of the iteration is
299 * reached.
242 * 300 *
243 * @param h handle to the PEERSTORE service 301 * @param h handle to the PEERSTORE service
244 * @param sub_system name of sub system 302 * @param sub_system name of sub system
245 * @param peer Peer identity (can be NULL) 303 * @param peer Peer identity (can be NULL)
246 * @param key entry key string (can be NULL) 304 * @param key entry key string (can be NULL)
247 * @param callback function called with each matching record, all NULL's on end 305 * @param callback function called with each matching record. The record will be NULL to indicate end.
248 * @param callback_cls closure for @a callback 306 * @param callback_cls closure for @a callback
307 * @return Handle to iteration request
249 */ 308 */
250struct GNUNET_PEERSTORE_IterateContext * 309struct GNUNET_PEERSTORE_IterateContext *
251GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, 310GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h,
252 const char *sub_system, 311 const char *sub_system,
253 const struct GNUNET_PeerIdentity *peer, 312 const struct GNUNET_PeerIdentity *peer,
254 const char *key, 313 const char *key,
255 GNUNET_PEERSTORE_Processor callback, 314 GNUNET_PEERSTORE_Processor callback,
256 void *callback_cls); 315 void *callback_cls);
257 316
258 317
259/** 318/**
260 * Cancel an iterate request 319 * Continue an iteration.
261 * Please do not call after the iterate request is done 320 * Do NOT call after the iterate request is done.
262 * 321 *
263 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() 322 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
323 * @param limit how many records to return max until #GNUNET_PEERSTORE_iterate_next() needs to be called again.
264 */ 324 */
265void 325void
266GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic); 326GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic,
327 uint64_t limit);
267 328
268 329
269/** 330/**
331 * Cancel an iteration.
332 * Do NOT call after the iterate request is done
333 *
334 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
335 */
336void
337GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic);
338
339/**
270 * Request watching a given key 340 * Request watching a given key
271 * User will be notified with any new values added to key. 341 * The monitoring can be filtered to contain only records
342 * matching @a peer and/or @a key.
343 * The @a sub_system to match must be provided.
344 * @a callback will be called with (each) matching new record.
345 * #GNUNET_PEERSTORE_monitor_next() must be invoked
346 * to continue processing until @a sync_cb is
347 * called, indicating that the caller should be up-to-date.
348 * The caller will be notified with any new values added to key
349 * through @a callback.
350 * If @a iterate_first is set to GNUNET_YES, the monitor will first
351 * iterate over all existing, matching records. In any case,
352 * after @a sync_cb is called the first time monitoring starts.
272 * 353 *
273 * @param h handle to the PEERSTORE service 354 * @param h handle to the PEERSTORE service
355 * @param iterate_first first iterated of all results if GNUNET_YES
274 * @param sub_system name of sub system 356 * @param sub_system name of sub system
275 * @param peer Peer identity 357 * @param peer Peer identity
276 * @param key entry key string 358 * @param key entry key string
359 * @param error_cb function to call on error (i.e. disconnect); note that
360 * unlike the other error callbacks in this API, a call to this
361 * function does NOT destroy the monitor handle, it merely signals
362 * that monitoring is down. You need to still explicitly call
363 * #GNUNET_PEERSTORE_monitor_stop().
364 * @param error_cb_cls closure for @a error_cb
365 * @param sync_cb function called when we're in sync with the peerstore
366 * @param sync_cb_cls closure for @a sync_cb
277 * @param callback function called with each new value 367 * @param callback function called with each new value
278 * @param callback_cls closure for @a callback 368 * @param callback_cls closure for @a callback
279 * @return Handle to watch request 369 * @return Handle to watch request
280 */ 370 */
281struct GNUNET_PEERSTORE_WatchContext * 371struct GNUNET_PEERSTORE_Monitor *
282GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, 372GNUNET_PEERSTORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
283 const char *sub_system, 373 int iterate_first,
284 const struct GNUNET_PeerIdentity *peer, 374 const char *sub_system,
285 const char *key, 375 const struct GNUNET_PeerIdentity *peer,
286 GNUNET_PEERSTORE_Processor callback, 376 const char *key,
287 void *callback_cls); 377 GNUNET_SCHEDULER_TaskCallback error_cb,
288 378 void *error_cb_cls,
379 GNUNET_SCHEDULER_TaskCallback sync_cb,
380 void *sync_cb_cls,
381 GNUNET_PEERSTORE_Processor callback,
382 void *callback_cls);
289 383
290/** 384/**
291 * Cancel a watch request 385 * Calls the monitor processor specified in #GNUNET_PEERSTORE_monitor_start
386 * for the next record(s). This function is used to allow clients that merely
387 * monitor the NAMESTORE to still throttle namestore operations, so we can be
388 * sure that the monitors can keep up.
389 *
390 * Note that #GNUNET_PEERSTORE_store() only waits for this
391 * call if the previous limit set by the client was already reached.
392 * Thus, by using a @a limit greater than 1, monitors basically enable
393 * a queue of notifications to be processed asynchronously with some
394 * delay. Note that even with a limit of 1 the
395 * #GNUNET_PEERSTORE_store() function will run asynchronously
396 * and the continuation may be invoked before the monitors completed
397 * (or even started) processing the notification. Thus, monitors will
398 * only closely track the current state of the peerstore, but not
399 * be involved in the transactions.
292 * 400 *
293 * @param wc handle to the watch request 401 * @param zm the monitor
402 * @param limit number of records to return to the iterator in one shot
403 * (before #GNUNET_PEERSTORE_monitor_next is to be called again)
294 */ 404 */
295void 405void
296GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc); 406GNUNET_PEERSTORE_monitor_next (struct GNUNET_PEERSTORE_Monitor *zm,
407 uint64_t limit);
297 408
409/**
410 * Stop monitoring.
411 *
412 * @param zm handle to the monitor activity to stop
413 */
414void
415GNUNET_PEERSTORE_monitor_stop (struct GNUNET_PEERSTORE_Monitor *zm);
298 416
299#if 0 /* keep Emacsens' auto-indent happy */ 417#if 0 /* keep Emacsens' auto-indent happy */
300{ 418{
@@ -306,3 +424,5 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
306#endif 424#endif
307 425
308/** @} */ /* end of group */ 426/** @} */ /* end of group */
427
428/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h
index d265eb343..2a9cde47f 100644
--- a/src/include/gnunet_plugin_lib.h
+++ b/src/include/gnunet_plugin_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -40,9 +48,6 @@ extern "C"
40#endif 48#endif
41#endif 49#endif
42 50
43#include "gnunet_common.h"
44#include "gnunet_configuration_lib.h"
45
46 51
47/** 52/**
48 * Signature of any function exported by a plugin. 53 * Signature of any function exported by a plugin.
@@ -65,7 +70,7 @@ typedef void *
65 * @param library_name name of the plugin to test if it is installed 70 * @param library_name name of the plugin to test if it is installed
66 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not 71 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
67 */ 72 */
68int 73enum GNUNET_GenericReturnValue
69GNUNET_PLUGIN_test (const char *library_name); 74GNUNET_PLUGIN_test (const char *library_name);
70 75
71 76
@@ -169,4 +174,6 @@ GNUNET_PLUGIN_unload (const char *library_name,
169 174
170/** @} */ /* end of group */ 175/** @} */ /* end of group */
171 176
177/** @} */ /* end of group addition */
178
172/* end of gnunet_plugin_lib.h */ 179/* end of gnunet_plugin_lib.h */
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 6a374f7e2..7501bee12 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2016, 2017, 2020, 2021 GNUnet e.V. 3 Copyright (C) 2016, 2017, 2020-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -25,9 +25,19 @@
25#ifndef GNUNET_PQ_LIB_H 25#ifndef GNUNET_PQ_LIB_H
26#define GNUNET_PQ_LIB_H 26#define GNUNET_PQ_LIB_H
27 27
28
28#include <libpq-fe.h> 29#include <libpq-fe.h>
30#include <stdint.h>
31#include "gnunet_common.h"
32#include "gnunet_time_lib.h"
29#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
30#include "gnunet_db_lib.h" 34#include "gnunet_db_lib.h"
35#include "postgres_ext.h"
36
37/**
38 * Postgres context.
39 */
40struct GNUNET_PQ_Context;
31 41
32/* ************************* pq_query_helper.c functions ************************ */ 42/* ************************* pq_query_helper.c functions ************************ */
33 43
@@ -57,6 +67,14 @@ typedef int
57 void *scratch[], 67 void *scratch[],
58 unsigned int scratch_length); 68 unsigned int scratch_length);
59 69
70/**
71 * Function called to cleanup the closure of SQL parameters converter. Will be
72 * called with GNUNET_PQ_query_params_cleanup
73 *
74 * @param cls closure
75 */
76typedef void
77(*GNUNET_PQ_QueryConverter_Cleanup)(void *cls);
60 78
61/** 79/**
62 * @brief Description of a DB query parameter. 80 * @brief Description of a DB query parameter.
@@ -70,10 +88,20 @@ struct GNUNET_PQ_QueryParam
70 88
71 /** 89 /**
72 * Closure for @e conv. 90 * Closure for @e conv.
91 * The function @conv_cls_cleanup can be set to cleanup the closure.
92 * The cleanup of the closure MUST be triggered manually by a call to
93 * GNUNET_PQ_query_params_cleanup.
73 */ 94 */
74 void *conv_cls; 95 void *conv_cls;
75 96
76 /** 97 /**
98 * Function to cleanup the closure @a conv_cls, may be NULL.
99 * The cleanup of the closure MUST be triggered manually by a call to
100 * GNUNET_PQ_query_params_cleanup.
101 */
102 GNUNET_PQ_QueryConverter_Cleanup conv_cls_cleanup;
103
104 /**
77 * Data or NULL. 105 * Data or NULL.
78 */ 106 */
79 const void *data; 107 const void *data;
@@ -90,13 +118,26 @@ struct GNUNET_PQ_QueryParam
90 118
91}; 119};
92 120
121/**
122 * Must be called to cleanup memory from closures after the query parameters
123 * have been used as much as needed.
124 *
125 * @param params Array of GNUNET_PQ_QueryParam which must terminate with a GNUNET_PQ_query_param_end
126 */
127void
128GNUNET_PQ_cleanup_query_params_closures (
129 const struct GNUNET_PQ_QueryParam *params);
93 130
94/** 131/**
95 * End of query parameter specification. 132 * End of query parameter specification.
96 */ 133 */
97#define GNUNET_PQ_query_param_end \ 134#define GNUNET_PQ_query_param_end \
98 { \ 135 { \
99 NULL, NULL, NULL, 0, 0 \ 136 .conv = NULL, \
137 .conv_cls = NULL, \
138 .data = NULL, \
139 .size = 0, \
140 .num_params = 0 \
100 } 141 }
101 142
102 143
@@ -114,7 +155,7 @@ GNUNET_PQ_query_param_null (void);
114 * @a ptr_size bytes. 155 * @a ptr_size bytes.
115 * 156 *
116 * @param ptr pointer to the query parameter to pass 157 * @param ptr pointer to the query parameter to pass
117 * @oaran ptr_size number of bytes in @a ptr 158 * @param ptr_size number of bytes in @a ptr
118 * @return query parameter to use 159 * @return query parameter to use
119 */ 160 */
120struct GNUNET_PQ_QueryParam 161struct GNUNET_PQ_QueryParam
@@ -133,6 +174,220 @@ GNUNET_PQ_query_param_string (const char *ptr);
133 174
134 175
135/** 176/**
177 * Pass a boolean into a query.
178 *
179 * @param b boolean bit to pass
180 * @return query parameter to use
181 */
182struct GNUNET_PQ_QueryParam
183GNUNET_PQ_query_param_bool (bool b);
184
185/**
186 * Returns the oid for a given datatype by name.
187 *
188 * @param db The db-connection
189 * @param name The name of the datatype
190 * @param[out] oid The OID of the datatype.
191 * @return GNUNET_OK when the datatype was found, GNUNET_SYSERR otherwise
192 */
193enum GNUNET_GenericReturnValue
194GNUNET_PQ_get_oid_by_name (
195 struct GNUNET_PQ_Context *db,
196 const char *name,
197 Oid *oid);
198
199
200/**
201 * The header for a postgresql array in binary format. note that this a
202 * simplified special case of the general structure (which contains pointers),
203 * as we only support one-dimensional arrays.
204 *
205 * Note that all values must be in network-byte-order.
206 */
207struct GNUNET_PQ_ArrayHeader_P
208{
209 uint32_t ndim; /* number of dimensions. we only support ndim = 1 */
210 uint32_t has_null;
211 uint32_t oid; /* oid of the elements */
212 uint32_t dim; /* size of the array */
213 uint32_t lbound; /* index value of first element in the db (default: 1). */
214} __attribute__((packed));
215
216
217/**
218 * Generate query parameter for an array of bool in host byte order.
219 *
220 * @param num Number of elements in @a elements
221 * @param elements Continuous array of @a num boolean elements
222 * @param db Database context, needed for database-depending encoding of @a elements
223 * @return query parameter to use
224 */
225struct GNUNET_PQ_QueryParam
226GNUNET_PQ_query_param_array_bool (
227 unsigned int num,
228 const bool *elements,
229 struct GNUNET_PQ_Context *db);
230
231/**
232 * Generate query parameter for an array of uint16_t in host byte order.
233 * Note that the (unsigend) elements are not checked to wrap over INT2_MAX
234 *
235 * @param num Number of elements in @a elements
236 * @param elements Continuous array of @a num uint16 elements
237 * @param db Database context, needed for database-depending encoding of @a elements
238 * @return query parameter to use
239 */
240struct GNUNET_PQ_QueryParam
241GNUNET_PQ_query_param_array_uint16 (
242 unsigned int num,
243 const uint16_t *elements,
244 struct GNUNET_PQ_Context *db);
245
246/**
247 * Generate query parameter for an array of uint32_t in host byte order.
248 * Note that the (unsigend) elements are not checked to wrap over INT4_MAX
249 *
250 * @param num Number of elements in @a elements
251 * @param elements Continuous Array of @a num uint32_t elements
252 * @param db Database context, needed for database-depending encoding of @a elements
253 * @return query parameter to use
254 */
255struct GNUNET_PQ_QueryParam
256GNUNET_PQ_query_param_array_uint32 (
257 unsigned int num,
258 const uint32_t *elements,
259 struct GNUNET_PQ_Context *db);
260
261/**
262 * Generate query parameter for an array of uint64 in host byte order.
263 * Note that the (unsigend) elements are not checked to wrap over INT8_MAX
264 *
265 * @param num Number of elements in @a elements
266 * @param elements Continuous array of @a num uint64_t elements
267 * @param db Database context, needed for database-depending encoding of @a elements
268 * @return query parameter to use
269 */
270struct GNUNET_PQ_QueryParam
271GNUNET_PQ_query_param_array_uint64 (
272 unsigned int num,
273 const uint64_t *elements,
274 struct GNUNET_PQ_Context *db);
275
276/**
277 * Generate query parameter for an array of buffers @a elements, each of
278 * corresponding size given in @a sizes.
279 *
280 * @param num Number of elements in @a elements
281 * @param elements Continous array of @a num buffers, each of corresponding size given in @a sizes.
282 * @param sizes Pointer to sizes in bytes of each element in @a elements
283 * @param db Database context, needed for database-depending encoding of @a elements
284 * @return query parameter to use
285 */
286struct GNUNET_PQ_QueryParam
287GNUNET_PQ_query_param_array_bytes (
288 unsigned int num,
289 const void *elements,
290 const size_t *sizes,
291 struct GNUNET_PQ_Context *db);
292
293/**
294 * Generate query parameter for an array of buffers @a elements,
295 * each of the same size @a size.
296 *
297 * @param num Number of elements in @a elements
298 * @param elements Continous array of @a num buffers, each with the same size @a same_size
299 * @param same_size Size in bytes of each element in @a elements
300 * @param db Database context, needed for database-depending encoding of @a elements
301 * @return query parameter to use
302 */
303struct GNUNET_PQ_QueryParam
304GNUNET_PQ_query_param_array_bytes_same_size (
305 unsigned int num,
306 const void *elements,
307 size_t same_size,
308 struct GNUNET_PQ_Context *db);
309
310/**
311 * Generate array of equal-sized query parameter with size determined
312 * by variable type from a pointer to an continuous array.
313 *
314 * @param num Number of elements in @a elements
315 * @param elements Continuous array of the query parameter to pass.
316 * @param db Database context, needed for database-depending encoding of @a elements
317 * @return query parameter to use
318 */
319#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
320 GNUNET_PQ_query_param_array_bytes_same_size ((num), \
321 (elements), \
322 sizeof(*(elements)), \
323 (db))
324
325/**
326 * Generate query parameter for an array of pointers to buffers @a elements,
327 * each of the same size @a size.
328 *
329 * @param num Number of elements in @a elements
330 * @param elements Array of @a num pointers to buffers, each with the same size @a same_size
331 * @param same_size Size in bytes of each element in @a elements
332 * @param db Database context, needed for database-depending encoding of @a elements
333 * @return query parameter to use
334 */
335struct GNUNET_PQ_QueryParam
336GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
337 unsigned int num,
338 const void *elements[static num],
339 size_t same_size,
340 struct GNUNET_PQ_Context *db);
341
342
343/**
344 * Generate array of equal-sized query parameter with size determined by
345 * variable type from a pointer to an array of pointers to objects of the same
346 * type.
347 *
348 * @param num Number of elements in @a elements
349 * @param elements Continuous array of the query parameter to pass.
350 * @param db Database context, needed for database-depending encoding of @a elements
351 * @return query parameter to use
352 */
353#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
354 GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
355 (const void **) (elements), \
356 sizeof(*(elements[0])), \
357 (db))
358
359
360/**
361 * Generate query parameter for an array of strings (continuous)
362 *
363 * @param num Number of elements in @a elements
364 * @param elements Array of @a num continuous strings (zero-terminated each)
365 * @param db Database context, needed for database-depending encoding of @a elements
366 * @return query parameter to use
367 */
368struct GNUNET_PQ_QueryParam
369GNUNET_PQ_query_param_array_string (
370 unsigned int num,
371 const char *elements,
372 struct GNUNET_PQ_Context *db);
373
374
375/**
376 * Generate query parameter for an array of strings (pointers)
377 *
378 * @param num Number of elements in @a elements
379 * @param elements Array of @a num pointer to strings
380 * @param db Database context, needed for database-depending encoding of @a elements
381 * @return query parameter to use
382 */
383struct GNUNET_PQ_QueryParam
384GNUNET_PQ_query_param_array_ptrs_string (
385 unsigned int num,
386 const char *elements[static num],
387 struct GNUNET_PQ_Context *db);
388
389
390/**
136 * Generate fixed-size query parameter with size determined 391 * Generate fixed-size query parameter with size determined
137 * by variable type. 392 * by variable type.
138 * 393 *
@@ -142,6 +397,83 @@ GNUNET_PQ_query_param_string (const char *ptr);
142#define GNUNET_PQ_query_param_auto_from_type(x) \ 397#define GNUNET_PQ_query_param_auto_from_type(x) \
143 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) 398 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
144 399
400/**
401 * Generate query parameter for an array of absolute time stamps (continuous)
402 *
403 * @param num Number of elements in @a elements
404 * @param elements Array of @a num absolute timestamps
405 * @return query parameter to use
406 */
407struct GNUNET_PQ_QueryParam
408GNUNET_PQ_query_param_array_abs_time (
409 unsigned int num,
410 const struct GNUNET_TIME_Absolute *elements,
411 struct GNUNET_PQ_Context *db);
412
413/**
414 * Generate query parameter for an array of absolute time stamps (pointers)
415 *
416 * @param num Number of elements in @a elements
417 * @param elements Array of @a num pointers to absolute timestamps
418 * @return query parameter to use
419 */
420struct GNUNET_PQ_QueryParam
421GNUNET_PQ_query_param_array_ptrs_abs_time (
422 unsigned int num,
423 const struct GNUNET_TIME_Absolute *elements[],
424 struct GNUNET_PQ_Context *db);
425
426/**
427 * Generate query parameter for an array of relative time stamps (continuous)
428 *
429 * @param num Number of elements in @a elements
430 * @param elements Array of @a num relative timestamps
431 * @return query parameter to use
432 */
433struct GNUNET_PQ_QueryParam
434GNUNET_PQ_query_param_array_rel_time (
435 unsigned int num,
436 const struct GNUNET_TIME_Relative *elements,
437 struct GNUNET_PQ_Context *db);
438
439/**
440 * Generate query parameter for an array of relative time stamps (pointers)
441 *
442 * @param num Number of elements in @a elements
443 * @param elements Array of @a num pointers to relative timestamps
444 * @return query parameter to use
445 */
446struct GNUNET_PQ_QueryParam
447GNUNET_PQ_query_param_array_ptrs_rel_time (
448 unsigned int num,
449 const struct GNUNET_TIME_Relative *elements[],
450 struct GNUNET_PQ_Context *db);
451
452/**
453 * Generate query parameter for an array of time stamps (continuous)
454 *
455 * @param num Number of elements in @a elements
456 * @param elements Array of @a num timestamps
457 * @return query parameter to use
458 */
459struct GNUNET_PQ_QueryParam
460GNUNET_PQ_query_param_array_timestamp (
461 unsigned int num,
462 const struct GNUNET_TIME_Timestamp *elements,
463 struct GNUNET_PQ_Context *db);
464
465/**
466 * Generate query parameter for an array of time stamps (pointers)
467 *
468 * @param num Number of elements in @a elements
469 * @param elements Array of @a num pointers to relative timestamps
470 * @return query parameter to use
471 */
472struct GNUNET_PQ_QueryParam
473GNUNET_PQ_query_param_array_ptrs_timestamp (
474 unsigned int num,
475 const struct GNUNET_TIME_Timestamp *elements[],
476 struct GNUNET_PQ_Context *db);
145 477
146/** 478/**
147 * Generate query parameter for an RSA public key. The 479 * Generate query parameter for an RSA public key. The
@@ -190,6 +522,17 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
190 522
191 523
192/** 524/**
525 * Generate query parameter for a timestamp.
526 * The database must store a 64-bit integer.
527 *
528 * @param x pointer to the query parameter to pass
529 * @return query parameter to use
530 */
531struct GNUNET_PQ_QueryParam
532GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x);
533
534
535/**
193 * Generate query parameter for an absolute time value. 536 * Generate query parameter for an absolute time value.
194 * The database must store a 64-bit integer. 537 * The database must store a 64-bit integer.
195 * 538 *
@@ -202,6 +545,18 @@ GNUNET_PQ_query_param_absolute_time_nbo (
202 545
203 546
204/** 547/**
548 * Generate query parameter for a timestamp in NBO.
549 * The database must store a 64-bit integer.
550 *
551 * @param x pointer to the query parameter to pass
552 * @return query parameter to use
553 */
554struct GNUNET_PQ_QueryParam
555GNUNET_PQ_query_param_timestamp_nbo (
556 const struct GNUNET_TIME_TimestampNBO *x);
557
558
559/**
205 * Generate query parameter for an uint16_t in host byte order. 560 * Generate query parameter for an uint16_t in host byte order.
206 * 561 *
207 * @param x pointer to the query parameter to pass 562 * @param x pointer to the query parameter to pass
@@ -222,7 +577,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x);
222 577
223 578
224/** 579/**
225 * Generate query parameter for an uint16_t in host byte order. 580 * Generate query parameter for an uint64_t in host byte order.
226 * 581 *
227 * @param x pointer to the query parameter to pass 582 * @param x pointer to the query parameter to pass
228 * @return query parameter to use 583 * @return query parameter to use
@@ -231,6 +586,37 @@ struct GNUNET_PQ_QueryParam
231GNUNET_PQ_query_param_uint64 (const uint64_t *x); 586GNUNET_PQ_query_param_uint64 (const uint64_t *x);
232 587
233 588
589/**
590 * Generate query parameter for an int64_t in host byte order.
591 *
592 * @param x pointer to the query parameter to pass
593 * @return query parameter to use
594 */
595struct GNUNET_PQ_QueryParam
596GNUNET_PQ_query_param_int64 (const int64_t *x);
597
598/**
599 * Generate query parameter for a blind sign public key.
600 * Internally, the various attributes of the public key
601 * will be serialized into on variable-size BLOB.
602 *
603 * @param pub pointer to the query parameter to pass
604 *
605 */
606struct GNUNET_PQ_QueryParam
607GNUNET_PQ_query_param_blind_sign_pub (
608 const struct GNUNET_CRYPTO_BlindSignPublicKey *pub);
609
610/**
611 * Generate query parameter for a blind sign private key of variable size.
612 *
613 * @param priv pointer to the query parameter to pass
614 *
615 */
616struct GNUNET_PQ_QueryParam
617GNUNET_PQ_query_param_blind_sign_priv (
618 const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv);
619
234/* ************************* pq_result_helper.c functions ************************ */ 620/* ************************* pq_result_helper.c functions ************************ */
235 621
236 622
@@ -280,8 +666,7 @@ struct GNUNET_PQ_ResultSpec
280 GNUNET_PQ_ResultConverter conv; 666 GNUNET_PQ_ResultConverter conv;
281 667
282 /** 668 /**
283 * Function to clean up result data, NULL if cleanup is 669 * Function to clean up result data, NULL if cleanup is not necessary.
284 * not necessary.
285 */ 670 */
286 GNUNET_PQ_ResultCleanup cleaner; 671 GNUNET_PQ_ResultCleanup cleaner;
287 672
@@ -296,9 +681,9 @@ struct GNUNET_PQ_ResultSpec
296 void *dst; 681 void *dst;
297 682
298 /** 683 /**
299 * 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
300 * (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
301 * and we need to allocate a buffer of the right size). 686 * size).
302 */ 687 */
303 size_t dst_size; 688 size_t dst_size;
304 689
@@ -318,10 +703,8 @@ struct GNUNET_PQ_ResultSpec
318 bool is_nullable; 703 bool is_nullable;
319 704
320 /** 705 /**
321 * Points to a location where we should store 706 * Points to a location where we should store "true" if the result found is
322 * "true" if the result found is NULL, and 707 * NULL, and otherwise "false". Only used if @e is_nullable is true.
323 * otherwise "false". Only used if @e is_nullable
324 * is true.
325 */ 708 */
326 bool *is_null; 709 bool *is_null;
327 710
@@ -348,8 +731,7 @@ struct GNUNET_PQ_ResultSpec
348 731
349 732
350/** 733/**
351 * Allow NULL value to be found in the database 734 * Allow NULL value to be found in the database for the given value.
352 * for the given value.
353 * 735 *
354 * @param rs result spec entry to modify 736 * @param rs result spec entry to modify
355 * @param[out] is_null location set to 'true' if the 737 * @param[out] is_null location set to 'true' if the
@@ -414,6 +796,18 @@ GNUNET_PQ_result_spec_string (const char *name,
414 796
415 797
416/** 798/**
799 * boolean expected.
800 *
801 * @param name name of the field in the table
802 * @param[out] dst where to store the result
803 * @return array entry for the result specification to use
804 */
805struct GNUNET_PQ_ResultSpec
806GNUNET_PQ_result_spec_bool (const char *name,
807 bool *dst);
808
809
810/**
417 * RSA public key expected. 811 * RSA public key expected.
418 * 812 *
419 * @param name name of the field in the table 813 * @param name name of the field in the table
@@ -450,6 +844,18 @@ GNUNET_PQ_result_spec_absolute_time (const char *name,
450 844
451 845
452/** 846/**
847 * Timestamp expected.
848 *
849 * @param name name of the field in the table
850 * @param[out] t where to store the result
851 * @return array entry for the result specification to use
852 */
853struct GNUNET_PQ_ResultSpec
854GNUNET_PQ_result_spec_timestamp (const char *name,
855 struct GNUNET_TIME_Timestamp *t);
856
857
858/**
453 * Relative time expected. 859 * Relative time expected.
454 * 860 *
455 * @param name name of the field in the table 861 * @param name name of the field in the table
@@ -474,6 +880,18 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
474 880
475 881
476/** 882/**
883 * Timestamp expected.
884 *
885 * @param name name of the field in the table
886 * @param[out] tn where to store the result
887 * @return array entry for the result specification to use
888 */
889struct GNUNET_PQ_ResultSpec
890GNUNET_PQ_result_spec_timestamp_nbo (const char *name,
891 struct GNUNET_TIME_TimestampNBO *tn);
892
893
894/**
477 * uint16_t expected. 895 * uint16_t expected.
478 * 896 *
479 * @param name name of the field in the table 897 * @param name name of the field in the table
@@ -509,13 +927,231 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
509 uint64_t *u64); 927 uint64_t *u64);
510 928
511 929
512/* ************************* 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
513 941
514/** 942/**
515 * 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
516 */ 950 */
517struct GNUNET_PQ_Context; 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
1047 */
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);
1073
1074
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);
518 1153
1154/* ************************* pq.c functions ************************ */
519 1155
520/** 1156/**
521 * Execute a prepared statement. 1157 * Execute a prepared statement.
@@ -681,11 +1317,6 @@ struct GNUNET_PQ_PreparedStatement
681 */ 1317 */
682 const char *sql; 1318 const char *sql;
683 1319
684 /**
685 * Number of arguments included in @e sql.
686 */
687 unsigned int num_arguments;
688
689}; 1320};
690 1321
691 1322
@@ -694,7 +1325,7 @@ struct GNUNET_PQ_PreparedStatement
694 */ 1325 */
695#define GNUNET_PQ_PREPARED_STATEMENT_END \ 1326#define GNUNET_PQ_PREPARED_STATEMENT_END \
696 { \ 1327 { \
697 NULL, NULL, 0 \ 1328 NULL, NULL \
698 } 1329 }
699 1330
700 1331
@@ -703,13 +1334,11 @@ struct GNUNET_PQ_PreparedStatement
703 * 1334 *
704 * @param name name of the statement 1335 * @param name name of the statement
705 * @param sql actual SQL statement 1336 * @param sql actual SQL statement
706 * @param num_args number of arguments in the statement
707 * @return initialized struct 1337 * @return initialized struct
708 */ 1338 */
709struct GNUNET_PQ_PreparedStatement 1339struct GNUNET_PQ_PreparedStatement
710GNUNET_PQ_make_prepare (const char *name, 1340GNUNET_PQ_make_prepare (const char *name,
711 const char *sql, 1341 const char *sql);
712 unsigned int num_args);
713 1342
714 1343
715/** 1344/**
@@ -726,6 +1355,22 @@ GNUNET_PQ_prepare_statements (struct GNUNET_PQ_Context *db,
726 const struct GNUNET_PQ_PreparedStatement *ps); 1355 const struct GNUNET_PQ_PreparedStatement *ps);
727 1356
728 1357
1358/**
1359 * Request creation of prepared statements @a ps from Postgres, but do not
1360 * automatically re-prepare the statement if we are disconnected from the
1361 * database.
1362 *
1363 * @param db database to prepare the statements for
1364 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
1365 * statements.
1366 * @return #GNUNET_OK on success,
1367 * #GNUNET_SYSERR on error
1368 */
1369enum GNUNET_GenericReturnValue
1370GNUNET_PQ_prepare_once (struct GNUNET_PQ_Context *db,
1371 const struct GNUNET_PQ_PreparedStatement *ps);
1372
1373
729/* ******************** pq_exec.c functions ************** */ 1374/* ******************** pq_exec.c functions ************** */
730 1375
731 1376
@@ -780,7 +1425,7 @@ GNUNET_PQ_make_try_execute (const char *sql);
780/** 1425/**
781 * Request execution of an array of statements @a es from Postgres. 1426 * Request execution of an array of statements @a es from Postgres.
782 * 1427 *
783 * @param pq database to execute the statements in 1428 * @param db database to execute the statements in
784 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared 1429 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
785 * statements. 1430 * statements.
786 * @return #GNUNET_OK on success (modulo statements where errors can be ignored) 1431 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
@@ -822,14 +1467,14 @@ enum GNUNET_PQ_Options
822 * configuration. Initialize logging via GNUnet's log routines and disable 1467 * configuration. Initialize logging via GNUnet's log routines and disable
823 * Postgres's logger. Also ensures that the statements in @a load_path and @a 1468 * Postgres's logger. Also ensures that the statements in @a load_path and @a
824 * es are executed whenever we (re)connect to the database, and that the 1469 * es are executed whenever we (re)connect to the database, and that the
825 * prepared statements in @a ps are "ready". If statements in @es fail that 1470 * prepared statements in @a ps are "ready". If statements in @a es fail that
826 * were created with #GNUNET_PQ_make_execute(), then the entire operation 1471 * were created with #GNUNET_PQ_make_execute(), then the entire operation
827 * fails. 1472 * fails.
828 * 1473 *
829 * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX 1474 * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
830 * must be a sequence of contiguous integer values starting at 0000. 1475 * must be a sequence of contiguous integer values starting at 0000.
831 * These files are then loaded in sequence using "psql $config_str" before 1476 * These files are then loaded in sequence using "psql $config_str" before
832 * running statements from @e es. The directory is inspected again on 1477 * running statements from @a es. The directory is inspected again on
833 * reconnect. 1478 * reconnect.
834 * 1479 *
835 * @param config_str configuration to use 1480 * @param config_str configuration to use
@@ -847,11 +1492,26 @@ GNUNET_PQ_connect (const char *config_str,
847 1492
848 1493
849/** 1494/**
1495 * Execute SQL statements from @a buf against @a db.
1496 * The given filename infix in @a buf is prefixed with
1497 * the "load_path" and ".sql" is appended to construct
1498 * the full filename.
1499 *
1500 * @param db database context to use
1501 * @param buf filename infix (!) with the SQL code to run
1502 * @return #GNUNET_OK on success, #GNUNET_NO if patch @a buf does not exist, #GNUNET_SYSERR on error
1503 */
1504enum GNUNET_GenericReturnValue
1505GNUNET_PQ_exec_sql (struct GNUNET_PQ_Context *db,
1506 const char *buf);
1507
1508
1509/**
850 * Create a connection to the Postgres database using @a config_str for the 1510 * Create a connection to the Postgres database using @a config_str for the
851 * configuration. Initialize logging via GNUnet's log routines and disable 1511 * configuration. Initialize logging via GNUnet's log routines and disable
852 * Postgres's logger. Also ensures that the statements in @a load_path and @a 1512 * Postgres's logger. Also ensures that the statements in @a load_path and @a
853 * es are executed whenever we (re)connect to the database, and that the 1513 * es are executed whenever we (re)connect to the database, and that the
854 * prepared statements in @a ps are "ready". If statements in @es fail that 1514 * prepared statements in @a ps are "ready". If statements in @a es fail that
855 * were created with #GNUNET_PQ_make_execute(), then the entire operation 1515 * were created with #GNUNET_PQ_make_execute(), then the entire operation
856 * fails. 1516 * fails.
857 * 1517 *
@@ -863,6 +1523,7 @@ GNUNET_PQ_connect (const char *config_str,
863 * 1523 *
864 * @param config_str configuration to use 1524 * @param config_str configuration to use
865 * @param load_path path to directory with SQL transactions to run, can be NULL 1525 * @param load_path path to directory with SQL transactions to run, can be NULL
1526 * @param auto_suffix infix of SQL series to run on every reconnect; runs multiple (!) files, of the form auto_suffix-XXXX where XXXX is from 0 to 9999 (consequtive).
866 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated 1527 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
867 * array of statements to execute upon EACH connection, can be NULL 1528 * array of statements to execute upon EACH connection, can be NULL
868 * @param ps array of prepared statements to prepare, can be NULL 1529 * @param ps array of prepared statements to prepare, can be NULL
@@ -872,16 +1533,17 @@ GNUNET_PQ_connect (const char *config_str,
872struct GNUNET_PQ_Context * 1533struct GNUNET_PQ_Context *
873GNUNET_PQ_connect2 (const char *config_str, 1534GNUNET_PQ_connect2 (const char *config_str,
874 const char *load_path, 1535 const char *load_path,
1536 const char *auto_suffix,
875 const struct GNUNET_PQ_ExecuteStatement *es, 1537 const struct GNUNET_PQ_ExecuteStatement *es,
876 const struct GNUNET_PQ_PreparedStatement *ps, 1538 const struct GNUNET_PQ_PreparedStatement *ps,
877 enum GNUNET_PQ_Options flags); 1539 enum GNUNET_PQ_Options flags);
878 1540
879 1541
880/** 1542/**
881 * Connect to a postgres database using the configuration 1543 * Connect to a postgres database using the configuration option "CONFIG" in
882 * option "CONFIG" in @a section. Also ensures that the 1544 * @a section. Also ensures that the statements in @a es are executed
883 * statements in @a es are executed whenever we (re)connect to the 1545 * whenever we (re)connect to the database, and that the prepared statements
884 * database, and that the prepared statements in @a ps are "ready". 1546 * in @a ps are "ready".
885 * 1547 *
886 * 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
887 * 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.
@@ -909,7 +1571,8 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
909 * database, and that the prepared statements in @a ps are "ready". 1571 * database, and that the prepared statements in @a ps are "ready".
910 * 1572 *
911 * 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
912 * 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.
913 * 1576 *
914 * @param cfg configuration 1577 * @param cfg configuration
915 * @param section configuration section to use to get Postgres configuration options 1578 * @param section configuration section to use to get Postgres configuration options
@@ -988,12 +1651,24 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);
988 1651
989 1652
990/** 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/**
991 * Notify all that listen on @a es of an event. 1667 * Notify all that listen on @a es of an event.
992 * 1668 *
993 * Unlike many other calls, this function is thread-safe 1669 * Unlike many other calls, this function is thread-safe and may be called
994 * and may be called from threads that are different 1670 * from threads that are different from the one that setup @a db. However, the
995 * from the one that setup @a db. However, the @a cb 1671 * @a cb will always be called from the thread that runs
996 * will always be called from the thread that runs
997 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler. 1672 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
998 * 1673 *
999 * @param db database context to use 1674 * @param db database context to use
@@ -1009,6 +1684,17 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
1009 1684
1010 1685
1011/** 1686/**
1687 * Compute the channel that one should notify upon for the given event
1688 * specification.
1689 *
1690 * @param es event specification
1691 * @return channel to notify upon
1692 */
1693char *
1694GNUNET_PQ_get_event_notify_channel (const struct GNUNET_DB_EventHeaderP *es);
1695
1696
1697/**
1012 * Within the @a db context, run all the SQL files 1698 * Within the @a db context, run all the SQL files
1013 * from the @a load_path from 0000-9999.sql (as long 1699 * from the @a load_path from 0000-9999.sql (as long
1014 * as the files exist contiguously). 1700 * as the files exist contiguously).
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h
index 4167060c0..f06d95422 100644
--- a/src/include/gnunet_program_lib.h
+++ b/src/include/gnunet_program_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -40,6 +48,7 @@ extern "C"
40#endif 48#endif
41#endif 49#endif
42 50
51
43#include "gnunet_configuration_lib.h" 52#include "gnunet_configuration_lib.h"
44#include "gnunet_getopt_lib.h" 53#include "gnunet_getopt_lib.h"
45#include "gnunet_scheduler_lib.h" 54#include "gnunet_scheduler_lib.h"
@@ -113,6 +122,45 @@ GNUNET_PROGRAM_run (int argc,
113 GNUNET_PROGRAM_Main task, 122 GNUNET_PROGRAM_Main task,
114 void *task_cls); 123 void *task_cls);
115 124
125enum GNUNET_GenericReturnValue
126GNUNET_DAEMON_register (const char *daemon_name,
127 const char *daemon_desc,
128 GNUNET_PROGRAM_Main task);
129
130#ifndef HAVE_GNUNET_MONOLITH
131#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb) \
132 int \
133 main (int argc, \
134 char *const *argv) \
135 { \
136 int ret; \
137 struct GNUNET_GETOPT_CommandLineOption options[] = { \
138 GNUNET_GETOPT_OPTION_END \
139 }; \
140 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, \
141 &argv)) \
142 return 2; \
143 ret = GNUNET_PROGRAM_run (argc, \
144 argv, \
145 daemon_name, \
146 daemon_help, \
147 options, \
148 init_cb, \
149 NULL); \
150 GNUNET_free_nz ((void*) argv); \
151 return ret; \
152 }
153#else
154#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb) \
155 static int __attribute__ ((constructor)) \
156 init (void) \
157 { \
158 return GNUNET_DAEMON_register (daemon_name, \
159 daemon_help, \
160 init_cb); \
161 }
162#endif
163
116 164
117#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
118{ 166{
@@ -126,4 +174,6 @@ GNUNET_PROGRAM_run (int argc,
126 174
127/** @} */ /* end of group program */ 175/** @} */ /* end of group program */
128 176
177/** @} */ /* end of group addition */
178
129/* end of gnunet_program_lib.h */ 179/* end of gnunet_program_lib.h */
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 9e278eb92..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
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * @author Tobias Frisch 27 * @author Tobias Frisch
24 * 28 *
@@ -153,10 +157,10 @@ extern "C" {
153 ******************************************************************************/ 157 ******************************************************************************/
154 158
155/** 159/**
156 * Previously used for HELLO messages used for communicating peer addresses. 160 * Latest HELLO messages used for communicating peer addresses.
157 * Managed by libgnunethello. 161 * Managed by libgnunethello.
158 */ 162 */
159#define GNUNET_MESSAGE_TYPE_HELLO_LEGACY 16 163#define GNUNET_MESSAGE_TYPE_HELLO_URI 16
160 164
161/** 165/**
162 * HELLO message with friend only flag used for communicating peer addresses. 166 * HELLO message with friend only flag used for communicating peer addresses.
@@ -660,13 +664,26 @@ extern "C" {
660#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 664#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156
661 665
662/** 666/**
663 * DHT wants to use CORE to transmit data. 667 * HELLO advertising a neighbours addresses.
664 */ 668 */
665#define GNUNET_MESSAGE_TYPE_DHT_CORE 143 669#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO 157
666 670
667/** 671/**
668 * Further X-VINE DHT messages continued from 880 672 * Encapsulation of DHT messages in CORE service.
669 */ 673 */
674#define GNUNET_MESSAGE_TYPE_DHT_CORE 158
675
676/**
677 * HELLO URL send between client and service (in
678 * either direction).
679 */
680#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL 159
681
682/**
683 * Client requests DHT service's HELLO URL.
684 */
685#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET 161
686
670 687
671/******************************************************************************* 688/*******************************************************************************
672 * HOSTLIST message types 689 * HOSTLIST message types
@@ -1310,7 +1327,7 @@ extern "C" {
1310/** 1327/**
1311 * Service to client: result of store operation. 1328 * Service to client: result of store operation.
1312 */ 1329 */
1313#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 436 1330#define GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE 436
1314 1331
1315/** 1332/**
1316 * Client to service: lookup label 1333 * Client to service: lookup label
@@ -1796,7 +1813,6 @@ extern "C" {
1796#define GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL 710 1813#define GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL 710
1797 1814
1798 1815
1799
1800/******************************************************************************* 1816/*******************************************************************************
1801 * SETI message types 1817 * SETI message types
1802 ******************************************************************************/ 1818 ******************************************************************************/
@@ -2336,7 +2352,7 @@ extern "C" {
2336/** M<->S<->C: PSYC message which contains a header and one or more message 2352/** M<->S<->C: PSYC message which contains a header and one or more message
2337 * parts. */ 2353 * parts. */
2338#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \ 2354#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \
2339 692 // FIXME: start using this where appropriate 2355 692 // FIXME: start using this where appropriate
2340 2356
2341/** Message part: method */ 2357/** Message part: method */
2342#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693 2358#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693
@@ -2583,14 +2599,14 @@ extern "C" {
2583#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820 2599#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820
2584 2600
2585/** 2601/**
2586 * Iteration request 2602 * Iteration request (see also 828, 829)
2587 */ 2603 */
2588#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 821 2604#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_START 821
2589 2605
2590/** 2606/**
2591 * Iteration record message 2607 * Record result message
2592 */ 2608 */
2593#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD 822 2609#define GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD 822
2594 2610
2595/** 2611/**
2596 * Iteration end message 2612 * Iteration end message
@@ -2598,19 +2614,34 @@ extern "C" {
2598#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823 2614#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823
2599 2615
2600/** 2616/**
2601 * Watch request 2617 * Monitor request
2618 */
2619#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_START 824
2620
2621/**
2622 * Monitor sync
2602 */ 2623 */
2603#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH 824 2624#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_SYNC 825
2604 2625
2605/** 2626/**
2606 * Watch response 2627 * Monitor next request
2607 */ 2628 */
2608#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD 825 2629#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_NEXT 826
2609 2630
2610/** 2631/**
2611 * Watch cancel request 2632 * Store result message
2612 */ 2633 */
2613#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL 826 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
2614 2645
2615/******************************************************************************* 2646/*******************************************************************************
2616 * SOCIAL message types 2647 * SOCIAL message types
@@ -3185,6 +3216,11 @@ extern "C" {
3185#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 3216#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064
3186 3217
3187/** 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/**
3188 * Message to ask NAT service to request autoconfiguration. 3224 * Message to ask NAT service to request autoconfiguration.
3189 */ 3225 */
3190#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067 3226#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067
@@ -3514,6 +3550,11 @@ extern "C" {
3514#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461 3550#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461
3515 3551
3516/** 3552/**
3553 * UDP Rekey.
3554 */
3555#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_REKEY 1462
3556
3557/**
3517 * Next available: 1500 3558 * Next available: 1500
3518 */ 3559 */
3519#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500 3560#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500
@@ -3533,17 +3574,9 @@ extern "C" {
3533 3574
3534#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 3575#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600
3535 3576
3536#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601 3577#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1601
3537 3578
3538#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602 3579#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1602
3539
3540#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603
3541
3542#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604
3543
3544#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605
3545
3546#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606
3547 3580
3548/************************************ Room *************************************/ 3581/************************************ Room *************************************/
3549 3582
@@ -3559,6 +3592,10 @@ extern "C" {
3559 3592
3560#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616 3593#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616
3561 3594
3595#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC 1617
3596
3597#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_LINK 1618
3598
3562/*********************************************************************************/ 3599/*********************************************************************************/
3563 3600
3564/*********************************************************************************/ 3601/*********************************************************************************/
@@ -3585,7 +3622,36 @@ extern "C" {
3585 3622
3586#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706 3623#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706
3587 3624
3625#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED 1707
3626
3627#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACH 1708
3628
3629#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE 1709
3630
3631#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED 1710
3632
3633/*********************************************************************************/
3634
3588/*********************************************************************************/ 3635/*********************************************************************************/
3636/********************************** NAMESTORE (cont.) **************************/
3637/*********************************************************************************/
3638/* NAMESTORE: message types 1750-1800
3639 */
3640
3641/**
3642 * Message type for start of record edit with advisory lock
3643 */
3644#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT 1750
3645
3646/**
3647 * Return record set to edit with previous editor hint/advisory lock
3648 */
3649#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE 1751
3650
3651/**
3652 * Message type for cancellation/reset of editor hint/advisory lock
3653 */
3654#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_CANCEL 1752
3589 3655
3590/** 3656/**
3591 * Type used to match 'all' message types. 3657 * Type used to match 'all' message types.
@@ -3605,4 +3671,6 @@ extern "C" {
3605 3671
3606/** @} */ /* end of group protocols */ 3672/** @} */ /* end of group protocols */
3607 3673
3674/** @} */ /* end of group addition */
3675
3608/* end of gnunet_protocols.h */ 3676/* end of gnunet_protocols.h */
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index bbf1c3ad3..e4dec14fa 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * Identity attribute definitions 28 * Identity attribute definitions
26 * 29 *
27 * @defgroup reclaim-attribute reclaim attributes 30 * @defgroup reclaim-attribute Reclaim attributes
28 * @{ 31 * @{
29 */ 32 */
30#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H 33#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
@@ -37,6 +40,7 @@ extern "C" {
37#endif 40#endif
38#endif 41#endif
39 42
43
40#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
41 45
42enum GNUNET_RECLAIM_AttributeType { 46enum GNUNET_RECLAIM_AttributeType {
@@ -512,7 +516,7 @@ GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type);
512/** 516/**
513 * Get required size for serialization buffer 517 * Get required size for serialization buffer
514 * 518 *
515 * @param attrs the attribute list to serialize 519 * @param credentials the attribute list to serialize
516 * @return the required buffer size 520 * @return the required buffer size
517 */ 521 */
518size_t 522size_t
@@ -521,9 +525,9 @@ GNUNET_RECLAIM_credential_list_serialize_get_size (
521 525
522 526
523/** 527/**
524 * Destroy claim list 528 * Destroy credential list
525 * 529 *
526 * @param attrs list to destroy 530 * @param credentials list to destroy
527 */ 531 */
528void 532void
529GNUNET_RECLAIM_credential_list_destroy ( 533GNUNET_RECLAIM_credential_list_destroy (
@@ -548,15 +552,15 @@ GNUNET_RECLAIM_credential_list_add (
548 552
549 553
550/** 554/**
551 * Serialize an attribute list 555 * Serialize a credential list
552 * 556 *
553 * @param attrs the attribute list to serialize 557 * @param credentials the credential list to serialize
554 * @param result the serialized attribute 558 * @param result the serialized credential
555 * @return length of serialized data 559 * @return length of serialized data
556 */ 560 */
557size_t 561size_t
558GNUNET_RECLAIM_credential_list_serialize ( 562GNUNET_RECLAIM_credential_list_serialize (
559 const struct GNUNET_RECLAIM_CredentialList *attrs, 563 const struct GNUNET_RECLAIM_CredentialList *credentials,
560 char *result); 564 char *result);
561 565
562 566
@@ -858,4 +862,6 @@ GNUNET_RECLAIM_credential_get_presentation (
858 862
859/** @} */ /* end of group reclaim-attribute */ 863/** @} */ /* end of group reclaim-attribute */
860 864
865/** @} */ /* end of group addition */
866
861/* end of gnunet_reclaim_attribute_lib.h */ 867/* end of gnunet_reclaim_attribute_lib.h */
diff --git a/src/include/gnunet_reclaim_plugin.h b/src/include/gnunet_reclaim_plugin.h
index 11d5d76f7..f8b2084d2 100644
--- a/src/include/gnunet_reclaim_plugin.h
+++ b/src/include/gnunet_reclaim_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -30,6 +33,7 @@
30#ifndef GNUNET_RECLAIM_PLUGIN_H 33#ifndef GNUNET_RECLAIM_PLUGIN_H
31#define GNUNET_RECLAIM_PLUGIN_H 34#define GNUNET_RECLAIM_PLUGIN_H
32 35
36
33#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
34#include "gnunet_reclaim_lib.h" 38#include "gnunet_reclaim_lib.h"
35 39
@@ -439,3 +443,5 @@ struct GNUNET_RECLAIM_CredentialPluginFunctions
439#endif 443#endif
440 444
441/** @} */ /* end of group */ 445/** @} */ /* end of group */
446
447/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index 38e1c8735..08f3f60a3 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -19,13 +19,16 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * reclaim service; implements identity and personal data sharing 28 * reclaim service; implements identity and personal data sharing
26 * for GNUnet 29 * for GNUnet
27 * 30 *
28 * @defgroup reclaim service 31 * @defgroup reclaim Reclaim service
29 * @{ 32 * @{
30 */ 33 */
31#ifndef GNUNET_RECLAIM_SERVICE_H 34#ifndef GNUNET_RECLAIM_SERVICE_H
@@ -38,6 +41,7 @@ extern "C" {
38#endif 41#endif
39#endif 42#endif
40 43
44
41#include "gnunet_identity_service.h" 45#include "gnunet_identity_service.h"
42#include "gnunet_reclaim_lib.h" 46#include "gnunet_reclaim_lib.h"
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
@@ -45,7 +49,7 @@ extern "C" {
45/** 49/**
46 * Version number of the re:claimID API. 50 * Version number of the re:claimID API.
47 */ 51 */
48#define GNUNET_RECLAIM_VERSION 0x00000001 52#define GNUNET_RECLAIM_VERSION 0x00000002
49 53
50/** 54/**
51 * Opaque handle to access the service. 55 * Opaque handle to access the service.
@@ -58,6 +62,9 @@ struct GNUNET_RECLAIM_Handle;
58 */ 62 */
59struct GNUNET_RECLAIM_Operation; 63struct GNUNET_RECLAIM_Operation;
60 64
65#define GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN 256
66
67#define GNUNET_RECLAIM_TICKET_RP_URI_URN_PREFIX "urn:gns:"
61 68
62/** 69/**
63 * The authorization ticket. This ticket is meant to be transferred 70 * The authorization ticket. This ticket is meant to be transferred
@@ -70,17 +77,20 @@ struct GNUNET_RECLAIM_Ticket
70 /** 77 /**
71 * The ticket issuer (= the user) 78 * The ticket issuer (= the user)
72 */ 79 */
73 struct GNUNET_IDENTITY_PublicKey identity; 80 struct GNUNET_CRYPTO_PublicKey identity;
74 81
75 /** 82 /**
76 * The ticket audience (= relying party) 83 * The ticket random identifier
77 */ 84 */
78 struct GNUNET_IDENTITY_PublicKey audience; 85 struct GNUNET_RECLAIM_Identifier rnd;
86
79 87
80 /** 88 /**
81 * The ticket random identifier 89 * Followed by the ticket audience (= relying party) URI.
90 * 0-terminated string.
91 * Example: "urn:gns:000G002B4RF1XPBXDPGZA0PT16BHQCS427YQK4NC84KZMK7TK8C2Z5GMK8"
82 */ 92 */
83 struct GNUNET_RECLAIM_Identifier rnd; 93 char rp_uri[GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN];
84}; 94};
85 95
86 96
@@ -130,7 +140,7 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
130 * @param attr The attribute 140 * @param attr The attribute
131 */ 141 */
132typedef void (*GNUNET_RECLAIM_AttributeResult) ( 142typedef void (*GNUNET_RECLAIM_AttributeResult) (
133 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 143 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
134 const struct GNUNET_RECLAIM_Attribute *attr); 144 const struct GNUNET_RECLAIM_Attribute *attr);
135 145
136/** 146/**
@@ -142,7 +152,7 @@ typedef void (*GNUNET_RECLAIM_AttributeResult) (
142 * @param presentation The presentation for the credential (may be NULL) 152 * @param presentation The presentation for the credential (may be NULL)
143 */ 153 */
144typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( 154typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
145 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 155 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
146 const struct GNUNET_RECLAIM_Attribute *attr, 156 const struct GNUNET_RECLAIM_Attribute *attr,
147 const struct GNUNET_RECLAIM_Presentation *presentation); 157 const struct GNUNET_RECLAIM_Presentation *presentation);
148 158
@@ -156,7 +166,7 @@ typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
156 * @param attributes the parsed attributes 166 * @param attributes the parsed attributes
157 */ 167 */
158typedef void (*GNUNET_RECLAIM_CredentialResult) ( 168typedef void (*GNUNET_RECLAIM_CredentialResult) (
159 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 169 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
160 const struct GNUNET_RECLAIM_Credential *credential); 170 const struct GNUNET_RECLAIM_Credential *credential);
161 171
162 172
@@ -185,7 +195,7 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
185struct GNUNET_RECLAIM_Operation * 195struct GNUNET_RECLAIM_Operation *
186GNUNET_RECLAIM_attribute_store ( 196GNUNET_RECLAIM_attribute_store (
187 struct GNUNET_RECLAIM_Handle *h, 197 struct GNUNET_RECLAIM_Handle *h,
188 const struct GNUNET_IDENTITY_PrivateKey *pkey, 198 const struct GNUNET_CRYPTO_PrivateKey *pkey,
189 const struct GNUNET_RECLAIM_Attribute *attr, 199 const struct GNUNET_RECLAIM_Attribute *attr,
190 const struct GNUNET_TIME_Relative *exp_interval, 200 const struct GNUNET_TIME_Relative *exp_interval,
191 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 201 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
@@ -197,7 +207,7 @@ GNUNET_RECLAIM_attribute_store (
197 * 207 *
198 * @param h handle to the re:claimID service 208 * @param h handle to the re:claimID service
199 * @param pkey private key of the identity 209 * @param pkey private key of the identity
200 * @param attr the credential value 210 * @param credential the credential value
201 * @param exp_interval the relative expiration interval for the credential 211 * @param exp_interval the relative expiration interval for the credential
202 * @param cont continuation to call when done 212 * @param cont continuation to call when done
203 * @param cont_cls closure for @a cont 213 * @param cont_cls closure for @a cont
@@ -206,7 +216,7 @@ GNUNET_RECLAIM_attribute_store (
206struct GNUNET_RECLAIM_Operation * 216struct GNUNET_RECLAIM_Operation *
207GNUNET_RECLAIM_credential_store ( 217GNUNET_RECLAIM_credential_store (
208 struct GNUNET_RECLAIM_Handle *h, 218 struct GNUNET_RECLAIM_Handle *h,
209 const struct GNUNET_IDENTITY_PrivateKey *pkey, 219 const struct GNUNET_CRYPTO_PrivateKey *pkey,
210 const struct GNUNET_RECLAIM_Credential *credential, 220 const struct GNUNET_RECLAIM_Credential *credential,
211 const struct GNUNET_TIME_Relative *exp_interval, 221 const struct GNUNET_TIME_Relative *exp_interval,
212 GNUNET_RECLAIM_ContinuationWithStatus cont, 222 GNUNET_RECLAIM_ContinuationWithStatus cont,
@@ -227,12 +237,12 @@ GNUNET_RECLAIM_credential_store (
227struct GNUNET_RECLAIM_Operation * 237struct GNUNET_RECLAIM_Operation *
228GNUNET_RECLAIM_attribute_delete ( 238GNUNET_RECLAIM_attribute_delete (
229 struct GNUNET_RECLAIM_Handle *h, 239 struct GNUNET_RECLAIM_Handle *h,
230 const struct GNUNET_IDENTITY_PrivateKey *pkey, 240 const struct GNUNET_CRYPTO_PrivateKey *pkey,
231 const struct GNUNET_RECLAIM_Attribute *attr, 241 const struct GNUNET_RECLAIM_Attribute *attr,
232 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 242 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
233 243
234/** 244/**
235 * Delete a credential. Tickets used to share use a presentation of this 245 * Delete a credential. Tickets used to share a presentation of this
236 * credential are updated accordingly. 246 * credential are updated accordingly.
237 * 247 *
238 * @param h handle to the re:claimID service 248 * @param h handle to the re:claimID service
@@ -245,7 +255,7 @@ GNUNET_RECLAIM_attribute_delete (
245struct GNUNET_RECLAIM_Operation * 255struct GNUNET_RECLAIM_Operation *
246GNUNET_RECLAIM_credential_delete ( 256GNUNET_RECLAIM_credential_delete (
247 struct GNUNET_RECLAIM_Handle *h, 257 struct GNUNET_RECLAIM_Handle *h,
248 const struct GNUNET_IDENTITY_PrivateKey *pkey, 258 const struct GNUNET_CRYPTO_PrivateKey *pkey,
249 const struct GNUNET_RECLAIM_Credential *cred, 259 const struct GNUNET_RECLAIM_Credential *cred,
250 GNUNET_RECLAIM_ContinuationWithStatus cont, 260 GNUNET_RECLAIM_ContinuationWithStatus cont,
251 void *cont_cls); 261 void *cont_cls);
@@ -277,7 +287,7 @@ GNUNET_RECLAIM_credential_delete (
277struct GNUNET_RECLAIM_AttributeIterator * 287struct GNUNET_RECLAIM_AttributeIterator *
278GNUNET_RECLAIM_get_attributes_start ( 288GNUNET_RECLAIM_get_attributes_start (
279 struct GNUNET_RECLAIM_Handle *h, 289 struct GNUNET_RECLAIM_Handle *h,
280 const struct GNUNET_IDENTITY_PrivateKey *identity, 290 const struct GNUNET_CRYPTO_PrivateKey *identity,
281 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 291 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
282 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, 292 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
283 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 293 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -333,7 +343,7 @@ GNUNET_RECLAIM_get_attributes_stop (
333struct GNUNET_RECLAIM_CredentialIterator * 343struct GNUNET_RECLAIM_CredentialIterator *
334GNUNET_RECLAIM_get_credentials_start ( 344GNUNET_RECLAIM_get_credentials_start (
335 struct GNUNET_RECLAIM_Handle *h, 345 struct GNUNET_RECLAIM_Handle *h,
336 const struct GNUNET_IDENTITY_PrivateKey *identity, 346 const struct GNUNET_CRYPTO_PrivateKey *identity,
337 GNUNET_SCHEDULER_TaskCallback error_cb, 347 GNUNET_SCHEDULER_TaskCallback error_cb,
338 void *error_cb_cls, 348 void *error_cb_cls,
339 GNUNET_RECLAIM_CredentialResult proc, 349 GNUNET_RECLAIM_CredentialResult proc,
@@ -346,7 +356,7 @@ GNUNET_RECLAIM_get_credentials_start (
346 * Calls the record processor specified in #GNUNET_RECLAIM_get_credentials_start 356 * Calls the record processor specified in #GNUNET_RECLAIM_get_credentials_start
347 * for the next record. 357 * for the next record.
348 * 358 *
349 * @param it the iterator 359 * @param ait the iterator
350 */ 360 */
351void 361void
352GNUNET_RECLAIM_get_credentials_next ( 362GNUNET_RECLAIM_get_credentials_next (
@@ -358,7 +368,7 @@ GNUNET_RECLAIM_get_credentials_next (
358 * be called on any iteration that has not yet completed prior to calling 368 * be called on any iteration that has not yet completed prior to calling
359 * #GNUNET_RECLAIM_disconnect. 369 * #GNUNET_RECLAIM_disconnect.
360 * 370 *
361 * @param it the iterator 371 * @param ait the iterator
362 */ 372 */
363void 373void
364GNUNET_RECLAIM_get_credentials_stop ( 374GNUNET_RECLAIM_get_credentials_stop (
@@ -372,7 +382,7 @@ GNUNET_RECLAIM_get_credentials_stop (
372 * 382 *
373 * @param h the identity provider to use 383 * @param h the identity provider to use
374 * @param iss the issuing identity (= the user) 384 * @param iss the issuing identity (= the user)
375 * @param rp the subject of the ticket (= the relying party) 385 * @param rp the subject of the ticket (= the relying party) see #GNUNET_RECLAIM_Ticket
376 * @param attrs the attributes that the relying party is given access to 386 * @param attrs the attributes that the relying party is given access to
377 * @param cb the callback 387 * @param cb the callback
378 * @param cb_cls the callback closure 388 * @param cb_cls the callback closure
@@ -381,8 +391,8 @@ GNUNET_RECLAIM_get_credentials_stop (
381struct GNUNET_RECLAIM_Operation * 391struct GNUNET_RECLAIM_Operation *
382GNUNET_RECLAIM_ticket_issue ( 392GNUNET_RECLAIM_ticket_issue (
383 struct GNUNET_RECLAIM_Handle *h, 393 struct GNUNET_RECLAIM_Handle *h,
384 const struct GNUNET_IDENTITY_PrivateKey *iss, 394 const struct GNUNET_CRYPTO_PrivateKey *iss,
385 const struct GNUNET_IDENTITY_PublicKey *rp, 395 const char *rp,
386 const struct GNUNET_RECLAIM_AttributeList *attrs, 396 const struct GNUNET_RECLAIM_AttributeList *attrs,
387 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); 397 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls);
388 398
@@ -403,7 +413,7 @@ GNUNET_RECLAIM_ticket_issue (
403struct GNUNET_RECLAIM_Operation * 413struct GNUNET_RECLAIM_Operation *
404GNUNET_RECLAIM_ticket_revoke ( 414GNUNET_RECLAIM_ticket_revoke (
405 struct GNUNET_RECLAIM_Handle *h, 415 struct GNUNET_RECLAIM_Handle *h,
406 const struct GNUNET_IDENTITY_PrivateKey *identity, 416 const struct GNUNET_CRYPTO_PrivateKey *identity,
407 const struct GNUNET_RECLAIM_Ticket *ticket, 417 const struct GNUNET_RECLAIM_Ticket *ticket,
408 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls); 418 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
409 419
@@ -413,8 +423,6 @@ GNUNET_RECLAIM_ticket_revoke (
413 * information from the issuer 423 * information from the issuer
414 * 424 *
415 * @param h the identity provider to use 425 * @param h the identity provider to use
416 * @param identity the identity that is the subject of the issued ticket (the
417 * relying party)
418 * @param ticket the issued ticket to consume 426 * @param ticket the issued ticket to consume
419 * @param cb the callback to call 427 * @param cb the callback to call
420 * @param cb_cls the callback closure 428 * @param cb_cls the callback closure
@@ -423,7 +431,6 @@ GNUNET_RECLAIM_ticket_revoke (
423struct GNUNET_RECLAIM_Operation * 431struct GNUNET_RECLAIM_Operation *
424GNUNET_RECLAIM_ticket_consume ( 432GNUNET_RECLAIM_ticket_consume (
425 struct GNUNET_RECLAIM_Handle *h, 433 struct GNUNET_RECLAIM_Handle *h,
426 const struct GNUNET_IDENTITY_PrivateKey *identity,
427 const struct GNUNET_RECLAIM_Ticket *ticket, 434 const struct GNUNET_RECLAIM_Ticket *ticket,
428 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); 435 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
429 436
@@ -448,7 +455,7 @@ GNUNET_RECLAIM_ticket_consume (
448struct GNUNET_RECLAIM_TicketIterator * 455struct GNUNET_RECLAIM_TicketIterator *
449GNUNET_RECLAIM_ticket_iteration_start ( 456GNUNET_RECLAIM_ticket_iteration_start (
450 struct GNUNET_RECLAIM_Handle *h, 457 struct GNUNET_RECLAIM_Handle *h,
451 const struct GNUNET_IDENTITY_PrivateKey *identity, 458 const struct GNUNET_CRYPTO_PrivateKey *identity,
452 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 459 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
453 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, 460 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
454 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 461 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -495,6 +502,43 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
495void 502void
496GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); 503GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
497 504
505/**
506 * Get serialized ticket size
507 *
508 * @param tkt the ticket
509 * @return the buffer length requirement for a serialization
510 */
511size_t
512GNUNET_RECLAIM_ticket_serialize_get_size (const struct GNUNET_RECLAIM_Ticket *tkt);
513
514/**
515 * Deserializes a ticket
516 *
517 * @param buffer the buffer to read from
518 * @param len the length of the buffer
519 * @param tkt the ticket to write to (must be allocated)
520 * @param kb_read how many bytes were read from buffer
521 * @return GNUNET_SYSERR on error
522 */
523enum GNUNET_GenericReturnValue
524GNUNET_RECLAIM_read_ticket_from_buffer (const void *buffer,
525 size_t len,
526 struct GNUNET_RECLAIM_Ticket *tkt,
527 size_t *tb_read);
528
529/**
530 * Serializes a ticket
531 *
532 * @param tkt the ticket to serialize
533 * @param buffer the buffer to serialize to (must be allocated with sufficient size
534 * @param len the length of the buffer
535 * @return the number of written bytes or < 0 on error
536 */
537ssize_t
538GNUNET_RECLAIM_write_ticket_to_buffer (const struct
539 GNUNET_RECLAIM_Ticket *tkt,
540 void *buffer,
541 size_t len);
498 542
499#if 0 /* keep Emacsens' auto-indent happy */ 543#if 0 /* keep Emacsens' auto-indent happy */
500{ 544{
@@ -509,4 +553,6 @@ GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
509 553
510/** @} */ /* end of group reclaim */ 554/** @} */ /* end of group reclaim */
511 555
556/** @} */ /* end of group addition */
557
512/* end of gnunet_reclaim_service.h */ 558/* end of gnunet_reclaim_service.h */
diff --git a/src/include/gnunet_regex_service.h b/src/include/gnunet_regex_service.h
index a875eab90..093bf2d6a 100644
--- a/src/include/gnunet_regex_service.h
+++ b/src/include/gnunet_regex_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Maximilian Szengel 24 * @author Maximilian Szengel
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -36,6 +39,7 @@
36#ifndef GNUNET_REGEX_SERVICE_H 39#ifndef GNUNET_REGEX_SERVICE_H
37#define GNUNET_REGEX_SERVICE_H 40#define GNUNET_REGEX_SERVICE_H
38 41
42
39#include "gnunet_util_lib.h" 43#include "gnunet_util_lib.h"
40 44
41#ifdef __cplusplus 45#ifdef __cplusplus
@@ -149,3 +153,5 @@ GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s);
149#endif 153#endif
150 154
151/** @} */ /* end of group */ 155/** @} */ /* end of group */
156
157/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_resolver_service.h b/src/include/gnunet_resolver_service.h
index 956e4d67e..89fec24f5 100644
--- a/src/include/gnunet_resolver_service.h
+++ b/src/include/gnunet_resolver_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_configuration_lib.h" 47#include "gnunet_configuration_lib.h"
44#include "gnunet_scheduler_lib.h" 48#include "gnunet_scheduler_lib.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
@@ -178,4 +182,6 @@ GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
178 182
179/** @} */ /* end of group resolver */ 183/** @} */ /* end of group resolver */
180 184
185/** @} */ /* end of group addition to vpn_suite */
186
181/* end of gnunet_resolver_service.h */ 187/* end of gnunet_resolver_service.h */
diff --git a/src/include/gnunet_rest_lib.h b/src/include/gnunet_rest_lib.h
index 7e74bee76..f70500de5 100644
--- a/src/include/gnunet_rest_lib.h
+++ b/src/include/gnunet_rest_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup rest_l2 REST service and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_REST_LIB_H 34#ifndef GNUNET_REST_LIB_H
32#define GNUNET_REST_LIB_H 35#define GNUNET_REST_LIB_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include <microhttpd.h> 39#include <microhttpd.h>
36 40
@@ -137,3 +141,5 @@ GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
137#endif 141#endif
138 142
139/** @} */ /* end of group */ 143/** @} */ /* end of group */
144
145/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index 96454f66b..3a8af5389 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup rest_l2 REST service and libraries
22 * @{
23 *
21 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
22 * 25 *
23 * @file 26 * @file
@@ -29,6 +32,7 @@
29#ifndef GNUNET_REST_PLUGIN_H 32#ifndef GNUNET_REST_PLUGIN_H
30#define GNUNET_REST_PLUGIN_H 33#define GNUNET_REST_PLUGIN_H
31 34
35
32#include "gnunet_util_lib.h" 36#include "gnunet_util_lib.h"
33#include "gnunet_rest_lib.h" 37#include "gnunet_rest_lib.h"
34#include "microhttpd.h" 38#include "microhttpd.h"
@@ -59,24 +63,13 @@ struct GNUNET_REST_Plugin
59 * e.g. http://hostname:port/name 63 * e.g. http://hostname:port/name
60 */ 64 */
61 char *name; 65 char *name;
62
63 /**
64 * Function to process a REST call
65 *
66 * @param method the HTTP method called
67 * @param url the relative url accessed
68 * @param data the REST data (can be NULL)
69 * @param data_size the length of the data
70 * @param proc the callback for result
71 * @param proc_cls closure for callback
72 * @return GNUNET_YES if the request was processed
73 */
74 enum GNUNET_GenericReturnValue (*process_request)(
75 struct GNUNET_REST_RequestHandle *handle,
76 GNUNET_REST_ResultProcessor proc,
77 void *proc_cls);
78}; 66};
79 67
68typedef enum GNUNET_GenericReturnValue (*GNUNET_REST_ProcessingFunction)(
69 void *plugin,
70 struct GNUNET_REST_RequestHandle *handle,
71 GNUNET_REST_ResultProcessor proc,
72 void *proc_cls);
80 73
81#if 0 /* keep Emacsens' auto-indent happy */ 74#if 0 /* keep Emacsens' auto-indent happy */
82{ 75{
@@ -88,3 +81,5 @@ struct GNUNET_REST_Plugin
88#endif 81#endif
89 82
90/** @} */ /* end of group */ 83/** @} */ /* end of group */
84
85/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h
index 8cff948e2..427be62ac 100644
--- a/src/include/gnunet_revocation_service.h
+++ b/src/include/gnunet_revocation_service.h
@@ -21,9 +21,14 @@
21#ifndef GNUNET_REVOCATION_SERVICE_H_ 21#ifndef GNUNET_REVOCATION_SERVICE_H_
22#define GNUNET_REVOCATION_SERVICE_H_ 22#define GNUNET_REVOCATION_SERVICE_H_
23 23
24
25#include "gnunet_gnsrecord_lib.h"
24#include "gnunet_identity_service.h" 26#include "gnunet_identity_service.h"
25 27
26/** 28/**
29 * @addtogroup egos Ego management
30 * @{
31 *
27 * @author Christian Grothoff 32 * @author Christian Grothoff
28 * 33 *
29 * @file 34 * @file
@@ -52,71 +57,6 @@ extern "C"
52 */ 57 */
53#define GNUNET_REVOCATION_VERSION 0x00000001 58#define GNUNET_REVOCATION_VERSION 0x00000001
54 59
55/**
56 * Maximum length of a revocation
57 */
58#define GNUNET_REVOCATION_MAX_PROOF_SIZE sizeof(struct GNUNET_REVOCATION_PowP) +\
59 sizeof(struct GNUNET_IDENTITY_PublicKey) +\
60 1024 //FIXME max sig_len
61
62/**
63 * The proof-of-work narrowing factor.
64 * The number of PoWs that are calculates as part of revocation.
65 */
66#define POW_COUNT 32
67
68
69GNUNET_NETWORK_STRUCT_BEGIN
70
71/**
72 * Struct for a proof of work as part of the revocation.
73 */
74struct GNUNET_REVOCATION_PowP
75{
76 /**
77 * The timestamp of the revocation
78 */
79 struct GNUNET_TIME_AbsoluteNBO timestamp;
80
81 /**
82 * The TTL of this revocation (purely informational)
83 */
84 struct GNUNET_TIME_RelativeNBO ttl;
85
86 /**
87 * The PoWs
88 */
89 uint64_t pow[POW_COUNT] GNUNET_PACKED;
90
91 /** followed by the public key type, the key and a signature **/
92};
93
94
95/**
96 * The signature object we use for the PoW
97 */
98struct GNUNET_REVOCATION_SignaturePurposePS
99{
100 /**
101 * The signature purpose
102 */
103 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
104
105 /**
106 * The timestamp of the revocation
107 */
108 struct GNUNET_TIME_AbsoluteNBO timestamp;
109
110 /** Followed by the zone public key type and key **/
111};
112
113GNUNET_NETWORK_STRUCT_END
114
115
116/**
117 * Handle to a running proof-of-work calculation.
118 */
119struct GNUNET_REVOCATION_PowCalculationHandle;
120 60
121/** 61/**
122 * Handle for the key revocation query. 62 * Handle for the key revocation query.
@@ -148,7 +88,7 @@ typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
148 */ 88 */
149struct GNUNET_REVOCATION_Query * 89struct GNUNET_REVOCATION_Query *
150GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, 90GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
151 const struct GNUNET_IDENTITY_PublicKey *key, 91 const struct GNUNET_CRYPTO_PublicKey *key,
152 GNUNET_REVOCATION_Callback func, void *func_cls); 92 GNUNET_REVOCATION_Callback func, void *func_cls);
153 93
154 94
@@ -172,7 +112,7 @@ struct GNUNET_REVOCATION_Handle;
172 * 112 *
173 * @param cfg the configuration to use 113 * @param cfg the configuration to use
174 * @param pow proof of work to use (should have been created by 114 * @param pow proof of work to use (should have been created by
175 * iteratively calling #GNUNET_REVOCATION_pow_round) 115 * iteratively calling #GNUNET_CRYPTO_pow_round)
176 * @param func function to call with the result of the check 116 * @param func function to call with the result of the check
177 * (called with `is_valid` being #GNUNET_NO if 117 * (called with `is_valid` being #GNUNET_NO if
178 * the revocation worked). 118 * the revocation worked).
@@ -181,7 +121,7 @@ struct GNUNET_REVOCATION_Handle;
181 */ 121 */
182struct GNUNET_REVOCATION_Handle * 122struct GNUNET_REVOCATION_Handle *
183GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, 123GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
184 const struct GNUNET_REVOCATION_PowP *pow, 124 const struct GNUNET_GNSRECORD_PowP *pow,
185 GNUNET_REVOCATION_Callback func, void *func_cls); 125 GNUNET_REVOCATION_Callback func, void *func_cls);
186 126
187 127
@@ -194,68 +134,6 @@ void
194GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h); 134GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
195 135
196 136
197/**
198 * Check if the given proof-of-work is valid.
199 *
200 * @param pow proof of work
201 * @param matching_bits how many bits must match (configuration)
202 * @param epoch_duration length of single epoch in configuration
203 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
204 */
205enum GNUNET_GenericReturnValue
206GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
207 unsigned int matching_bits,
208 struct GNUNET_TIME_Relative epoch_duration);
209
210
211/**
212 * Initializes a fresh PoW computation.
213 *
214 * @param key the key to calculate the PoW for.
215 * @param pow the pow object to work with in the calculation.
216 */
217void
218GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key,
219 struct GNUNET_REVOCATION_PowP *pow);
220
221
222/**
223 * Starts a proof-of-work calculation given the pow object as well as
224 * target epochs and difficulty.
225 *
226 * @param pow the PoW to based calculations on.
227 * @param epochs the number of epochs for which the PoW must be valid.
228 * @param difficulty the base difficulty of the PoW.
229 * @return a handle for use in PoW rounds
230 */
231struct GNUNET_REVOCATION_PowCalculationHandle*
232GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
233 int epochs,
234 unsigned int difficulty);
235
236
237/**
238 * Calculate a single round in the key revocation PoW.
239 *
240 * @param pc handle to the PoW, initially called with NULL.
241 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
242 */
243enum GNUNET_GenericReturnValue
244GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
245
246
247/**
248 * Stop a PoW calculation
249 *
250 * @param pc the calculation to clean up
251 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
252 * valid
253 */
254void
255GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
256
257size_t
258GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow);
259 137
260 138
261#if 0 /* keep Emacsens' auto-indent happy */ 139#if 0 /* keep Emacsens' auto-indent happy */
@@ -268,3 +146,5 @@ GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow);
268#endif /* GNUNET_REVOCATION_SERVICE_H_ */ 146#endif /* GNUNET_REVOCATION_SERVICE_H_ */
269 147
270/** @} */ /* end of group revocation */ 148/** @} */ /* end of group revocation */
149
150/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_rps_service.h b/src/include/gnunet_rps_service.h
index a0ed675f7..85c085111 100644
--- a/src/include/gnunet_rps_service.h
+++ b/src/include/gnunet_rps_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Julius Bünger 25 * @author Julius Bünger
23 * 26 *
24 * @file 27 * @file
@@ -262,3 +265,5 @@ GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
262#endif 265#endif
263 266
264/** @} */ /* end of group */ 267/** @} */ /* end of group */
268
269/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_scalarproduct_service.h b/src/include/gnunet_scalarproduct_service.h
index 1d775f659..96d12db3f 100644
--- a/src/include/gnunet_scalarproduct_service.h
+++ b/src/include/gnunet_scalarproduct_service.h
@@ -31,6 +31,7 @@
31#ifndef GNUNET_SCALARPRODUCT_SERVICE_H 31#ifndef GNUNET_SCALARPRODUCT_SERVICE_H
32#define GNUNET_SCALARPRODUCT_SERVICE_H 32#define GNUNET_SCALARPRODUCT_SERVICE_H
33#define GCRYPT_NO_DEPRECATED 33#define GCRYPT_NO_DEPRECATED
34
34#include <gcrypt.h> 35#include <gcrypt.h>
35 36
36#ifdef __cplusplus 37#ifdef __cplusplus
@@ -179,7 +180,7 @@ GNUNET_SCALARPRODUCT_start_computation (
179struct GNUNET_SCALARPRODUCT_ComputationHandle * 180struct GNUNET_SCALARPRODUCT_ComputationHandle *
180GNUNET_SCALARPRODUCT_accept_computation ( 181GNUNET_SCALARPRODUCT_accept_computation (
181 const struct GNUNET_CONFIGURATION_Handle *cfg, 182 const struct GNUNET_CONFIGURATION_Handle *cfg,
182 const struct GNUNET_HashCode *key, 183 const struct GNUNET_HashCode *session_key,
183 const struct GNUNET_SCALARPRODUCT_Element *elements, 184 const struct GNUNET_SCALARPRODUCT_Element *elements,
184 uint32_t element_count, 185 uint32_t element_count,
185 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, 186 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 158f1d83b..0118a1535 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -92,6 +96,7 @@ enum GNUNET_SCHEDULER_Reason
92}; 96};
93 97
94 98
99
95#include "gnunet_time_lib.h" 100#include "gnunet_time_lib.h"
96#include "gnunet_network_lib.h" 101#include "gnunet_network_lib.h"
97 102
@@ -929,3 +934,5 @@ GNUNET_SCHEDULER_begin_async_scope (struct GNUNET_AsyncScopeId *aid);
929#endif 934#endif
930 935
931/** @} */ /* end of group scheduler */ 936/** @} */ /* end of group scheduler */
937
938/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_secretsharing_service.h b/src/include/gnunet_secretsharing_service.h
index c13cf482a..de629b308 100644
--- a/src/include/gnunet_secretsharing_service.h
+++ b/src/include/gnunet_secretsharing_service.h
@@ -40,6 +40,7 @@ extern "C"
40#endif 40#endif
41#endif 41#endif
42 42
43
43#include "gnunet_common.h" 44#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 45#include "gnunet_time_lib.h"
45#include "gnunet_configuration_lib.h" 46#include "gnunet_configuration_lib.h"
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index ad238a0fa..0ad4fcc3c 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -18,7 +18,19 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21
22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
21/** 26/**
27 * @addtogroup libgnunetutil
28 * Multi-function utilities library for GNUnet programs
29 * @{
30 *
31 * @addtogroup networking
32 * @{
33 *
22 * @author Christian Grothoff 34 * @author Christian Grothoff
23 * 35 *
24 * @file 36 * @file
@@ -43,8 +55,8 @@ extern "C"
43#endif 55#endif
44#endif 56#endif
45 57
58#include "gnunet_util_lib.h"
46#include "gnunet_configuration_lib.h" 59#include "gnunet_configuration_lib.h"
47#include "gnunet_mq_lib.h"
48 60
49 61
50/** 62/**
@@ -191,7 +203,6 @@ GNUNET_SERVICE_start (const char *service_name,
191void 203void
192GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv); 204GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv);
193 205
194
195/** 206/**
196 * Creates the "main" function for a GNUnet service. You 207 * Creates the "main" function for a GNUnet service. You
197 * should almost always use the #GNUNET_SERVICE_MAIN macro 208 * should almost always use the #GNUNET_SERVICE_MAIN macro
@@ -246,6 +257,56 @@ GNUNET_SERVICE_run_ (int argc,
246 257
247 258
248/** 259/**
260 * Registers the GNUnet service to be scheduled as part of a monilithic
261 * libgnunet.
262 * You should almost always use the #GNUNET_SERVICE_MAIN macro
263 * instead of calling this function directly.
264 *
265 * The function will launch the service with the name @a service_name
266 * using the @a service_options to configure its shutdown
267 * behavior. Once the service is ready, the @a init_cb will be called
268 * for service-specific initialization. @a init_cb will be given the
269 * service handler which can be used to control the service's
270 * availability. When clients connect or disconnect, the respective
271 * @a connect_cb or @a disconnect_cb functions will be called. For
272 * messages received from the clients, the respective @a handlers will
273 * be invoked; for the closure of the handlers we use the return value
274 * from the @a connect_cb invocation of the respective client.
275 *
276 * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
277 * message to receive further messages from this client. If
278 * #GNUNET_SERVICE_client_continue() is not called within a short
279 * time, a warning will be logged. If delays are expected, services
280 * should call #GNUNET_SERVICE_client_disable_continue_warning() to
281 * disable the warning.
282 *
283 * Clients sending invalid messages (based on @a handlers) will be
284 * dropped. Additionally, clients can be dropped at any time using
285 * #GNUNET_SERVICE_client_drop().
286 *
287 * @param service_name name of the service to run
288 * @param options options controlling shutdown of the service
289 * @param service_init_cb function to call once the service is ready
290 * @param connect_cb function to call whenever a client connects
291 * @param disconnect_cb function to call whenever a client disconnects
292 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
293 * @param handlers NULL-terminated array of message handlers for the service,
294 * the closure will be set to the value returned by
295 * the @a connect_cb for the respective connection
296 * @return 0 on success, non-zero on error
297 */
298int
299GNUNET_SERVICE_register_ (
300 const char *service_name,
301 enum GNUNET_SERVICE_Options options,
302 GNUNET_SERVICE_InitCallback service_init_cb,
303 GNUNET_SERVICE_ConnectHandler connect_cb,
304 GNUNET_SERVICE_DisconnectHandler disconnect_cb,
305 void *cls,
306 const struct GNUNET_MQ_MessageHandler *handlers);
307
308
309/**
249 * Creates the "main" function for a GNUnet service. You 310 * Creates the "main" function for a GNUnet service. You
250 * MUST use this macro to define GNUnet services (except 311 * MUST use this macro to define GNUnet services (except
251 * for ARM, which MUST NOT use the macro). The reason is 312 * for ARM, which MUST NOT use the macro). The reason is
@@ -275,8 +336,8 @@ GNUNET_SERVICE_run_ (int argc,
275 * #GNUNET_SERVICE_client_drop(). 336 * #GNUNET_SERVICE_client_drop().
276 * 337 *
277 * @param service_name name of the service to run 338 * @param service_name name of the service to run
278 * @param options options controlling shutdown of the service 339 * @param service_options options controlling shutdown of the service
279 * @param service_init_cb function to call once the service is ready 340 * @param init_cb function to call once the service is ready
280 * @param connect_cb function to call whenever a client connects 341 * @param connect_cb function to call whenever a client connects
281 * @param disconnect_cb function to call whenever a client disconnects 342 * @param disconnect_cb function to call whenever a client disconnects
282 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb 343 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
@@ -302,26 +363,51 @@ GNUNET_SERVICE_run_ (int argc,
302 * GNUNET_MQ_handler_end ()); 363 * GNUNET_MQ_handler_end ());
303 * </code> 364 * </code>
304 */ 365 */
366#ifndef HAVE_GNUNET_MONOLITH
367#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
368 disconnect_cb, cls, ...) \
369 int \
370 main (int argc, \
371 char *const *argv) \
372 { \
373 struct GNUNET_MQ_MessageHandler mh[] = { \
374 __VA_ARGS__ \
375 }; \
376 return GNUNET_SERVICE_run_ (argc, \
377 argv, \
378 service_name, \
379 service_options, \
380 init_cb, \
381 connect_cb, \
382 disconnect_cb, \
383 cls, \
384 mh); \
385 }
386#else
305#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ 387#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
306 disconnect_cb, cls, ...) \ 388 disconnect_cb, cls, ...) \
307 int \ 389 static int __attribute__ ((constructor)) \
308 main (int argc, \ 390 init (void) \
309 char *const *argv) \ 391 { \
310 { \ 392 struct GNUNET_MQ_MessageHandler mh[] = { \
311 struct GNUNET_MQ_MessageHandler mh[] = { \ 393 __VA_ARGS__ \
312 __VA_ARGS__ \ 394 }; \
313 }; \ 395 return GNUNET_SERVICE_register_ (service_name, \
314 return GNUNET_SERVICE_run_ (argc, \ 396 service_options, \
315 argv, \ 397 init_cb, \
316 service_name, \ 398 connect_cb, \
317 service_options, \ 399 disconnect_cb, \
318 init_cb, \ 400 cls, \
319 connect_cb, \ 401 mh); \
320 disconnect_cb, \ 402 }
321 cls, \ 403#endif
322 mh); \
323 }
324 404
405/**
406 * Run the mainloop in a monolithic libgnunet.
407 * Must be called such that services are actually launched.
408 */
409void
410GNUNET_SERVICE_main (int argc, char *const *argv);
325 411
326/** 412/**
327 * Suspend accepting connections from the listen socket temporarily. 413 * Suspend accepting connections from the listen socket temporarily.
@@ -442,4 +528,8 @@ GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c);
442 528
443/** @} */ /* end of group service */ 529/** @} */ /* end of group service */
444 530
531/** @} */ /* end of group addition to networking*/
532
533/** @} */ /* end of group addition to libgnunetutil */
534
445/* end of gnunet_service_lib.h */ 535/* end of gnunet_service_lib.h */
diff --git a/src/include/gnunet_set_service.h b/src/include/gnunet_set_service.h
index 802a979cd..6874c9ec4 100644
--- a/src/include/gnunet_set_service.h
+++ b/src/include/gnunet_set_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Sets
23 * @{
24 *
22 * @author Florian Dold 25 * @author Florian Dold
23 * @author Christian Grothoff 26 * @author Christian Grothoff
24 * 27 *
@@ -44,6 +47,7 @@ extern "C"
44#endif 47#endif
45#endif 48#endif
46 49
50
47#include "gnunet_common.h" 51#include "gnunet_common.h"
48#include "gnunet_time_lib.h" 52#include "gnunet_time_lib.h"
49#include "gnunet_configuration_lib.h" 53#include "gnunet_configuration_lib.h"
@@ -365,10 +369,10 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
365 369
366 370
367/** 371/**
368 * Remove an element to the given set. 372 * Remove an element to the given set.
369 * After the element has been removed (in the sense of the 373 * After the element has been removed (in the sense of the request
370 * request being transmitted to the set service), cont will be called. 374 * being transmitted to the set service), @a cont will be called.
371 * Calls to remove_element can be queued 375 * Multiple calls to GNUNET_SET_remove_element() can be queued
372 * 376 *
373 * @param set set to remove element from 377 * @param set set to remove element from
374 * @param element element to remove from the set 378 * @param element element to remove from the set
@@ -556,7 +560,7 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element);
556 * Hash a set element. 560 * Hash a set element.
557 * 561 *
558 * @param element the element that should be hashed 562 * @param element the element that should be hashed
559 * @param ret_hash a pointer to where the hash of @a element 563 * @param[out] ret_hash a pointer to where the hash of @a element
560 * should be stored 564 * should be stored
561 */ 565 */
562void 566void
@@ -574,3 +578,5 @@ GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element,
574#endif 578#endif
575 579
576/** @} */ /* end of group */ 580/** @} */ /* end of group */
581
582/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_seti_service.h b/src/include/gnunet_seti_service.h
index 5cf35e0cd..9125ae825 100644
--- a/src/include/gnunet_seti_service.h
+++ b/src/include/gnunet_seti_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Sets
22 * @{
23 *
21 * @author Florian Dold 24 * @author Florian Dold
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_common.h" 48#include "gnunet_common.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
46#include "gnunet_configuration_lib.h" 50#include "gnunet_configuration_lib.h"
@@ -367,3 +371,5 @@ GNUNET_SETI_element_hash (const struct GNUNET_SETI_Element *element,
367#endif 371#endif
368 372
369/** @} */ /* end of group */ 373/** @} */ /* end of group */
374
375/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_setu_service.h b/src/include/gnunet_setu_service.h
index 1d7e48402..89a50f138 100644
--- a/src/include/gnunet_setu_service.h
+++ b/src/include/gnunet_setu_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Sets
22 * @{
23 *
21 * @author Florian Dold 24 * @author Florian Dold
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_common.h" 48#include "gnunet_common.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
46#include "gnunet_configuration_lib.h" 50#include "gnunet_configuration_lib.h"
@@ -288,9 +292,9 @@ GNUNET_SETU_destroy (struct GNUNET_SETU_Handle *set);
288 292
289 293
290/** 294/**
291 * Prepare a set operation to be evaluated with another peer. The evaluation 295 * Prepare a set operation to be evaluated with another peer.
292 * will not start until the client provides a local set with 296 * The evaluation will not start until the client provides a
293 * GNUNET_SETU_commit(). 297 * local set with GNUNET_SETU_commit().
294 * 298 *
295 * @param other_peer peer with the other set 299 * @param other_peer peer with the other set
296 * @param app_id hash for the application using the set 300 * @param app_id hash for the application using the set
@@ -412,3 +416,5 @@ GNUNET_SETU_element_hash (const struct GNUNET_SETU_Element *element,
412#endif 416#endif
413 417
414/** @} */ /* end of group */ 418/** @} */ /* end of group */
419
420/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_signal_lib.h b/src/include/gnunet_signal_lib.h
index 5a14a2d9e..02fbbf005 100644
--- a/src/include/gnunet_signal_lib.h
+++ b/src/include/gnunet_signal_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -105,4 +113,6 @@ GNUNET_SIGNAL_raise (const int sig);
105 113
106/** @} */ /* end of group */ 114/** @} */ /* end of group */
107 115
116/** @} */ /* end of group addition */
117
108/* end of gnunet_signal_lib.h */ 118/* end of gnunet_signal_lib.h */
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 7c0c1d104..6ec30bf71 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2012-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -17,250 +17,238 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20#ifndef GNUNET_SIGNATURES_H
21#define GNUNET_SIGNATURES_H
20 22
21/** 23/**
22 * @author Christian Grothoff 24 * WARNING:
23 * 25 * This header is generated!
24 * @file 26 * In order to add a signature purpose, you must register
25 * Constants for network signatures 27 * them in GANA, and then use the header generation script
26 * 28 * to create an update of this file. You may then replace this
27 * @defgroup signatures Network signature definitions 29 * file with the update.
28 * @{
29 */ 30 */
30 31
31#ifndef GNUNET_SIGNATURES_H 32
32#define GNUNET_SIGNATURES_H
33 33
34#ifdef __cplusplus 34#ifdef __cplusplus
35extern "C" 35extern "C" {
36{ 36#if 0 /* keep Emacsens' auto-indent happy */
37#if 0 /* keep Emacsens' auto-indent happy */
38} 37}
39#endif 38#endif
40#endif 39#endif
41 40
41
42/** 42/**
43 * Test signature, not valid for anything other than writing 43 * Network signature purpose definitions. Note that all values
44 * a test. (Note that the signature verification code will 44 * must be uint32_t and encoded in network byte order in the structs.
45 * accept this value). 45 */
46
47
48
49/**
50 * Test signature, not valid for anything other than writing a test. (Note that the signature verification code will accept this value). (GNUnet)
46 */ 51 */
47#define GNUNET_SIGNATURE_PURPOSE_TEST 0 52#define GNUNET_SIGNATURE_PURPOSE_TEST 0
48 53
54
49/** 55/**
50 * Signature for confirming that this peer uses a particular address. 56 * Signature for confirming that this peer uses a particular address. (GNUnet-TRANSPORT)
51 */ 57 */
52#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1 58#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1
53 59
60
54/** 61/**
55 * Signature for confirming that this peer intends to disconnect. 62 * Signature for confirming that this peer intends to disconnect. (GNUnet-TRANSPORT)
56 */ 63 */
57#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2 64#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2
58 65
66
59/** 67/**
60 * Signature for confirming a key revocation. 68 * GNS zone key revocation (GNS)
61 */ 69 */
62#define GNUNET_SIGNATURE_PURPOSE_REVOCATION 3 70#define GNUNET_SIGNATURE_PURPOSE_GNS_REVOCATION 3
71
63 72
64/** 73/**
65 * Signature for a namespace/pseudonym advertisement (by 74 * Signature for a namespace/pseudonym advertisement (by the namespace owner). (GNUnet-FS)
66 * the namespace owner).
67 */ 75 */
68#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4 76#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4
69 77
78
70/** 79/**
71 * Signature by which a peer affirms that it is 80 * Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation URIs. (GNUnet-FS)
72 * providing a certain bit of content (used
73 * in LOCation URIs).
74 */ 81 */
75#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5 82#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5
76 83
77/**
78 * Obsolete, legacy value.
79 */
80#define GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK 6
81 84
82/** 85/**
83 * Obsolete, legacy value. 86 * Signature by which a peer affirms that it forwarded a message in the DHT. (GNUnet-DHT)
84 */ 87 */
85#define GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK 7 88#define GNUNET_SIGNATURE_PURPOSE_DHT_HOP 6
86 89
87/**
88 * Obsolete, legacy value.
89 */
90#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK 8
91 90
92/** 91/**
93 * Obsolete, legacy value. 92 * Signature by which a peer affirms its address. (GNUnet-HELLO)
94 */ 93 */
95#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG 9 94#define GNUNET_SIGNATURE_PURPOSE_HELLO 7
96 95
97/**
98 *
99 */
100#define GNUNET_SIGNATURE_PURPOSE_RESOLVER_RESPONSE 10
101 96
102/** 97/**
103 * Signature of an GNUNET_DNS_Advertisement 98 * Signature on a GNUNET_DNS_Advertisement. (GNUnet-DNS+Exit)
104 */ 99 */
105#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11 100#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11
106 101
102
107/** 103/**
108 * Signature of a chat message. 104 * Signature of a chat message. (GNUnet-MESSENGER)
109 */ 105 */
110#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12 106#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12
111 107
108
112/** 109/**
113 * Signature of confirmation receipt for a chat message. 110 * Signature of confirmation receipt for a chat message. (GNUnet-MESSENGER)
114 */ 111 */
115#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13 112#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13
116 113
114
117/** 115/**
118 * Signature of a network size estimate message. 116 * Signature of a network size estimate message. (GNUnet-NSE)
119 */ 117 */
120#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14 118#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14
121 119
120
122/** 121/**
123 * Signature of a gnunet naming system record block 122 * GNS record set signature (GNS)
124 */ 123 */
125#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15 124#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15
126 125
126
127/** 127/**
128 * Purpose is to set a session key. 128 * Purpose is to set a session key. (GNUnet-CORE)
129 */ 129 */
130#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16 130#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16
131 131
132
132/** 133/**
133 * UBlock Signature, done using DSS, not ECC 134 * UBlock Signature, done using DSS, not ECC (GNUnet-FS)
134 */ 135 */
135#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17 136#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17
136 137
138
137/** 139/**
138 * Accept state in regex DFA. Peer affirms that 140 * Accept state in regex DFA. Peer affirms that it offers the matching service. (GNUnet-REGEX)
139 * it offers the matching service.
140 */ 141 */
141#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18 142#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18
142 143
143/**
144 * Signature of a multicast message sent by the origin.
145 */
146#define GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE 19
147 144
148/** 145/**
149 * Signature of a conversation ring. 146 * Signature of a conversation ring. (GNUnet-CONVERSATION)
150 */ 147 */
151#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20 148#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20
152 149
150
153/** 151/**
154 * Signature for the first round of distributed key generation. 152 * Signature for the first round of distributed key generation. (GNUnet-SECRETSHARING)
155 */ 153 */
156#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21 154#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21
157 155
158/**
159 * Signature for the second round of distributed key generation.
160 */
161#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
162 156
163/** 157/**
164 * Signature for cooperatice decryption. 158 * Signature for the second round of distributed key generation. (GNUnet-SECRETSHARING)
165 */ 159 */
166#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DECRYPTION 23 160#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
167 161
168/**
169 * Signature of a multicast request sent by a member.
170 */
171#define GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST 24
172 162
173/** 163/**
174 * Signature for a sensor anomaly report message. 164 * Signature for the cooperative decryption. (GNUnet-SECRETSHARING)
175 */ 165 */
176#define GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT 25 166#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DECRYPTION 23
177 167
178/**
179 * Signature for a GNUid Token
180 */
181#define GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN 26
182 168
183/** 169/**
184 * Signature for a GNUid Ticket 170 * Signature for a GNUid Ticket (Reclaim)
185 */ 171 */
186#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27 172#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27
187 173
174
188/** 175/**
189 * Signature for a GNUnet credential 176 * Signature for a GNUnet credential (Reclaim)
190 */ 177 */
191#define GNUNET_SIGNATURE_PURPOSE_DELEGATE 28 178#define GNUNET_SIGNATURE_PURPOSE_DELEGATE 28
192 179
180
193/** 181/**
194 * Signature by a peer affirming that this is one of its 182 * Signature by a peer affirming that this is one of its addresses for the given time period. (GNUnet-TRANSPORT)
195 * addresses (for the given time period).
196 */ 183 */
197#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29 184#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29
198 185
186
199/** 187/**
200 * Signature by a peer affirming that the given ephemeral 188 * Signature by a peer affirming that the given ephemeral key is currently in use by that peer's transport service. (GNUnet-TRANSPORT)
201 * key is currently in use by that peer's transport service.
202 */ 189 */
203#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30 190#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30
204 191
192
205/** 193/**
206 * Signature used by TCP communicator handshake, 194 * Signature used by TCP communicator handshake. (GNUnet-TRANSPORT-TCP)
207 */ 195 */
208#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE 31 196#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE 31
197
209 198
210/** 199/**
211 * Signature used by TCP communicator rekey. 200 * Signature used by TCP communicator rekey. (GNUnet-TRANSPORT-TCP)
212 */ 201 */
213#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY 32 202#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY 32
203
214 204
215/** 205/**
216 * Signature used by UDP communicator handshake 206 * Signature used by UDP communicator handshake. (GNUnet-TRANSPORT-UDP)
217 */ 207 */
218#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE 33 208#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE 33
209
219 210
220/** 211/**
221 * Signature used by UDP broadcasts. 212 * Signature used by UDP broadcasts. (GNUnet-TRANSPORT-UDP)
222 */ 213 */
223#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST 34 214#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST 34
215
224 216
225/** 217/**
226 * Signature by a peer affirming that it received a 218 * Signature by a peer affirming that it received a challenge (and stating how long it expects the address on which the challenge was received to remain valid). (GNUnet-TRANSPORT)
227 * challenge (and stating how long it expects the
228 * address on which the challenge was received to
229 * remain valid).
230 */ 219 */
231#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 35 220#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 35
232 221
222
233/** 223/**
234 * Signature by a peer affirming that it is on a DV path. 224 * Signature by a peer affirming that it is on a DV path. (GNUnet-TRANSPORT)
235 */ 225 */
236#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 36 226#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 36
237 227
228
238/** 229/**
239 * Signature by a peer affirming that it originated the 230 * Signature by a peer affirming that it originated the DV path. (GNUnet-TRANSPORT)
240 * DV path.
241 */ 231 */
242#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37 232#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37
243 233
234
244/** 235/**
245 * Signature by a peer that like to create a connection. 236 * Signature by a peer that like to create a connection. (GNUnet-CADET)
246 */ 237 */
247#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38 238#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38
248 239
240
249/** 241/**
250 * Signature by a peer sending back the nonce received at initial handshake. 242 * Signature by a peer sending back the nonce received at initial handshake. (GNUnet-TRANSPORT-TCP)
251 */ 243 */
252#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK 39 244#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK 39
253 245
254#if 0 /* keep Emacsens' auto-indent happy */ 246
247#if 0 /* keep Emacsens' auto-indent happy */
255{ 248{
256#endif 249#endif
257#ifdef __cplusplus 250#ifdef __cplusplus
258} 251}
259#endif 252#endif
260 253
261/* ifndef GNUNET_SIGNATURES_H */
262#endif 254#endif
263
264/** @} */ /* end of group */
265
266/* end of gnunet_signatures.h */
diff --git a/src/include/gnunet_socks.h b/src/include/gnunet_socks.h
index 1a6ae1119..98a27cd1a 100644
--- a/src/include/gnunet_socks.h
+++ b/src/include/gnunet_socks.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * @{
24 *
22 * @author Jeffrey Burdges 25 * @author Jeffrey Burdges
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44 48
45 49
@@ -81,4 +85,6 @@ GNUNET_SOCKS_do_connect (const char *service_name,
81 85
82/** @} */ /* end of group */ 86/** @} */ /* end of group */
83 87
88/** @} */ /* end of group addition to libgnunetutil */
89
84/* end of gnunet_socks.h */ 90/* end of gnunet_socks.h */
diff --git a/src/include/gnunet_speaker_lib.h b/src/include/gnunet_speaker_lib.h
index 71a7c2166..c6bb128dd 100644
--- a/src/include/gnunet_speaker_lib.h
+++ b/src/include/gnunet_speaker_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_util_lib.h" 48#include "gnunet_util_lib.h"
45 49
46/** 50/**
@@ -142,4 +146,6 @@ GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker);
142 146
143/** @} */ /* end of group */ 147/** @} */ /* end of group */
144 148
149/** @} */ /* end of group addition */
150
145/* end of gnunet_speaker_lib.h */ 151/* end of gnunet_speaker_lib.h */
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index 21ce5b393..b84e6759a 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_SQ_LIB_H 25#ifndef GNUNET_SQ_LIB_H
26#define GNUNET_SQ_LIB_H 26#define GNUNET_SQ_LIB_H
27 27
28
28#include <sqlite3.h> 29#include <sqlite3.h>
29#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
30 31
@@ -40,7 +41,7 @@
40 * so immediately suitable for passing to `sqlite3_bind`-functions. 41 * so immediately suitable for passing to `sqlite3_bind`-functions.
41 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 42 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
42 */ 43 */
43typedef int 44typedef enum GNUNET_GenericReturnValue
44(*GNUNET_SQ_QueryConverter)(void *cls, 45(*GNUNET_SQ_QueryConverter)(void *cls,
45 const void *data, 46 const void *data,
46 size_t data_len, 47 size_t data_len,
@@ -91,7 +92,7 @@ struct GNUNET_SQ_QueryParam
91 * @a ptr_size bytes. 92 * @a ptr_size bytes.
92 * 93 *
93 * @param ptr pointer to the query parameter to pass 94 * @param ptr pointer to the query parameter to pass
94 * @oaran ptr_size number of bytes in @a ptr 95 * @param ptr_size number of bytes in @a ptr
95 */ 96 */
96struct GNUNET_SQ_QueryParam 97struct GNUNET_SQ_QueryParam
97GNUNET_SQ_query_param_fixed_size (const void *ptr, 98GNUNET_SQ_query_param_fixed_size (const void *ptr,
@@ -156,8 +157,8 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
156 * @param x pointer to the query parameter to pass 157 * @param x pointer to the query parameter to pass
157 */ 158 */
158struct GNUNET_SQ_QueryParam 159struct GNUNET_SQ_QueryParam
159GNUNET_SQ_query_param_absolute_time_nbo (const struct 160GNUNET_SQ_query_param_absolute_time_nbo (
160 GNUNET_TIME_AbsoluteNBO *x); 161 const struct GNUNET_TIME_AbsoluteNBO *x);
161 162
162 163
163/** 164/**
@@ -194,7 +195,7 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x);
194 * @param params parameters to the statement 195 * @param params parameters to the statement
195 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 196 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
196 */ 197 */
197int 198enum GNUNET_GenericReturnValue
198GNUNET_SQ_bind (sqlite3_stmt *stmt, 199GNUNET_SQ_bind (sqlite3_stmt *stmt,
199 const struct GNUNET_SQ_QueryParam *params); 200 const struct GNUNET_SQ_QueryParam *params);
200 201
@@ -222,7 +223,7 @@ GNUNET_SQ_reset (sqlite3 *dbh,
222 * #GNUNET_YES if all results could be extracted 223 * #GNUNET_YES if all results could be extracted
223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 224 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
224 */ 225 */
225typedef int 226typedef enum GNUNET_GenericReturnValue
226(*GNUNET_SQ_ResultConverter)(void *cls, 227(*GNUNET_SQ_ResultConverter)(void *cls,
227 sqlite3_stmt *result, 228 sqlite3_stmt *result,
228 unsigned int column, 229 unsigned int column,
@@ -436,7 +437,7 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
436 * #GNUNET_OK if all results could be extracted 437 * #GNUNET_OK if all results could be extracted
437 * #GNUNET_SYSERR if a result was invalid (non-existing field) 438 * #GNUNET_SYSERR if a result was invalid (non-existing field)
438 */ 439 */
439int 440enum GNUNET_GenericReturnValue
440GNUNET_SQ_extract_result (sqlite3_stmt *result, 441GNUNET_SQ_extract_result (sqlite3_stmt *result,
441 struct GNUNET_SQ_ResultSpec *rs); 442 struct GNUNET_SQ_ResultSpec *rs);
442 443
@@ -498,7 +499,7 @@ GNUNET_SQ_make_prepare (const char *sql,
498 * @param ps array of statements to prepare 499 * @param ps array of statements to prepare
499 * @return #GNUNET_OK on success 500 * @return #GNUNET_OK on success
500 */ 501 */
501int 502enum GNUNET_GenericReturnValue
502GNUNET_SQ_prepare (sqlite3 *dbh, 503GNUNET_SQ_prepare (sqlite3 *dbh,
503 const struct GNUNET_SQ_PrepareStatement *ps); 504 const struct GNUNET_SQ_PrepareStatement *ps);
504 505
@@ -520,7 +521,7 @@ struct GNUNET_SQ_ExecuteStatement
520 /** 521 /**
521 * Should we ignore errors? 522 * Should we ignore errors?
522 */ 523 */
523 int ignore_errors; 524 bool ignore_errors;
524}; 525};
525 526
526 527
@@ -560,7 +561,7 @@ GNUNET_SQ_make_try_execute (const char *sql);
560 * @return #GNUNET_OK on success (modulo statements where errors can be ignored) 561 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
561 * #GNUNET_SYSERR on error 562 * #GNUNET_SYSERR on error
562 */ 563 */
563int 564enum GNUNET_GenericReturnValue
564GNUNET_SQ_exec_statements (sqlite3 *dbh, 565GNUNET_SQ_exec_statements (sqlite3 *dbh,
565 const struct GNUNET_SQ_ExecuteStatement *es); 566 const struct GNUNET_SQ_ExecuteStatement *es);
566 567
diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h
index 20e958865..0fe09e69a 100644
--- a/src/include/gnunet_statistics_service.h
+++ b/src/include/gnunet_statistics_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -47,6 +50,7 @@ extern "C"
47#endif 50#endif
48#endif 51#endif
49 52
53
50#include "gnunet_util_lib.h" 54#include "gnunet_util_lib.h"
51 55
52/** 56/**
@@ -227,4 +231,6 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
227 231
228/** @} */ /* end of group statistics */ 232/** @} */ /* end of group statistics */
229 233
234/** @} */ /* end of group addition */
235
230#endif 236#endif
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 977c2ead7..df70c5e8f 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Krista Bennett 31 * @author Krista Bennett
24 * @author Gerd Knorr <kraxel@bytesex.org> 32 * @author Gerd Knorr <kraxel@bytesex.org>
@@ -33,6 +41,10 @@
33 * @{ 41 * @{
34 */ 42 */
35 43
44#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
45#error "Only <gnunet_util_lib.h> can be included directly."
46#endif
47
36#ifndef GNUNET_STRINGS_LIB_H 48#ifndef GNUNET_STRINGS_LIB_H
37#define GNUNET_STRINGS_LIB_H 49#define GNUNET_STRINGS_LIB_H
38 50
@@ -40,6 +52,7 @@
40 or unsigned long long, this IS platform dependent; 52 or unsigned long long, this IS platform dependent;
41 but "stdlib.h" should be portable 'enough' to be 53 but "stdlib.h" should be portable 'enough' to be
42 unconditionally available... */ 54 unconditionally available... */
55
43#include <stdlib.h> 56#include <stdlib.h>
44#include <sys/socket.h> 57#include <sys/socket.h>
45#include <netinet/in.h> 58#include <netinet/in.h>
@@ -63,7 +76,7 @@ extern "C"
63 * @param size set to the size in bytes 76 * @param size set to the size in bytes
64 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
65 */ 78 */
66int 79enum GNUNET_GenericReturnValue
67GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 80GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
68 unsigned long long *size); 81 unsigned long long *size);
69 82
@@ -76,7 +89,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
76 * @param rtime set to the relative time 89 * @param rtime set to the relative time
77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
78 */ 91 */
79int 92enum GNUNET_GenericReturnValue
80GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 93GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
81 struct GNUNET_TIME_Relative *rtime); 94 struct GNUNET_TIME_Relative *rtime);
82 95
@@ -91,12 +104,27 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
91 * @param atime set to the absolute time 104 * @param atime set to the absolute time
92 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
93 */ 106 */
94int 107enum GNUNET_GenericReturnValue
95GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 108GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
96 struct GNUNET_TIME_Absolute *atime); 109 struct GNUNET_TIME_Absolute *atime);
97 110
98 111
99/** 112/**
113 * @ingroup time
114 * Convert a given fancy human-readable time to our internal
115 * representation. The human-readable time is expected to be
116 * in local time, whereas the returned value will be in UTC.
117 *
118 * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S)
119 * @param atime set to the absolute time
120 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
121 */
122enum GNUNET_GenericReturnValue
123GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
124 struct GNUNET_TIME_Timestamp *atime);
125
126
127/**
100 * Convert a given filesize into a fancy human-readable format. 128 * Convert a given filesize into a fancy human-readable format.
101 * 129 *
102 * @param size number of bytes 130 * @param size number of bytes
@@ -143,6 +171,16 @@ GNUNET_STRINGS_to_utf8 (const char *input,
143 171
144 172
145/** 173/**
174 * Normalize the utf-8 input string to NFC.
175 *
176 * @param input input string
177 * @return result (freshly allocated) or NULL on error.
178 */
179char*
180GNUNET_STRINGS_utf8_normalize (const char *input);
181
182
183/**
146 * Convert the len bytes-long UTF-8 string 184 * Convert the len bytes-long UTF-8 string
147 * given in input to the given charset. 185 * given in input to the given charset.
148 * 186 *
@@ -165,8 +203,9 @@ GNUNET_STRINGS_from_utf8 (const char *input,
165 * 203 *
166 * @param input input string 204 * @param input input string
167 * @param output output buffer 205 * @param output output buffer
206 * @return GNUNET_OK on success
168 */ 207 */
169void 208enum GNUNET_GenericReturnValue
170GNUNET_STRINGS_utf8_tolower (const char *input, 209GNUNET_STRINGS_utf8_tolower (const char *input,
171 char *output); 210 char *output);
172 211
@@ -177,8 +216,9 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
177 * 216 *
178 * @param input input string 217 * @param input input string
179 * @param output output buffer 218 * @param output output buffer
219 * @return #GNUNET_OK on success
180 */ 220 */
181void 221enum GNUNET_GenericReturnValue
182GNUNET_STRINGS_utf8_toupper (const char *input, 222GNUNET_STRINGS_utf8_toupper (const char *input,
183 char *output); 223 char *output);
184 224
@@ -370,15 +410,19 @@ GNUNET_STRINGS_base64_encode (const void *in,
370/** 410/**
371 * url/percent encode (RFC3986). 411 * url/percent encode (RFC3986).
372 * 412 *
413 * FIXME: awkward API, @a len is not actually used
414 * @a out is 0-terminated, should probably be changed
415 * to only input @a data and directly return @out or NULL.
416 *
373 * @param data the data to decode 417 * @param data the data to decode
374 * @param len the length of the input 418 * @param len the length of the input
375 * @param output where to write the output (*output should be NULL, 419 * @param out where to write the output (*out should be NULL,
376 * is allocated) 420 * is allocated)
377 * @return the size of the output 421 * @return the size of the output
378 */ 422 */
379size_t 423size_t
380GNUNET_STRINGS_urlencode (const char *data, 424GNUNET_STRINGS_urlencode (size_t len,
381 size_t len, 425 const char data[static len],
382 char **out); 426 char **out);
383 427
384 428
@@ -417,7 +461,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
417 * 461 *
418 * @param data the data to decode 462 * @param data the data to decode
419 * @param len the length of the input 463 * @param len the length of the input
420 * @param output where to write the output (*output should be NULL, 464 * @param out where to write the output (*out should be NULL,
421 * is allocated) 465 * is allocated)
422 * @return the size of the output 466 * @return the size of the output
423 */ 467 */
@@ -431,7 +475,7 @@ GNUNET_STRINGS_base64url_decode (const char *data,
431 * 475 *
432 * @param data the data to encode 476 * @param data the data to encode
433 * @param len the length of the input 477 * @param len the length of the input
434 * @param output where to write the output (*output should be NULL, 478 * @param[out] out where to write the output (*output should be NULL,
435 * is allocated) 479 * is allocated)
436 * @return the size of the output 480 * @return the size of the output
437 */ 481 */
@@ -442,18 +486,6 @@ GNUNET_STRINGS_urldecode (const char *data,
442 486
443 487
444/** 488/**
445 * Convert a peer path to a human-readable string.
446 *
447 * @param pids array of PIDs to convert to a string
448 * @param num_pids length of the @a pids array
449 * @return string representing the array of @a pids
450 */
451char *
452GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
453 unsigned int num_pids);
454
455
456/**
457 * Parse a path that might be an URI. 489 * Parse a path that might be an URI.
458 * 490 *
459 * @param path path to parse. Must be NULL-terminated. 491 * @param path path to parse. Must be NULL-terminated.
@@ -550,7 +582,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
550 */ 582 */
551enum GNUNET_GenericReturnValue 583enum GNUNET_GenericReturnValue
552GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 584GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
553 uint16_t addrlen, 585 size_t addrlen,
554 struct sockaddr_in6 *r_buf); 586 struct sockaddr_in6 *r_buf);
555 587
556 588
@@ -566,7 +598,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
566 */ 598 */
567enum GNUNET_GenericReturnValue 599enum GNUNET_GenericReturnValue
568GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 600GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
569 uint16_t addrlen, 601 size_t addrlen,
570 struct sockaddr_in *r_buf); 602 struct sockaddr_in *r_buf);
571 603
572 604
@@ -642,6 +674,23 @@ GNUNET_strlcpy (char *dst,
642 size_t n); 674 size_t n);
643 675
644 676
677/**
678 * Sometimes we use the binary name to determine which specific
679 * test to run. In those cases, the string after the last "_"
680 * in 'argv[0]' specifies a string that determines the configuration
681 * file or plugin to use.
682 *
683 * This function returns the respective substring, taking care
684 * of issues such as binaries ending in '.exe' on W32.
685 *
686 * @param argv0 the name of the binary
687 * @return string between the last '_' and the '.exe' (or the end of the string),
688 * NULL if argv0 has no '_'
689 */
690char *
691GNUNET_STRINGS_get_suffix_from_binary_name (const char *argv0);
692
693
645/* ***************** IPv4/IPv6 parsing ****************** */ 694/* ***************** IPv4/IPv6 parsing ****************** */
646 695
647struct GNUNET_STRINGS_PortPolicy 696struct GNUNET_STRINGS_PortPolicy
@@ -750,4 +799,6 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX);
750 799
751/** @} */ /* end of group */ 800/** @} */ /* end of group */
752 801
802/** @} */ /* end of group addition */
803
753/* end of gnunet_util_string.h */ 804/* end of gnunet_util_string.h */
diff --git a/src/include/gnunet_testbed_logger_service.h b/src/include/gnunet_testbed_logger_service.h
deleted file mode 100644
index 72b5ab364..000000000
--- a/src/include/gnunet_testbed_logger_service.h
+++ /dev/null
@@ -1,133 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 *
24 * @file
25 * API for submitting data to the testbed logger service
26 *
27 * @defgroup testbed-logger Testbed Logger service
28 * Submit data to the testbed logger service.
29 * @{
30 */
31
32#ifndef GNUNET_TESTBED_LOGGER_SERVICE_H
33#define GNUNET_TESTBED_LOGGER_SERVICE_H
34
35#ifdef __cplusplus
36extern "C"
37{
38#if 0 /* keep Emacsens' auto-indent happy */
39}
40#endif
41#endif
42
43#include "gnunet_util_lib.h"
44
45/**
46 * Opaque handle for the logging service
47 */
48struct GNUNET_TESTBED_LOGGER_Handle;
49
50
51/**
52 * Connect to the testbed logger service
53 *
54 * @param cfg configuration to use
55 * @return the handle which can be used for sending data to the service; NULL
56 * upon any error
57 */
58struct GNUNET_TESTBED_LOGGER_Handle *
59GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
60
61
62/**
63 * Disconnect from the logger service. Also cancels any pending send handles.
64 *
65 * @param h the logger handle
66 */
67void
68GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h);
69
70
71/**
72 * Functions of this type are called to notify a successful transmission of the
73 * message to the logger service.
74 *
75 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
76 * @param size the amount of data sent
77 */
78typedef void
79(*GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls,
80 size_t size);
81
82
83/**
84 * Send data to be logged to the logger service. The data will be buffered and
85 * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon
86 * exceeding a threshold size.
87 *
88 * @param h the logger handle
89 * @param data the data to send;
90 * @param size how many bytes of @a data to send
91 */
92void
93GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h,
94 const void *data,
95 size_t size);
96
97
98/**
99 * Flush the buffered data to the logger service
100 *
101 * @param h the logger handle
102 * @param cb the callback to call after the data is flushed
103 * @param cb_cls the closure for @a cb
104 */
105void
106GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
107 GNUNET_TESTBED_LOGGER_FlushCompletion cb,
108 void *cb_cls);
109
110
111/**
112 * Cancel notification upon flush. Should only be used when the flush
113 * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already
114 * called.
115 *
116 * @param h the logger handle
117 */
118void
119GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h);
120
121
122#if 0 /* keep Emacsens' auto-indent happy */
123{
124#endif
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* GNUNET_TESTBED_LOGGER_SERVICE_H */
130
131/** @} */ /* end of group */
132
133/* End of gnunet_testbed_logger_service.h */
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
deleted file mode 100644
index 888c6e391..000000000
--- a/src/include/gnunet_testbed_service.h
+++ /dev/null
@@ -1,1729 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * API for writing tests and creating large-scale emulation testbeds for GNUnet.
26 *
27 * @defgroup testbed Testbed service
28 * Writing tests and creating large-scale emulation testbeds for GNUnet.
29 *
30 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-Subsystem)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TESTBED_SERVICE_H
36#define GNUNET_TESTBED_SERVICE_H
37
38#include "gnunet_util_lib.h"
39#include "gnunet_testing_lib.h"
40
41#ifdef __cplusplus
42extern "C"
43{
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
49
50/**
51 * Opaque handle to a host running experiments managed by the testbed framework.
52 * The master process must be able to SSH to this host without password (via
53 * ssh-agent).
54 */
55struct GNUNET_TESTBED_Host;
56
57/**
58 * Opaque handle to a peer controlled by the testbed framework. A peer runs
59 * at a particular host.
60 */
61struct GNUNET_TESTBED_Peer;
62
63/**
64 * Opaque handle to an abstract operation to be executed by the testbed framework.
65 */
66struct GNUNET_TESTBED_Operation;
67
68/**
69 * Handle to interact with a GNUnet testbed controller. Each
70 * controller has at least one master handle which is created when the
71 * controller is created; this master handle interacts with the
72 * controller process, destroying it destroys the controller (by
73 * closing stdin of the controller process). Additionally,
74 * controllers can interact with each other (in a P2P fashion); those
75 * links are established via TCP/IP on the controller's service port.
76 */
77struct GNUNET_TESTBED_Controller;
78
79
80/**
81 * Create a host to run peers and controllers on.
82 *
83 * @param hostname name of the host, use "NULL" for localhost
84 * @param username username to use for the login; may be NULL
85 * @param cfg the configuration to use as a template while starting a controller
86 * on this host. Operation queue sizes specific to a host are also
87 * read from this configuration handle
88 * @param port port number to use for ssh; use 0 to let ssh decide
89 * @return handle to the host, NULL on error
90 */
91struct GNUNET_TESTBED_Host *
92GNUNET_TESTBED_host_create (const char *hostname,
93 const char *username,
94 const struct GNUNET_CONFIGURATION_Handle *cfg,
95 uint16_t port);
96
97
98/**
99 * Create a host to run peers and controllers on. This function is used
100 * if a peer learns about a host via IPC between controllers (and thus
101 * some higher-level controller has already determined the unique IDs).
102 *
103 * @param id global host ID assigned to the host; 0 is
104 * reserved to always mean 'localhost'
105 * @param hostname name of the host, use "NULL" for localhost
106 * @param username username to use for the login; may be NULL
107 * @param cfg the configuration to use as a template while starting a controller
108 * on this host. Operation queue sizes specific to a host are also
109 * read from this configuration handle
110 * @param port port number to use for ssh; use 0 to let ssh decide
111 * @return handle to the host, NULL on error
112 */
113struct GNUNET_TESTBED_Host *
114GNUNET_TESTBED_host_create_with_id (uint32_t id,
115 const char *hostname,
116 const char *username,
117 const struct GNUNET_CONFIGURATION_Handle
118 *cfg,
119 uint16_t port);
120
121
122/**
123 * Load a set of hosts from a configuration file. The hostfile format is
124 * specified at https://gnunet.org/content/hosts-file-format
125 *
126 * @param filename file with the host specification
127 * @param cfg the configuration to use as a template while starting a controller
128 * on any of the loaded hosts. Operation queue sizes specific to a host
129 * are also read from this configuration handle
130 * @param hosts set to the hosts found in the file; caller must free this if
131 * number of hosts returned is greater than 0
132 * @return number of hosts returned in 'hosts', 0 on error
133 */
134unsigned int
135GNUNET_TESTBED_hosts_load_from_file (const char *filename,
136 const struct GNUNET_CONFIGURATION_Handle
137 *cfg,
138 struct GNUNET_TESTBED_Host ***hosts);
139
140
141/**
142 * Destroy a host handle. Must only be called once everything
143 * running on that host has been stopped.
144 *
145 * @param host handle to destroy
146 */
147void
148GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
149
150
151/**
152 * The handle for whether a host is habitable or not
153 */
154struct GNUNET_TESTBED_HostHabitableCheckHandle;
155
156
157/**
158 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
159 * inform whether the given host is habitable or not. The Handle returned by
160 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
161 *
162 * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
163 * @param host the host whose status is being reported; will be NULL if the host
164 * given to GNUNET_TESTBED_is_host_habitable() is NULL
165 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
166 */
167typedef void
168(*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
169 const struct GNUNET_TESTBED_Host *host,
170 int status);
171
172
173/**
174 * Checks whether a host can be used to start testbed service
175 *
176 * @param host the host to check
177 * @param config the configuration handle to lookup the path of the testbed
178 * helper
179 * @param cb the callback to call to inform about habitability of the given host
180 * @param cb_cls the closure for the callback
181 * @return NULL upon any error or a handle which can be passed to
182 * GNUNET_TESTBED_is_host_habitable_cancel()
183 */
184struct GNUNET_TESTBED_HostHabitableCheckHandle *
185GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
186 const struct GNUNET_CONFIGURATION_Handle
187 *config,
188 GNUNET_TESTBED_HostHabitableCallback cb,
189 void *cb_cls);
190
191
192/**
193 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
194 *
195 * @param handle the habitability check handle
196 */
197void
198GNUNET_TESTBED_is_host_habitable_cancel (struct
199 GNUNET_TESTBED_HostHabitableCheckHandle
200 *handle);
201
202/**
203 * Obtain the host's hostname.
204 *
205 * @param host handle to the host, NULL means 'localhost'
206 * @return hostname of the host
207 */
208const char *
209GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
210
211
212/**
213 * Enumeration with (at most 64) possible event types that
214 * can be monitored using the testbed framework.
215 */
216enum GNUNET_TESTBED_EventType
217{
218 /**
219 * A peer has been started.
220 */
221 GNUNET_TESTBED_ET_PEER_START = 0,
222
223 /**
224 * A peer has been stopped.
225 */
226 GNUNET_TESTBED_ET_PEER_STOP = 1,
227
228 /**
229 * A connection between two peers was established.
230 */
231 GNUNET_TESTBED_ET_CONNECT = 2,
232
233 /**
234 * A connection between two peers was torn down.
235 */
236 GNUNET_TESTBED_ET_DISCONNECT = 3,
237
238 /**
239 * A requested testbed operation has been completed.
240 */
241 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
242};
243
244
245/**
246 * Types of information that can be requested about a peer.
247 */
248enum GNUNET_TESTBED_PeerInformationType
249{
250 /**
251 * Special value (not valid for requesting information)
252 * that is used in the event struct if a 'generic' pointer
253 * is returned (for other operations not related to this
254 * enumeration).
255 */
256 GNUNET_TESTBED_PIT_GENERIC = 0,
257
258 /**
259 * What configuration is the peer using? Returns a 'const struct
260 * GNUNET_CONFIGURATION_Handle *'. Valid until
261 * 'GNUNET_TESTNIG_operation_done' is called. However, the
262 * values may be inaccurate if the peer is reconfigured in
263 * the meantime.
264 */
265 GNUNET_TESTBED_PIT_CONFIGURATION,
266
267 /**
268 * What is the identity of the peer? Returns a
269 * 'const struct GNUNET_PeerIdentity *'. Valid until
270 * 'GNUNET_TESTNIG_operation_done' is called.
271 */
272 GNUNET_TESTBED_PIT_IDENTITY
273};
274
275
276/**
277 * Argument to GNUNET_TESTBED_ControllerCallback with details about
278 * the event.
279 */
280struct GNUNET_TESTBED_EventInformation
281{
282 /**
283 * Type of the event.
284 */
285 enum GNUNET_TESTBED_EventType type;
286
287 /**
288 * Handle for the corresponding operation that generated this event
289 */
290 struct GNUNET_TESTBED_Operation *op;
291
292 /**
293 * Closure given while creating the above operation
294 */
295 void *op_cls;
296
297 /**
298 * Details about the event.
299 */
300 union
301 {
302 /**
303 * Details about peer start event.
304 */
305 struct
306 {
307 /**
308 * Handle for the host where the peer
309 * was started.
310 */
311 struct GNUNET_TESTBED_Host *host;
312
313 /**
314 * Handle for the peer that was started.
315 */
316 struct GNUNET_TESTBED_Peer *peer;
317 } peer_start;
318
319 /**
320 * Details about peer stop event.
321 */
322 struct
323 {
324 /**
325 * Handle for the peer that was started.
326 */
327 struct GNUNET_TESTBED_Peer *peer;
328 } peer_stop;
329
330 /**
331 * Details about connect event.
332 */
333 struct
334 {
335 /**
336 * Handle for one of the connected peers.
337 */
338 struct GNUNET_TESTBED_Peer *peer1;
339
340 /**
341 * Handle for one of the connected peers.
342 */
343 struct GNUNET_TESTBED_Peer *peer2;
344 } peer_connect;
345
346 /**
347 * Details about disconnect event.
348 */
349 struct
350 {
351 /**
352 * Handle for one of the disconnected peers.
353 */
354 struct GNUNET_TESTBED_Peer *peer1;
355
356 /**
357 * Handle for one of the disconnected peers.
358 */
359 struct GNUNET_TESTBED_Peer *peer2;
360 } peer_disconnect;
361
362 /**
363 * Details about an operation finished event.
364 */
365 struct
366 {
367 /**
368 * Error message for the operation, NULL on success.
369 */
370 const char *emsg;
371
372 /**
373 * No result (NULL pointer) or generic result
374 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
375 */
376 void *generic;
377 } operation_finished;
378 } details;
379};
380
381
382/**
383 * Signature of the event handler function called by the
384 * respective event controller.
385 *
386 * @param cls closure
387 * @param event information about the event
388 */
389typedef void
390(*GNUNET_TESTBED_ControllerCallback)(void *cls,
391 const struct
392 GNUNET_TESTBED_EventInformation *event);
393
394
395/**
396 * Opaque Handle for Controller process
397 */
398struct GNUNET_TESTBED_ControllerProc;
399
400
401/**
402 * Callback to signal successful startup of the controller process
403 *
404 * @param cls the closure from GNUNET_TESTBED_controller_start()
405 * @param cfg the configuration with which the controller has been started;
406 * NULL if status is not #GNUNET_OK
407 * @param status #GNUNET_OK if the startup is successful; #GNUNET_SYSERR if not,
408 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
409 */
410typedef void
411(*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
412 const struct
413 GNUNET_CONFIGURATION_Handle *cfg,
414 int status);
415
416
417/**
418 * Starts a controller process at the given host. The given host's configuration
419 * is used as a Template configuration to use for the remote controller; the
420 * remote controller will be started with a slightly modified configuration
421 * (port numbers, unix domain sockets and service home values are changed as per
422 * TESTING library on the remote host). The modified configuration replaces the
423 * host's existing configuration before signalling success through the
424 * GNUNET_TESTBED_ControllerStatusCallback()
425 *
426 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
427 * HOST(all connections form this ip are permitted by the testbed) when
428 * starting testbed controller at host. This can either be a single ip
429 * address or a network address in CIDR notation.
430 * @param host the host where the controller has to be started. CANNOT be NULL.
431 * @param cb function called when the controller is successfully started or
432 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
433 * called if cb is called with GNUNET_SYSERR as status. Will never be
434 * called in the same task as 'GNUNET_TESTBED_controller_start'
435 * (synchronous errors will be signalled by returning NULL). This
436 * parameter cannot be NULL.
437 * @param cls closure for above callbacks
438 * @return the controller process handle, NULL on errors
439 */
440struct GNUNET_TESTBED_ControllerProc *
441GNUNET_TESTBED_controller_start (const char *trusted_ip,
442 struct GNUNET_TESTBED_Host *host,
443 GNUNET_TESTBED_ControllerStatusCallback cb,
444 void *cls);
445
446
447/**
448 * Stop the controller process (also will terminate all peers and controllers
449 * dependent on this controller). This function blocks until the testbed has
450 * been fully terminated (!). The controller status cb from
451 * GNUNET_TESTBED_controller_start() will not be called.
452 *
453 * @param cproc the controller process handle
454 */
455void
456GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
457
458
459/**
460 * Connect to a controller process. The configuration to use for the connection
461 * is retrieved from the given host where a controller is started using
462 * GNUNET_TESTBED_controller_start().
463 *
464 * @param host host to run the controller on; This should be the same host if
465 * the controller was previously started with
466 * GNUNET_TESTBED_controller_start()
467 * @param event_mask bit mask with set of events to call 'cc' for;
468 * or-ed values of "1LL" shifted by the
469 * respective 'enum GNUNET_TESTBED_EventType'
470 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
471 * @param cc controller callback to invoke on events
472 * @param cc_cls closure for cc
473 * @return handle to the controller
474 */
475struct GNUNET_TESTBED_Controller *
476GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
477 uint64_t event_mask,
478 GNUNET_TESTBED_ControllerCallback cc,
479 void *cc_cls);
480
481
482/**
483 * Stop the given controller (also will terminate all peers and
484 * controllers dependent on this controller). This function
485 * blocks until the testbed has been fully terminated (!).
486 *
487 * @param c handle to controller to stop
488 */
489void
490GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
491
492
493/**
494 * Opaque handle for host registration
495 */
496struct GNUNET_TESTBED_HostRegistrationHandle;
497
498
499/**
500 * Callback which will be called to after a host registration succeeded or failed
501 *
502 * @param cls the closure
503 * @param emsg the error message; NULL if host registration is successful
504 */
505typedef void
506(*GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
507 const char *emsg);
508
509
510/**
511 * Register a host with the controller. This makes the controller aware of the
512 * host. A host should be registered at the controller before starting a
513 * sub-controller on that host using GNUNET_TESTBED_controller_link().
514 *
515 * @param controller the controller handle
516 * @param host the host to register
517 * @param cc the completion callback to call to inform the status of
518 * registration. After calling this callback the registration handle
519 * will be invalid. Cannot be NULL
520 * @param cc_cls the closure for the cc
521 * @return handle to the host registration which can be used to cancel the
522 * registration; NULL if another registration handle is present and
523 * is not cancelled
524 */
525struct GNUNET_TESTBED_HostRegistrationHandle *
526GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
527 struct GNUNET_TESTBED_Host *host,
528 GNUNET_TESTBED_HostRegistrationCompletion cc,
529 void *cc_cls);
530
531
532/**
533 * Cancel the pending registration. Note that the registration message will
534 * already be queued to be sent to the service, cancellation has only the
535 * effect that the registration completion callback for the registration is
536 * never called and from our perspective the host is not registered until the
537 * completion callback is called.
538 *
539 * @param handle the registration handle to cancel
540 */
541void
542GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
543 *handle);
544
545
546/**
547 * Callback to be called when an operation is completed
548 *
549 * @param cls the callback closure from functions generating an operation
550 * @param op the operation that has been finished
551 * @param emsg error message in case the operation has failed; will be NULL if
552 * operation has executed successfully.
553 */
554typedef void
555(*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
556 struct GNUNET_TESTBED_Operation *
557 op,
558 const char *emsg);
559
560
561/**
562 * Create a link from slave controller to delegated controller. Whenever the
563 * master controller is asked to start a peer at the delegated controller the
564 * request will be routed towards slave controller (if a route exists). The
565 * slave controller will then route it to the delegated controller. The
566 * configuration of the delegated controller is given and is used to either
567 * create the delegated controller or to connect to an existing controller. Note
568 * that while starting the delegated controller the configuration will be
569 * modified to accommodate available free ports. the 'is_subordinate' specifies
570 * if the given delegated controller should be started and managed by the slave
571 * controller, or if the delegated controller already has a master and the slave
572 * controller connects to it as a non master controller. The success or failure
573 * of this operation will be signalled through the
574 * GNUNET_TESTBED_ControllerCallback() with an event of type
575 * #GNUNET_TESTBED_ET_OPERATION_FINISHED
576 *
577 * @param op_cls the operation closure for the event which is generated to
578 * signal success or failure of this operation
579 * @param master handle to the master controller who creates the association
580 * @param delegated_host requests to which host should be delegated; cannot be NULL
581 * @param slave_host which host is used to run the slave controller; use NULL to
582 * make the master controller connect to the delegated host
583 * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
584 * be started by the slave controller; #GNUNET_NO if the slave
585 * controller has to connect to the already started delegated
586 * controller via TCP/IP
587 * @return the operation handle
588 */
589struct GNUNET_TESTBED_Operation *
590GNUNET_TESTBED_controller_link (void *op_cls,
591 struct GNUNET_TESTBED_Controller *master,
592 struct GNUNET_TESTBED_Host *delegated_host,
593 struct GNUNET_TESTBED_Host *slave_host,
594 int is_subordinate);
595
596
597/**
598 * Function to acquire the configuration of a running slave controller. The
599 * completion of the operation is signalled through the controller_cb from
600 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
601 * handle to the configuration is available in the generic pointer of
602 * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
603 *
604 * @param op_cls the closure for the operation
605 * @param master the handle to master controller
606 * @param slave_host the host where the slave controller is running; the handle
607 * to the slave_host should remain valid until this operation is
608 * cancelled or marked as finished
609 * @return the operation handle; NULL if the slave_host is not registered at
610 * master
611 */
612struct GNUNET_TESTBED_Operation *
613GNUNET_TESTBED_get_slave_config (void *op_cls,
614 struct GNUNET_TESTBED_Controller *master,
615 struct GNUNET_TESTBED_Host *slave_host);
616
617
618/**
619 * Functions of this signature are called when a peer has been successfully
620 * created
621 *
622 * @param cls the closure from GNUNET_TESTBED_peer_create()
623 * @param peer the handle for the created peer; NULL on any error during
624 * creation
625 * @param emsg NULL if peer is not NULL; else MAY contain the error description
626 */
627typedef void
628(*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
629 struct GNUNET_TESTBED_Peer *peer,
630 const char *emsg);
631
632
633/**
634 * Create the given peer at the specified host using the given
635 * controller. If the given controller is not running on the target
636 * host, it should find or create a controller at the target host and
637 * delegate creating the peer. Explicit delegation paths can be setup
638 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
639 * path exists, a direct link with a subordinate controller is setup
640 * for the first delegated peer to a particular host; the subordinate
641 * controller is then destroyed once the last peer that was delegated
642 * to the remote host is stopped.
643 *
644 * Creating the peer only creates the handle to manipulate and further
645 * configure the peer; use #GNUNET_TESTBED_peer_start and
646 * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
647 * processes.
648 *
649 * Note that the given configuration will be adjusted by the
650 * controller to avoid port/path conflicts with other peers.
651 * The "final" configuration can be obtained using
652 * #GNUNET_TESTBED_peer_get_information.
653 *
654 * @param controller controller process to use
655 * @param host host to run the peer on; cannot be NULL
656 * @param cfg Template configuration to use for the peer. Should exist until
657 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
658 * @param cb the callback to call when the peer has been created
659 * @param cls the closure to the above callback
660 * @return the operation handle
661 */
662struct GNUNET_TESTBED_Operation *
663GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
664 struct GNUNET_TESTBED_Host *host,
665 const struct GNUNET_CONFIGURATION_Handle *cfg,
666 GNUNET_TESTBED_PeerCreateCallback cb,
667 void *cls);
668
669
670/**
671 * Functions of this signature are called when a peer has been successfully
672 * started or stopped.
673 *
674 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
675 * @param emsg NULL on success; otherwise an error description
676 */
677typedef void
678(*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
679 const char *emsg);
680
681
682/**
683 * Start the given peer.
684 *
685 * @param op_cls the closure for this operation; will be set in the event
686 * information
687 * @param peer peer to start
688 * @param pcc function to call upon completion
689 * @param pcc_cls closure for 'pcc'
690 * @return handle to the operation
691 */
692struct GNUNET_TESTBED_Operation *
693GNUNET_TESTBED_peer_start (void *op_cls,
694 struct GNUNET_TESTBED_Peer *peer,
695 GNUNET_TESTBED_PeerChurnCallback pcc,
696 void *pcc_cls);
697
698
699/**
700 * Stop the given peer. The handle remains valid (use
701 * #GNUNET_TESTBED_peer_destroy to fully clean up the
702 * state of the peer).
703 *
704 * @param op_cls the closure for this operation; will be set in the event
705 * information
706 * @param peer peer to stop
707 * @param pcc function to call upon completion
708 * @param pcc_cls closure for 'pcc'
709 * @return handle to the operation
710 */
711struct GNUNET_TESTBED_Operation *
712GNUNET_TESTBED_peer_stop (void *op_cls,
713 struct GNUNET_TESTBED_Peer *peer,
714 GNUNET_TESTBED_PeerChurnCallback pcc,
715 void *pcc_cls);
716
717
718/**
719 * Data returned from GNUNET_TESTBED_peer_get_information
720 */
721struct GNUNET_TESTBED_PeerInformation
722{
723 /**
724 * Peer information type; captures which of the types
725 * in the 'op_result' is actually in use.
726 */
727 enum GNUNET_TESTBED_PeerInformationType pit;
728
729 /**
730 * The result of the get information operation; Choose according to the pit
731 */
732 union
733 {
734 /**
735 * The configuration of the peer
736 */
737 struct GNUNET_CONFIGURATION_Handle *cfg;
738
739 /**
740 * The identity of the peer
741 */
742 struct GNUNET_PeerIdentity *id;
743 } result;
744};
745
746
747/**
748 * Callback to be called when the requested peer information is available
749 * The peer information in the callback is valid until the operation 'op' is canceled.
750 *
751 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
752 * @param op the operation this callback corresponds to
753 * @param pinfo the result; will be NULL if the operation has failed
754 * @param emsg error message if the operation has failed; will be NULL if the
755 * operation is successful
756 */
757typedef void
758(*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
759 struct GNUNET_TESTBED_Operation *op,
760 const struct
761 GNUNET_TESTBED_PeerInformation *pinfo,
762 const char *emsg);
763
764
765/**
766 * Request information about a peer. The controller callback will not be called
767 * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
768 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
769 * be called.
770 * The peer information in the callback is valid until the operation is canceled.
771 *
772 * @param peer peer to request information about
773 * @param pit desired information
774 * @param cb the convenience callback to be called when results for this
775 * operation are available
776 * @param cb_cls the closure for @a cb
777 * @return handle to the operation
778 */
779struct GNUNET_TESTBED_Operation *
780GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
781 enum GNUNET_TESTBED_PeerInformationType
782 pit,
783 GNUNET_TESTBED_PeerInfoCallback cb,
784 void *cb_cls);
785
786
787/**
788 * Change @a peer configuration. Ports and paths cannot be changed this
789 * way.
790 *
791 * @param peer peer to change configuration for
792 * @param cfg new configuration
793 * @return handle to the operation
794 */
795struct GNUNET_TESTBED_Operation *
796GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
797 const struct
798 GNUNET_CONFIGURATION_Handle *cfg);
799
800
801/**
802 * Destroy the given peer; the peer should have been
803 * stopped first (if it was started).
804 *
805 * @param peer peer to stop
806 * @return handle to the operation
807 */
808struct GNUNET_TESTBED_Operation *
809GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
810
811
812/**
813 * Start or stop given service at a peer. This should not be called to
814 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
815 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
816 * or failure of the generated operation is signalled through the controller
817 * event callback and/or operation completion callback.
818 *
819 * @param op_cls the closure for the operation
820 * @param peer the peer whose service is to be started/stopped
821 * @param service_name the name of the service
822 * @param cb the operation completion callback
823 * @param cb_cls the closure for @a cb
824 * @param start 1 to start the service; 0 to stop the service
825 * @return an operation handle; NULL upon error (peer not running)
826 */
827struct GNUNET_TESTBED_Operation *
828GNUNET_TESTBED_peer_manage_service (void *op_cls,
829 struct GNUNET_TESTBED_Peer *peer,
830 const char *service_name,
831 GNUNET_TESTBED_OperationCompletionCallback
832 cb,
833 void *cb_cls,
834 unsigned int start);
835
836
837/**
838 * Stops and destroys all peers. Is equivalent of calling
839 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
840 * except that the peer stop event and operation finished event corresponding to
841 * the respective functions are not generated. This function should be called
842 * when there are no other pending operations. If there are pending operations,
843 * it will return NULL
844 *
845 * @param c the controller to send this message to
846 * @param op_cls closure for the operation
847 * @param cb the callback to call when all peers are stopped and destroyed
848 * @param cb_cls the closure for the callback
849 * @return operation handle on success; NULL if any pending operations are
850 * present
851 */
852struct GNUNET_TESTBED_Operation *
853GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
854 void *op_cls,
855 GNUNET_TESTBED_OperationCompletionCallback cb,
856 void *cb_cls);
857
858
859/**
860 * Options for peer connections.
861 */
862enum GNUNET_TESTBED_ConnectOption
863{
864 /**
865 * No option (not valid as an argument).
866 */
867 GNUNET_TESTBED_CO_NONE = 0,
868
869 /**
870 * Allow or disallow a connection between the specified peers.
871 * Followed by #GNUNET_NO (int) if a connection is disallowed
872 * or #GNUNET_YES if a connection is allowed. Note that the
873 * default (all connections allowed or disallowed) is
874 * specified in the configuration of the controller.
875 */
876 GNUNET_TESTBED_CO_ALLOW = 1,
877
878 /**
879 * FIXME: add (and implement) options to limit connection to
880 * particular transports, force simulation of particular latencies
881 * or message loss rates, or set bandwidth limitations.
882 */
883};
884
885
886/**
887 * Manipulate the P2P underlay topology by configuring a link
888 * between two peers.
889 *
890 * @param op_cls closure argument to give with the operation event
891 * @param p1 first peer
892 * @param p2 second peer
893 * @param co option to change
894 * @param ap option-specific values
895 * @return handle to the operation, NULL if configuring the link at this
896 * time is not allowed
897 */
898struct GNUNET_TESTBED_Operation *
899GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
900 struct GNUNET_TESTBED_Peer *p1,
901 struct GNUNET_TESTBED_Peer *p2,
902 enum GNUNET_TESTBED_ConnectOption co,
903 va_list ap);
904
905
906/**
907 * Manipulate the P2P underlay topology by configuring a link
908 * between two peers.
909 *
910 * @param op_cls closure argument to give with the operation event
911 * @param p1 first peer
912 * @param p2 second peer
913 * @param co option to change
914 * @param ... option-specific values
915 * @return handle to the operation, NULL if configuring the link at this
916 * time is not allowed
917 */
918struct GNUNET_TESTBED_Operation *
919GNUNET_TESTBED_underlay_configure_link (void *op_cls,
920 struct GNUNET_TESTBED_Peer *p1,
921 struct GNUNET_TESTBED_Peer *p2,
922 enum GNUNET_TESTBED_ConnectOption co,
923 ...);
924
925
926/**
927 * Topologies and topology options supported for testbeds. Options should always
928 * end with #GNUNET_TESTBED_TOPOLOGY_OPTION_END
929 */
930enum GNUNET_TESTBED_TopologyOption
931{
932 /**
933 * A clique (everyone connected to everyone else). No options. If there are N
934 * peers this topology results in (N * (N -1)) connections.
935 */
936 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
937
938 /**
939 * Small-world network (2d torus plus random links). Followed
940 * by the number of random links to add (unsigned int).
941 */
942 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
943
944 /**
945 * Small-world network (ring plus random links). Followed
946 * by the number of random links to add (unsigned int).
947 */
948 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
949
950 /**
951 * Ring topology. No options.
952 */
953 GNUNET_TESTBED_TOPOLOGY_RING,
954
955 /**
956 * Star topology. No options.
957 */
958 GNUNET_TESTBED_TOPOLOGY_STAR,
959
960 /**
961 * 2-d torus. No options.
962 */
963 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
964
965 /**
966 * Random graph. Followed by the number of random links to be established
967 * (unsigned int)
968 */
969 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
970
971 /**
972 * Certain percentage of peers are unable to communicate directly
973 * replicating NAT conditions. Followed by the fraction of
974 * NAT'ed peers (float).
975 */
976 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
977
978 /**
979 * Scale free topology. It is generated according to the method described in
980 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
981 *
982 * This options takes two arguments in the following order: an uint16_t to
983 * determine the maximum number of edges a peer is permitted to have while
984 * generating scale free topology, a good value for this argument is 70; and
985 * an uint8_t to determine the number of edges to be established when adding a
986 * new node to the scale free network, a good value for this argument is 4.
987 */
988 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
989
990 /**
991 * Straight line topology. No options.
992 */
993 GNUNET_TESTBED_TOPOLOGY_LINE,
994
995 /**
996 * Read a topology from a given file. Followed by the name of the file (const char *).
997 */
998 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
999
1000 /**
1001 * All peers are disconnected. No options.
1002 */
1003 GNUNET_TESTBED_TOPOLOGY_NONE,
1004
1005 /**
1006 * The options should always end with this
1007 */
1008 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1009
1010 /* The following are not topologies but influence how the topology has to be
1011 setup. These options should follow the topology specific options (if
1012 required by the chosen topology). Note that these should be given before
1013 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1014
1015 /**
1016 * How many times should the failed overlay connect operations be retried
1017 * before giving up. The default if this option is not specified is to retry
1018 * 3 times. This option takes and unsigned integer as a parameter. Use this
1019 * option with parameter 0 to disable retrying of failed overlay connect
1020 * operations.
1021 */
1022 GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1023};
1024
1025
1026/**
1027 * Configure overall network topology to have a particular shape.
1028 *
1029 * @param op_cls closure argument to give with the operation event
1030 * @param num_peers number of peers in 'peers'
1031 * @param peers array of 'num_peers' with the peers to configure
1032 * @param topo desired underlay topology to use
1033 * @param ap topology-specific options
1034 * @return handle to the operation, NULL if configuring the topology
1035 * is not allowed at this time
1036 */
1037struct GNUNET_TESTBED_Operation *
1038GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1039 unsigned int num_peers,
1040 struct GNUNET_TESTBED_Peer **
1041 peers,
1042 enum
1043 GNUNET_TESTBED_TopologyOption
1044 topo,
1045 va_list ap);
1046
1047
1048/**
1049 * Configure overall network topology to have a particular shape.
1050 *
1051 * @param op_cls closure argument to give with the operation event
1052 * @param num_peers number of peers in 'peers'
1053 * @param peers array of 'num_peers' with the peers to configure
1054 * @param topo desired underlay topology to use
1055 * @param ... topology-specific options
1056 * @return handle to the operation, NULL if configuring the topology
1057 * is not allowed at this time
1058 */
1059struct GNUNET_TESTBED_Operation *
1060GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1061 unsigned int num_peers,
1062 struct GNUNET_TESTBED_Peer **peers,
1063 enum GNUNET_TESTBED_TopologyOption
1064 topo,
1065 ...);
1066
1067
1068/**
1069 * Both peers must have been started before calling this function.
1070 * This function then obtains a HELLO from @a p1, gives it to @a p2
1071 * and asks @a p2 to connect to @a p1.
1072 *
1073 * @param op_cls closure argument to give with the operation event
1074 * @param cb the callback to call when this operation has finished
1075 * @param cb_cls the closure for @a cb
1076 * @param p1 first peer
1077 * @param p2 second peer
1078 * @return handle to the operation, NULL if connecting these two
1079 * peers is fundamentally not possible at this time (peers
1080 * not running or underlay disallows)
1081 */
1082struct GNUNET_TESTBED_Operation *
1083GNUNET_TESTBED_overlay_connect (void *op_cls,
1084 GNUNET_TESTBED_OperationCompletionCallback cb,
1085 void *cb_cls,
1086 struct GNUNET_TESTBED_Peer *p1,
1087 struct GNUNET_TESTBED_Peer *p2);
1088
1089
1090/**
1091 * Callbacks of this type are called when topology configuration is completed
1092 *
1093 * @param cls the operation closure given to
1094 * GNUNET_TESTBED_overlay_configure_topology_va() and
1095 * GNUNET_TESTBED_overlay_configure() calls
1096 * @param nsuccess the number of successful overlay connects
1097 * @param nfailures the number of overlay connects which failed
1098 */
1099typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1100 unsigned int
1101 nsuccess,
1102 unsigned int
1103 nfailures);
1104
1105
1106/**
1107 * All peers must have been started before calling this function.
1108 * This function then connects the given peers in the P2P overlay
1109 * using the given topology.
1110 *
1111 * @param op_cls closure argument to give with the peer connect operation events
1112 * generated through this function
1113 * @param num_peers number of peers in 'peers'
1114 * @param peers array of 'num_peers' with the peers to configure
1115 * @param max_connections the maximums number of overlay connections that will
1116 * be made to achieve the given topology
1117 * @param comp_cb the completion callback to call when the topology generation
1118 * is completed
1119 * @param comp_cb_cls closure for the @a comp_cb
1120 * @param topo desired underlay topology to use
1121 * @param va topology-specific options
1122 * @return handle to the operation, NULL if connecting these
1123 * peers is fundamentally not possible at this time (peers
1124 * not running or underlay disallows) or if num_peers is less than 2
1125 */
1126struct GNUNET_TESTBED_Operation *
1127GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1128 unsigned int num_peers,
1129 struct GNUNET_TESTBED_Peer **peers,
1130 unsigned int *max_connections,
1131 GNUNET_TESTBED_TopologyCompletionCallback
1132 comp_cb,
1133 void *comp_cb_cls,
1134 enum GNUNET_TESTBED_TopologyOption
1135 topo,
1136 va_list va);
1137
1138
1139/**
1140 * All peers must have been started before calling this function.
1141 * This function then connects the given peers in the P2P overlay
1142 * using the given topology.
1143 *
1144 * @param op_cls closure argument to give with the peer connect operation events
1145 * generated through this function
1146 * @param num_peers number of peers in 'peers'
1147 * @param peers array of 'num_peers' with the peers to configure
1148 * @param max_connections the maximums number of overlay connections that will
1149 * be made to achieve the given topology
1150 * @param comp_cb the completion callback to call when the topology generation
1151 * is completed
1152 * @param comp_cb_cls closure for the above completion callback
1153 * @param topo desired underlay topology to use
1154 * @param ... topology-specific options
1155 * @return handle to the operation, NULL if connecting these
1156 * peers is fundamentally not possible at this time (peers
1157 * not running or underlay disallows) or if num_peers is less than 2
1158 */
1159struct GNUNET_TESTBED_Operation *
1160GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1161 unsigned int num_peers,
1162 struct GNUNET_TESTBED_Peer **peers,
1163 unsigned int *max_connections,
1164 GNUNET_TESTBED_TopologyCompletionCallback
1165 comp_cb,
1166 void *comp_cb_cls,
1167 enum GNUNET_TESTBED_TopologyOption
1168 topo,
1169 ...);
1170
1171
1172/**
1173 * Ask the testbed controller to write the current overlay topology to
1174 * a file. Naturally, the file will only contain a snapshot as the
1175 * topology may evolve all the time.
1176 * FIXME: needs continuation!?
1177 *
1178 * @param controller overlay controller to inspect
1179 * @param filename name of the file the topology should
1180 * be written to.
1181 */
1182void
1183GNUNET_TESTBED_overlay_write_topology_to_file (struct
1184 GNUNET_TESTBED_Controller *
1185 controller,
1186 const char *filename);
1187
1188
1189/**
1190 * Adapter function called to establish a connection to
1191 * a service.
1192 *
1193 * @param cls closure
1194 * @param cfg configuration of the peer to connect to; will be available until
1195 * GNUNET_TESTBED_operation_done() is called on the operation returned
1196 * from GNUNET_TESTBED_service_connect()
1197 * @return service handle to return in 'op_result', NULL on error
1198 */
1199typedef void *
1200(*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1201 const struct GNUNET_CONFIGURATION_Handle *cfg);
1202
1203
1204/**
1205 * Adapter function called to destroy a connection to
1206 * a service.
1207 *
1208 * @param cls closure
1209 * @param op_result service handle returned from the connect adapter
1210 */
1211typedef void
1212(*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1213 void *op_result);
1214
1215
1216/**
1217 * Callback to be called when a service connect operation is completed
1218 *
1219 * @param cls the callback closure from functions generating an operation
1220 * @param op the operation that has been finished
1221 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1222 * @param emsg error message in case the operation has failed; will be NULL if
1223 * operation has executed successfully.
1224 */
1225typedef void
1226(*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1227 struct
1228 GNUNET_TESTBED_Operation *op,
1229 void *ca_result,
1230 const char *emsg);
1231
1232
1233/**
1234 * Connect to a service offered by the given peer. Will ensure that
1235 * the request is queued to not overwhelm our ability to create and
1236 * maintain connections with other systems. The actual service
1237 * handle is then returned via the 'op_result' member in the event
1238 * callback. The @a ca callback is used to create the connection
1239 * when the time is right; the @a da callback will be used to
1240 * destroy the connection (upon #GNUNET_TESTBED_operation_done).
1241 * #GNUNET_TESTBED_operation_done can be used to abort this
1242 * operation until the event callback has been called.
1243 *
1244 * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG
1245 * @param peer peer that runs the service
1246 * @param service_name name of the service to connect to
1247 * @param cb the callback to call when this operation is ready (that is,
1248 * right after the connect adapter returns)
1249 * @param cb_cls closure for @a cb
1250 * @param ca helper function to establish the connection
1251 * @param da helper function to close the connection
1252 * @param cada_cls closure for @a ca and @a da
1253 * @return handle for the operation
1254 */
1255struct GNUNET_TESTBED_Operation *
1256GNUNET_TESTBED_service_connect (void *op_cls,
1257 struct GNUNET_TESTBED_Peer *peer,
1258 const char *service_name,
1259 GNUNET_TESTBED_ServiceConnectCompletionCallback
1260 cb,
1261 void *cb_cls,
1262 GNUNET_TESTBED_ConnectAdapter ca,
1263 GNUNET_TESTBED_DisconnectAdapter da,
1264 void *cada_cls);
1265
1266
1267/**
1268 * This function is used to signal that the event information (struct
1269 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1270 * i.e. if the event callback is ever called for this operation. If the event
1271 * callback for this operation has not yet been called, calling this function
1272 * cancels the operation, frees its resources and ensures the no event is
1273 * generated with respect to this operation. Note that however cancelling an
1274 * operation does NOT guarantee that the operation will be fully undone (or that
1275 * nothing ever happened).
1276 *
1277 * This function MUST be called for every operation to fully remove the
1278 * operation from the operation queue. After calling this function, if
1279 * operation is completed and its event information is of type
1280 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1281
1282 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1283 * calling this function on such as operation calls the disconnect adapter if
1284 * the connect adapter was ever called.
1285 *
1286 * @param operation operation to signal completion or cancellation
1287 */
1288void
1289GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1290
1291
1292/**
1293 * Callback function to process statistic values from all peers.
1294 *
1295 * @param cls closure
1296 * @param peer the peer the statistic belong to
1297 * @param subsystem name of subsystem that created the statistic
1298 * @param name the name of the datum
1299 * @param value the current value
1300 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1301 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1302 */
1303typedef int
1304(*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1305 const struct GNUNET_TESTBED_Peer *peer,
1306 const char *subsystem,
1307 const char *name,
1308 uint64_t value,
1309 int is_persistent);
1310
1311
1312/**
1313 * Convenience method that iterates over all (running) peers
1314 * and retrieves all statistics from each peer.
1315 *
1316 * @param num_peers number of peers to iterate over
1317 * @param peers array of peers to iterate over
1318 * @param subsystem limit to the specified subsystem, NULL for all subsystems
1319 * @param name name of the statistic value, NULL for all values
1320 * @param proc processing function for each statistic retrieved
1321 * @param cont continuation to call once call is completed. The completion of this
1322 * operation is *ONLY* signalled through this callback -- no
1323 * GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1324 * @param cls closure to pass to proc and cont
1325 * @return operation handle to cancel the operation
1326 */
1327struct GNUNET_TESTBED_Operation *
1328GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1329 struct GNUNET_TESTBED_Peer **peers,
1330 const char *subsystem, const char *name,
1331 GNUNET_TESTBED_StatisticsIterator proc,
1332 GNUNET_TESTBED_OperationCompletionCallback cont,
1333 void *cls);
1334
1335
1336/**
1337 * Return the index of the peer inside of the total peer array,
1338 * aka. the peer's "unique ID".
1339 *
1340 * @param peer Peer handle.
1341 *
1342 * @return The peer's unique ID.
1343 */
1344uint32_t
1345GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer);
1346
1347
1348/**
1349 * Handle for testbed run helper functions
1350 */
1351struct GNUNET_TESTBED_RunHandle;
1352
1353
1354/**
1355 * Signature of a main function for a testcase.
1356 *
1357 * @param cls closure
1358 * @param h the run handle
1359 * @param num_peers number of peers in 'peers'
1360 * @param peers handle to peers run in the testbed. NULL upon timeout (see
1361 * GNUNET_TESTBED_test_run()).
1362 * @param links_succeeded the number of overlay link connection attempts that
1363 * succeeded
1364 * @param links_failed the number of overlay link connection attempts that
1365 * failed
1366 * @see GNUNET_TESTBED_test_run()
1367 */
1368typedef void
1369(*GNUNET_TESTBED_TestMaster)(void *cls,
1370 struct GNUNET_TESTBED_RunHandle *h,
1371 unsigned int num_peers,
1372 struct GNUNET_TESTBED_Peer **peers,
1373 unsigned int links_succeeded,
1374 unsigned int links_failed);
1375
1376
1377/**
1378 * Convenience method for running a testbed with
1379 * a single call. Underlay and overlay topology
1380 * are configured using the "UNDERLAY" and "OVERLAY"
1381 * options in the "[testbed]" section of the configuration\
1382 * (with possible options given in "UNDERLAY_XXX" and/or
1383 * "OVERLAY_XXX").
1384 *
1385 * The test_master callback will be called once the testbed setup is finished or
1386 * upon a timeout. This timeout is given through the configuration file by
1387 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1388 *
1389 * The testbed is to be terminated using a call to
1390 * "GNUNET_SCHEDULER_shutdown".
1391 *
1392 * @param host_filename name of the file with the 'hosts', NULL
1393 * to run everything on 'localhost'
1394 * @param cfg configuration to use (for testbed, controller and peers)
1395 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1396 * cfg?; should be greater than 0
1397 * @param event_mask bit mask with set of events to call 'cc' for;
1398 * or-ed values of "1LL" shifted by the
1399 * respective 'enum GNUNET_TESTBED_EventType'
1400 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1401 * @param cc controller callback to invoke on events; This callback is called
1402 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1403 * set in the event_mask as this is the only way get access to the
1404 * handle of each peer
1405 * @param cc_cls closure for cc
1406 * @param test_master this callback will be called once the test is ready or
1407 * upon timeout
1408 * @param test_master_cls closure for 'test_master'.
1409 */
1410void
1411GNUNET_TESTBED_run (const char *host_filename,
1412 const struct GNUNET_CONFIGURATION_Handle *cfg,
1413 unsigned int num_peers,
1414 uint64_t event_mask,
1415 GNUNET_TESTBED_ControllerCallback cc,
1416 void *cc_cls,
1417 GNUNET_TESTBED_TestMaster test_master,
1418 void *test_master_cls);
1419
1420
1421/**
1422 * Convenience method for running a "simple" test on the local system
1423 * with a single call from 'main'. Underlay and overlay topology are
1424 * configured using the "UNDERLAY" and "OVERLAY" options in the
1425 * "[TESTBED]" section of the configuration (with possible options
1426 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1427 *
1428 * The test_master callback will be called once the testbed setup is finished or
1429 * upon a timeout. This timeout is given through the configuration file by
1430 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1431 *
1432 * The test is to be terminated using a call to
1433 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1434 * the program is stopped without 'master' ever being run.
1435 *
1436 * NOTE: this function should be called from 'main', NOT from
1437 * within a GNUNET_SCHEDULER-loop. This function will initialize
1438 * the scheduler loop, the testbed and then pass control to
1439 * 'master'.
1440 *
1441 * @param testname name of the testcase (to configure logging, etc.)
1442 * @param cfg_filename configuration filename to use
1443 * (for testbed, controller and peers)
1444 * @param num_peers number of peers to start; should be greter than 0
1445 * @param event_mask bit mask with set of events to call 'cc' for;
1446 * or-ed values of "1LL" shifted by the
1447 * respective 'enum GNUNET_TESTBED_EventType'
1448 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1449 * @param cc controller callback to invoke on events; This callback is called
1450 * for all peer start events even if #GNUNET_TESTBED_ET_PEER_START isn't
1451 * set in the event_mask as this is the only way get access to the
1452 * handle of each peer
1453 * @param cc_cls closure for @a cc
1454 * @param test_master this callback will be called once the test is ready or
1455 * upon timeout
1456 * @param test_master_cls closure for @a test_master.
1457 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1458 */
1459int
1460GNUNET_TESTBED_test_run (const char *testname,
1461 const char *cfg_filename,
1462 unsigned int num_peers,
1463 uint64_t event_mask,
1464 GNUNET_TESTBED_ControllerCallback cc,
1465 void *cc_cls,
1466 GNUNET_TESTBED_TestMaster test_master,
1467 void *test_master_cls);
1468
1469
1470/**
1471 * Obtain handle to the master controller from a testbed run. The handle
1472 * returned should not be disconnected.
1473 *
1474 * @param h the testbed run handle
1475 * @return handle to the master controller
1476 */
1477struct GNUNET_TESTBED_Controller *
1478GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
1479
1480
1481/**
1482 * Opaque handle for barrier
1483 */
1484struct GNUNET_TESTBED_Barrier;
1485
1486
1487/**
1488 * Status of a barrier
1489 */
1490enum GNUNET_TESTBED_BarrierStatus
1491{
1492 /**
1493 * Barrier initialised successfully
1494 */
1495 GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
1496
1497 /**
1498 * Barrier is crossed
1499 */
1500 GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
1501
1502 /**
1503 * Error status
1504 */
1505 GNUNET_TESTBED_BARRIERSTATUS_ERROR,
1506};
1507
1508
1509/**
1510 * Functions of this type are to be given as callback argument to
1511 * GNUNET_TESTBED_barrier_init(). The callback will be called when status
1512 * information is available for the barrier.
1513 *
1514 * @param cls the closure given to GNUNET_TESTBED_barrier_init()
1515 * @param name the name of the barrier
1516 * @param barrier the barrier handle
1517 * @param status status of the barrier. The barrier is removed once it has been
1518 * crossed or an error occurs while processing it. Therefore it is
1519 * invalid to call GNUNET_TESTBED_barrier_cancel() on a crossed or
1520 * errored barrier.
1521 * @param emsg if the status were to be #GNUNET_SYSERR, this parameter has the
1522 * error message
1523 */
1524typedef void
1525(*GNUNET_TESTBED_barrier_status_cb) (void *cls,
1526 const char *name,
1527 struct GNUNET_TESTBED_Barrier *barrier,
1528 enum GNUNET_TESTBED_BarrierStatus status,
1529 const char *emsg);
1530
1531
1532/**
1533 * Initialise a barrier and call the given callback when the required percentage
1534 * of peers (quorum) reach the barrier.
1535 *
1536 * @param controller the handle to the controller
1537 * @param name identification name of the barrier
1538 * @param quorum the percentage of peers that is required to reach the barrier.
1539 * Peers signal reaching a barrier by calling
1540 * GNUNET_TESTBED_barrier_reached().
1541 * @param cb the callback to call when the barrier is reached or upon error.
1542 * Cannot be NULL.
1543 * @param cb_cls closure for @a cb
1544 * @return barrier handle
1545 */
1546struct GNUNET_TESTBED_Barrier *
1547GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
1548 const char *name,
1549 unsigned int quorum,
1550 GNUNET_TESTBED_barrier_status_cb cb,
1551 void *cb_cls);
1552
1553
1554/**
1555 * Cancel a barrier.
1556 *
1557 * @param barrier the barrier handle
1558 */
1559void
1560GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
1561
1562
1563/**
1564 * Opaque handle for barrier wait
1565 */
1566struct GNUNET_TESTBED_BarrierWaitHandle;
1567
1568
1569/**
1570 * Functions of this type are to be given as acallback argument to
1571 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
1572 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
1573 *
1574 * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
1575 * @param name the barrier name
1576 * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
1577 * #GNUNET_OK if the barrier is crossed
1578 */
1579typedef void
1580(*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
1581 const char *name,
1582 int status);
1583
1584
1585/**
1586 * Wait for a barrier to be crossed. This function should be called by the
1587 * peers which have been started by the testbed. If the peer is not started by
1588 * testbed this function may return error
1589 *
1590 * @param name the name of the barrier
1591 * @param cb the barrier wait callback
1592 * @param cls the closure for the above callback
1593 * @return barrier wait handle which can be used to cancel the waiting at
1594 * anytime before the callback is called. NULL upon error.
1595 */
1596struct GNUNET_TESTBED_BarrierWaitHandle *
1597GNUNET_TESTBED_barrier_wait (const char *name,
1598 GNUNET_TESTBED_barrier_wait_cb cb,
1599 void *cls);
1600
1601
1602/**
1603 * Cancel a barrier wait handle. Should not be called in or after the callback
1604 * given to GNUNET_TESTBED_barrier_wait() has been called.
1605 *
1606 * @param h the barrier wait handle
1607 */
1608void
1609GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
1610
1611
1612/**
1613 * Model for configuring underlay links of a peer
1614 * @ingroup underlay
1615 */
1616struct GNUNET_TESTBED_UnderlayLinkModel;
1617
1618
1619/**
1620 * The type of GNUNET_TESTBED_UnderlayLinkModel
1621 * @ingroup underlay
1622 */
1623enum GNUNET_TESTBED_UnderlayLinkModelType
1624{
1625 /**
1626 * The model is based on white listing of peers to which underlay connections
1627 * are permitted. Underlay connections to all other peers will not be
1628 * permitted.
1629 */
1630 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST,
1631
1632 /**
1633 * The model is based on black listing of peers to which underlay connections
1634 * are not permitted. Underlay connections to all other peers will be
1635 * permitted
1636 */
1637 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_WHITELIST
1638};
1639
1640
1641/**
1642 * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can
1643 * have ONLY ONE model and it can be either a blacklist or whitelist based one.
1644 *
1645 * @ingroup underlay
1646 * @param peer the peer for which the model has to be created
1647 * @param type the type of the model
1648 * @return the model
1649 */
1650struct GNUNET_TESTBED_UnderlayLinkModel *
1651GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
1652 enum
1653 GNUNET_TESTBED_UnderlayLinkModelType
1654 type);
1655
1656
1657/**
1658 * Add a peer to the given model. Underlay connections to the given peer will
1659 * be permitted if the model is whitelist based; otherwise they will not be
1660 * permitted.
1661 *
1662 * @ingroup underlay
1663 * @param model the model
1664 * @param peer the peer to add
1665 */
1666void
1667GNUNET_TESTBED_underlaylinkmodel_add_peer (struct
1668 GNUNET_TESTBED_UnderlayLinkModel *
1669 model,
1670 struct GNUNET_TESTBED_Peer *peer);
1671
1672
1673/**
1674 * Set the metrics for a link to the given peer in the underlay model. The link
1675 * SHOULD be permittable according to the given model.
1676 *
1677 * @ingroup underlay
1678 * @param model the model
1679 * @param peer the other end peer of the link
1680 * @param latency latency of the link in microseconds
1681 * @param loss data loss of the link expressed as a percentage
1682 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
1683 */
1684void
1685GNUNET_TESTBED_underlaylinkmodel_set_link (struct
1686 GNUNET_TESTBED_UnderlayLinkModel *
1687 model,
1688 struct GNUNET_TESTBED_Peer *peer,
1689 uint32_t latency,
1690 uint32_t loss,
1691 uint32_t bandwidth);
1692
1693
1694/**
1695 * Commit the model. The model is freed in this function(!).
1696 *
1697 * @ingroup underlay
1698 * @param model the model to commit
1699 */
1700void
1701GNUNET_TESTBED_underlaylinkmodel_commit (struct
1702 GNUNET_TESTBED_UnderlayLinkModel *model);
1703
1704
1705/**
1706 * Free the resources of the model. Use this function only if the model has not
1707 * be committed and has to be unallocated. The peer can then have another model
1708 * created.
1709 *
1710 * @ingroup underlay
1711 * @param model the model to unallocate
1712 */
1713void
1714GNUNET_TESTBED_underlaylinkmodel_free (struct
1715 GNUNET_TESTBED_UnderlayLinkModel *model);
1716
1717
1718#if 0 /* keep Emacsens' auto-indent happy */
1719{
1720#endif
1721
1722
1723#ifdef __cplusplus
1724}
1725#endif
1726
1727#endif
1728
1729/** @} */ /* end of group */
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h
new file mode 100644
index 000000000..b0f4e1c03
--- /dev/null
+++ b/src/include/gnunet_testing_barrier.h
@@ -0,0 +1,122 @@
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
33struct GNUNET_TESTING_Barrier;
34
35
36#define GNUNET_TESTING_BARRIER_MAX 32
37
38/**
39 * An entry for a barrier list
40 * FIXME: why is this in the public API!??!
41 */
42struct GNUNET_TESTING_BarrierListEntry
43{
44 /* DLL */
45 struct GNUNET_TESTING_BarrierListEntry *next;
46
47 /* DLL */
48 struct GNUNET_TESTING_BarrierListEntry *prev;
49
50 /* The barrier name*/
51 char *barrier_name;
52
53 /**
54 * Number of commands attached to the barrier.
55 */
56 unsigned int expected_reaches;
57 };
58
59/**
60 * A list to hold barriers provided by plugins
61 * FIXME: why is this in the public API!??!
62 */
63struct GNUNET_TESTING_BarrierList
64{
65 /** List head **/
66 struct GNUNET_TESTING_BarrierListEntry *head;
67
68 /** List tail **/
69 struct GNUNET_TESTING_BarrierListEntry *tail;
70};
71
72
73/**
74 * Command to create a barrier.
75 *
76 * FIXME: high-level it is baffling how we need both the GNUNET_TESTING_Barrier
77 * and the Command that creates barriers. Conceptually this seems to be
78 * very much separate. Can we move _Barrier completely into testing as private?
79 *
80 * @param label The label of this command.
81 * @param percentage_to_be_reached If this percentage of processes reached
82 * this barrier, all processes waiting at
83 * this barrier can pass it. Must not be
84 * used together with number_to_be_reached.
85 * @param number_to_be_reached If this number of processes reached
86 * this barrier, all processes waiting at
87 * this barrier can pass it. Must not be
88 * used together with percentage_to_be_reached.
89 */
90struct GNUNET_TESTING_Command
91GNUNET_TESTING_cmd_barrier_create (
92 const char *label,
93 double percentage_to_be_reached,
94 unsigned int number_to_be_reached);
95
96
97/**
98 * If this command is executed the the process is signaling the master process
99 * that it reached a barrier. If this command is synchronous it will block.
100 *
101 * FIXME: Now this, as it returns a Command, seems to me like it should be
102 * part of the public API?
103 *
104 * @param label name for command.
105 * @param barrier_label The name of the barrier we waited for and which was reached.
106 * @param asynchronous_finish If #GNUNET_YES this command will not block.
107 * @param node_number The global number of the node the cmd runs on.
108 * @param running_on_master Is this cmd running on the master loop?
109 * @param write_message Callback to write messages to the master loop.
110 * @return command.
111 */
112struct GNUNET_TESTING_Command
113GNUNET_TESTING_cmd_barrier_reached (
114 const char *label,
115 const char *barrier_label,
116 unsigned int asynchronous_finish, /* FIXME: why not a bool? */
117 unsigned int node_number,
118 unsigned int running_on_master, /* FIXME: why not a bool? */
119 GNUNET_TESTING_cmd_helper_write_cb write_message); /* FIXME: no 'cls' closure argument!? */
120
121#endif
122/* end of testing_barrier.h */
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index 664e20ac3..0d74de8c2 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Testing
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -41,6 +44,7 @@
41#ifndef GNUNET_TESTING_LIB_H 44#ifndef GNUNET_TESTING_LIB_H
42#define GNUNET_TESTING_LIB_H 45#define GNUNET_TESTING_LIB_H
43 46
47
44#include "gnunet_util_lib.h" 48#include "gnunet_util_lib.h"
45#include "gnunet_statistics_service.h" 49#include "gnunet_statistics_service.h"
46#include "gnunet_arm_service.h" 50#include "gnunet_arm_service.h"
@@ -398,7 +402,7 @@ typedef void
398 * Starts a peer using the given configuration and then invokes the 402 * Starts a peer using the given configuration and then invokes the
399 * given callback. This function ALSO initializes the scheduler loop 403 * given callback. This function ALSO initializes the scheduler loop
400 * and should thus be called directly from "main". The testcase 404 * and should thus be called directly from "main". The testcase
401 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. 405 * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown().
402 * 406 *
403 * @param testdir only the directory name without any path. This is used for 407 * @param testdir only the directory name without any path. This is used for
404 * all service homes; the directory will be created in a temporary 408 * all service homes; the directory will be created in a temporary
@@ -406,7 +410,7 @@ typedef void
406 * @param cfgfilename name of the configuration file to use; 410 * @param cfgfilename name of the configuration file to use;
407 * use NULL to only run with defaults 411 * use NULL to only run with defaults
408 * @param tm main function of the testcase 412 * @param tm main function of the testcase
409 * @param tm_cls closure for 'tm' 413 * @param tm_cls closure for @a tm
410 * @return 0 on success, 1 on error 414 * @return 0 on success, 1 on error
411 */ 415 */
412int 416int
@@ -422,7 +426,7 @@ GNUNET_TESTING_peer_run (const char *testdir,
422 * Starts a service using the given configuration and then invokes the 426 * Starts a service using the given configuration and then invokes the
423 * given callback. This function ALSO initializes the scheduler loop 427 * given callback. This function ALSO initializes the scheduler loop
424 * and should thus be called directly from "main". The testcase 428 * and should thus be called directly from "main". The testcase
425 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. 429 * should self-terminate by invoking #GNUNET_SCHEDULER_shutdown().
426 * 430 *
427 * This function is useful if the testcase is for a single service 431 * This function is useful if the testcase is for a single service
428 * and if that service doesn't itself depend on other services. 432 * and if that service doesn't itself depend on other services.
@@ -445,23 +449,6 @@ GNUNET_TESTING_service_run (const char *testdir,
445 void *tm_cls); 449 void *tm_cls);
446 450
447 451
448/**
449 * Sometimes we use the binary name to determine which specific
450 * test to run. In those cases, the string after the last "_"
451 * in 'argv[0]' specifies a string that determines the configuration
452 * file or plugin to use.
453 *
454 * This function returns the respective substring, taking care
455 * of issues such as binaries ending in '.exe' on W32.
456 *
457 * @param argv0 the name of the binary
458 * @return string between the last '_' and the '.exe' (or the end of the string),
459 * NULL if argv0 has no '_'
460 */
461char *
462GNUNET_TESTING_get_testname_from_underscore (const char *argv0);
463
464
465#if 0 /* keep Emacsens' auto-indent happy */ 452#if 0 /* keep Emacsens' auto-indent happy */
466{ 453{
467#endif 454#endif
@@ -472,3 +459,5 @@ GNUNET_TESTING_get_testname_from_underscore (const char *argv0);
472#endif 459#endif
473 460
474/** @} */ /* end of group */ 461/** @} */ /* end of group */
462
463/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_testing_loop_lib.h b/src/include/gnunet_testing_loop_lib.h
new file mode 100644
index 000000000..7e13edfab
--- /dev/null
+++ b/src/include/gnunet_testing_loop_lib.h
@@ -0,0 +1,697 @@
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 Central interpreter and command loop for writing an interpreter to test asynchronous systems
23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci
25 * @author t3sserakt
26 */
27#ifndef GNUNET_TESTING_LOOP_LIB_H
28#define GNUNET_TESTING_LOOP_LIB_H
29
30/**
31 * Maximum length of label in command
32 */
33#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
34
35/* ********************* Helper functions ********************* */
36
37/**
38 * Print failing line number and trigger shutdown. Useful
39 * quite any time after the command "run" method has been called.
40 */
41#define GNUNET_TESTING_FAIL(is) \
42 do \
43 { \
44 GNUNET_break (0); \
45 GNUNET_TESTING_interpreter_fail (is); \
46 return; \
47 } while (0)
48
49
50/* ******************* Generic interpreter logic ************ */
51
52/**
53 * Global state of the interpreter, used by a command
54 * to access information about other commands.
55 */
56struct GNUNET_TESTING_Interpreter;
57
58/**
59 * State each asynchronous command must have in its closure.
60 */
61struct GNUNET_TESTING_AsyncContext
62{
63
64 /**
65 * Interpreter we are part of.
66 */
67 struct GNUNET_TESTING_Interpreter *is; // FIXME: Why needed? When available?
68
69 /**
70 * Function to call when done.
71 */
72 GNUNET_SCHEDULER_TaskCallback cont;
73
74 /**
75 * Closure for @e cont.
76 */
77 void *cont_cls;
78
79 /**
80 * Indication if the command finished (#GNUNET_OK).
81 * #GNUNET_NO if it did not finish,
82 * #GNUNET_SYSERR if it failed.
83 */
84 enum GNUNET_GenericReturnValue finished;
85};
86
87
88/**
89 * The asynchronous command of @a ac has failed.
90 *
91 * @param ac command-specific context
92 */
93void
94GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
95
96
97/**
98 * The asynchronous command of @a ac has finished.
99 *
100 * @param ac command-specific context
101 */
102void
103GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
104
105
106/**
107 * Signature of a function used to start executing a command
108 * of a test.
109 *
110 * @param cls closure
111 * @param is interpreter running the command
112 */
113typedef void
114(*GNUNET_TESTING_CommandRunRoutine)(void *cls,
115 struct GNUNET_TESTING_Interpreter *is);
116
117
118/**
119 * Signature of a function used to clean up resources allocated
120 * by a command.
121 *
122 * @param cls closure
123 */
124typedef void
125(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
126
127
128/**
129 * Signature of a function used to extract traits exposed by a
130 * command.
131 *
132 * @param cls closure
133 * @param[out] ret where to return the trait data
134 * @param trait name of the trait to return
135 * @param index index of the trait (for traits that are indexed)
136 * @return #GNUNET_OK on success
137 */
138typedef enum GNUNET_GenericReturnValue
139(*GNUNET_TESTING_CommandGetTraits) (void *cls,
140 const void **ret,
141 const char *trait,
142 unsigned int index);
143
144/**
145 * Create a new command
146 *
147 * @param cls the closure
148 * @param label the Label. Maximum length is GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
149 * @param run the run routing
150 * @param cleanup the cleanup function
151 * @param traits the traits function (optional)
152 * @param the async context
153 * @return the command the function cannot fail
154 */
155struct GNUNET_TESTING_Command
156GNUNET_TESTING_command_new (void *cls,
157 const char *label,
158 GNUNET_TESTING_CommandRunRoutine run,
159 GNUNET_TESTING_CommandCleanupRoutine cleanup,
160 GNUNET_TESTING_CommandGetTraits traits,
161 struct GNUNET_TESTING_AsyncContext *ac);
162
163
164/**
165 * Structure with storage space for a label.
166 */
167struct GNUNET_TESTING_CommandLabel
168{
169 char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
170};
171
172
173/**
174 * Set @a label to @a value. Asserts that @a value is
175 * not longer than #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH.
176 *
177 * @param[out] label label to initialize
178 * @param value value to store into @a label
179 */
180void
181GNUNET_TESTING_set_label (struct GNUNET_TESTING_CommandLabel *label,
182 const char *value);
183
184
185/**
186 * A command to be run by the interpreter.
187 */
188struct GNUNET_TESTING_Command
189{
190 /**
191 * Closure for all commands with command-specific context information.
192 */
193 void *cls;
194
195 /**
196 * Label for the command.
197 */
198 struct GNUNET_TESTING_CommandLabel label;
199
200 /**
201 * Runs the command. Note that upon return, the interpreter
202 * will not automatically run the next command, as the command
203 * may continue asynchronously in other scheduler tasks. Thus,
204 * the command must ensure to eventually call
205 * #GNUNET_TESTING_interpreter_next() or
206 * #GNUNET_TESTING_interpreter_fail().
207 *
208 * If this function creates some asynchronous activity, it should
209 * initialize @e finish to a function that can be used to wait for
210 * the asynchronous activity to terminate.
211 *
212 * @param cls closure
213 * @param is interpreter state
214 */
215 GNUNET_TESTING_CommandRunRoutine run;
216
217 /**
218 * Pointer to the asynchronous context in the command's
219 * closure. Used by the
220 * #GNUNET_TESTING_async_finish() and
221 * #GNUNET_TESTING_async_fail() functions.
222 *
223 * Must be NULL if a command is synchronous.
224 */
225 struct GNUNET_TESTING_AsyncContext *ac;
226
227 /**
228 * Clean up after the command. Run during forced termination
229 * (CTRL-C) or test failure or test success.
230 *
231 * @param cls closure
232 */
233 GNUNET_TESTING_CommandCleanupRoutine cleanup;
234
235 /**
236 * Extract information from a command that is useful for other
237 * commands. Can be NULL if a command has no traits.
238 *
239 * @param cls closure
240 * @param[out] ret result (could be anything)
241 * @param trait name of the trait
242 * @param index index number of the object to extract.
243 * @return #GNUNET_OK on success,
244 * #GNUNET_NO if no trait was found
245 */
246 GNUNET_TESTING_CommandGetTraits traits;
247
248 /**
249 * When did the execution of this command start?
250 */
251 struct GNUNET_TIME_Absolute start_time;
252
253 /**
254 * When did the execution of this command finish?
255 */
256 struct GNUNET_TIME_Absolute finish_time;
257
258 /**
259 * When did we start the last run of this command? Delta to @e finish_time
260 * gives the latency for the last successful run. Useful in case @e
261 * num_tries was positive and the command was run multiple times. In that
262 * case, the @e start_time gives the time when we first tried to run the
263 * command, so the difference between @e start_time and @e finish_time would
264 * be the time all of the @e num_tries took, while the delta to @e
265 * last_req_time is the time the last (successful) execution took.
266 */
267 struct GNUNET_TIME_Absolute last_req_time;
268
269 /**
270 * In case @e asynchronous_finish is true, how long should we wait for this
271 * command to complete? If @e finish did not complete after this amount of
272 * time, the interpreter will fail. Should be set generously to ensure
273 * tests do not fail on slow systems.
274 */
275 struct GNUNET_TIME_Relative default_timeout;
276
277 /**
278 * How often did we try to execute this command? (In case it is a request
279 * that is repated.) Note that a command must have some built-in retry
280 * mechanism for this value to be useful.
281 */
282 unsigned int num_tries;
283
284 /**
285 * If "true", the interpreter should not immediately call
286 * @e finish, even if @e finish is non-NULL. Otherwise,
287 * #GNUNET_TESTING_cmd_finish() must be used
288 * to ensure that a command actually completed.
289 */
290 bool asynchronous_finish;
291
292};
293
294
295/**
296 * Lookup command by label.
297 * Only future commands are looked up.
298 *
299 * @param is interpreter to lookup command in
300 * @param label label of the command to lookup.
301 * @return the command, if it is found, or NULL.
302 * @deprecated (still in use in a very odd way)
303 */
304// FIXME: think harder about whether this is actually needed, likely not.
305const struct GNUNET_TESTING_Command *
306GNUNET_TESTING_interpreter_lookup_future_command (
307 struct GNUNET_TESTING_Interpreter *is,
308 const char *label);
309
310
311/**
312 * Lookup command by label.
313 *
314 * @param is interpreter to lookup command in
315 * @param label label of the command to lookup.
316 * @return the command, if it is found, or NULL.
317 */
318const struct GNUNET_TESTING_Command *
319GNUNET_TESTING_interpreter_lookup_command (
320 struct GNUNET_TESTING_Interpreter *is,
321 const char *label);
322
323
324/**
325 * Lookup command by label.
326 * All commands, first into the past, then into the future are looked up.
327 *
328 * @param is interpreter to lookup command in
329 * @param label label of the command to lookup.
330 * @return the command, if it is found, or NULL.
331 * @deprecated (still in use in a very odd way)
332 */
333const struct GNUNET_TESTING_Command *
334GNUNET_TESTING_interpreter_lookup_command_all (
335 struct GNUNET_TESTING_Interpreter *is,
336 const char *label);
337
338
339/**
340 * Current command failed, clean up and fail the test case.
341 *
342 * @param is interpreter state.
343 */
344void
345GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
346
347
348/**
349 * Turn asynchronous command into non-blocking command by setting
350 * asynchronous_finish to true. Modifies (and then returns) @a cmd simply
351 * setting the bit. By default, most commands are blocking, and by wrapping
352 * the command construction in this function a blocking command can be turned
353 * into an asynchronous command where the interpreter continues after
354 * initiating the asynchronous action. Does nothing if the command is
355 * fundamentally synchronous.
356 *
357 * @param[in,out] cmd command to make non-blocking
358 * @return a finish-command.
359 */
360struct GNUNET_TESTING_Command
361GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
362
363
364/**
365 * Create (synchronous) command that waits for another command to finish.
366 * If @a cmd_ref did not finish after @a timeout, this command will fail
367 * the test case.
368 *
369 * @param finish_label label for this command
370 * @param cmd_ref reference to a previous command which we should
371 * wait for (call `finish()` on)
372 * @param timeout how long to wait at most for @a cmd_ref to finish
373 * @return a finish-command.
374 */
375const struct GNUNET_TESTING_Command
376GNUNET_TESTING_cmd_finish (const char *finish_label,
377 const char *cmd_ref,
378 struct GNUNET_TIME_Relative timeout);
379
380
381/**
382 * Make the instruction pointer point to @a target_label
383 * only if @a counter is greater than zero.
384 *
385 * @param label command label
386 * @param target_label label of the new instruction pointer's destination after the jump;
387 * must be before the current instruction
388 * @param counter counts how many times the rewinding is to happen.
389 */
390struct GNUNET_TESTING_Command
391GNUNET_TESTING_cmd_rewind_ip (const char *label,
392 const char *target_label,
393 unsigned int counter);
394
395
396/**
397 * Function called with the final result of the test.
398 * FIXME: This may want to use a GNUNET_ErrorCode (namespaced, e.g.
399 * GNUNET_EC_TESTING_*)
400 *
401 * @param cls closure
402 * @param rv #GNUNET_OK if the test passed
403 */
404typedef void
405(*GNUNET_TESTING_ResultCallback)(void *cls,
406 enum GNUNET_GenericReturnValue rv);
407
408
409/**
410 * Run the testsuite. Note, CMDs are copied into
411 * the interpreter state because they are _usually_
412 * defined into the "run" method that returns after
413 * having scheduled the test interpreter.
414 *
415 * @param commands the array of command to execute
416 * @param timeout how long to wait for each command to execute
417 * @param rc function to call with the final result
418 * @param rc_cls closure for @a rc
419 * @return The interpreter.
420 */
421struct GNUNET_TESTING_Interpreter *
422GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
423 struct GNUNET_TIME_Relative timeout,
424 GNUNET_TESTING_ResultCallback rc,
425 void *rc_cls);
426
427
428/**
429 * Start a GNUnet scheduler event loop and
430 * run the testsuite. Return 0 upon success.
431 * Expected to be called directly from main().
432 * FIXME: Why is this commands array here not const?
433 *
434 * @param commands the list of command to execute
435 * @param timeout how long to wait for each command to execute
436 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
437 */
438int
439GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
440 struct GNUNET_TIME_Relative timeout);
441
442
443
444/* ************** Fundamental interpreter commands ************ */
445
446
447/**
448 * Create command array terminator.
449 *
450 * @return a end-command.
451 */
452struct GNUNET_TESTING_Command
453GNUNET_TESTING_cmd_end (void);
454
455
456/**
457 * Create a "batch" command. Such command takes a end_CMD-terminated array of
458 * CMDs and executed them. Once it hits the end CMD, it passes the control to
459 * the next top-level CMD, regardless of it being another batch or ordinary
460 * CMD.
461 *
462 * @param label the command label.
463 * @param batch array of CMDs to execute.
464 * @return the command.
465 */
466struct GNUNET_TESTING_Command
467GNUNET_TESTING_cmd_batch (const char *label,
468 struct GNUNET_TESTING_Command *batch);
469
470
471/**
472 * Performance counter.
473 */
474struct GNUNET_TESTING_Timer
475{
476 /**
477 * For which type of commands.
478 */
479 const char *prefix;
480
481 /**
482 * Total time spend in all commands of this type.
483 */
484 struct GNUNET_TIME_Relative total_duration;
485
486 /**
487 * Total time spend waiting for the *successful* exeuction
488 * in all commands of this type.
489 */
490 struct GNUNET_TIME_Relative success_latency;
491
492 /**
493 * Number of commands summed up.
494 */
495 unsigned int num_commands;
496
497 /**
498 * Number of retries summed up.
499 */
500 unsigned int num_retries;
501};
502
503/**
504 * Obtain performance data from the interpreter.
505 *
506 * @param[in,out] timers what commands (by label) to obtain runtimes for
507 * @return the command
508 */
509struct GNUNET_TESTING_Command
510GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
511
512
513/* *** Generic trait logic for implementing traits ********* */
514
515/**
516 * A `struct GNUNET_TESTING_Trait` can be used to exchange data between cmds.
517 *
518 * Therefor the cmd which like to provide data to other cmds has to implement
519 * the trait function, where an array of traits is defined with the help of the
520 * #GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the help of the
521 * #GNUNET_TESTING_get_trait_ macro. Traits name and type must be defined to make
522 * use of the macros.
523 */
524struct GNUNET_TESTING_Trait
525{
526 /**
527 * Index number associated with the trait. This gives the
528 * possibility to have _multiple_ traits on offer under the
529 * same name.
530 */
531 unsigned int index;
532
533 /**
534 * Trait type, for example "reserve-pub" or "coin-priv".
535 */
536 const char *trait_name;
537
538 /**
539 * Pointer to the piece of data to offer.
540 */
541 const void *ptr;
542};
543
544
545/**
546 * "end" of traits array. Because traits are offered into arrays, this type
547 * of trait is used to mark the end of such arrays; useful when iterating over
548 * those.
549 */
550struct GNUNET_TESTING_Trait
551GNUNET_TESTING_trait_end (void);
552
553
554/**
555 * Obtain value of a trait from a command.
556 *
557 * @param traits the array of all the traits.
558 * @param[out] ret where to store the result.
559 * @param trait type of the trait to extract.
560 * @param index index number of the trait to extract.
561 * @return #GNUNET_OK when the trait is found.
562 */
563enum GNUNET_GenericReturnValue
564GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
565 const void **ret,
566 const char *trait,
567 unsigned int index);
568
569
570
571/**
572 * Create headers for a trait with name @a name for
573 * statically allocated data of type @a type.
574 *
575 * @param prefix symbol prefix to use
576 * @param name name of the trait
577 * @param type data type for the trait
578 */
579#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \
580 enum GNUNET_GenericReturnValue \
581 prefix ## _get_trait_ ## name ( \
582 const struct GNUNET_TESTING_Command *cmd, \
583 type **ret); \
584 struct GNUNET_TESTING_Trait \
585 prefix ## _make_trait_ ## name ( \
586 type * value);
587
588
589/**
590 * Create C implementation for a trait with name @a name for statically
591 * allocated data of type @a type.
592 *
593 * @param prefix symbol prefix to use
594 * @param name name of the trait
595 * @param type data type for the trait
596 */
597#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \
598 enum GNUNET_GenericReturnValue \
599 prefix ## _get_trait_ ## name ( \
600 const struct GNUNET_TESTING_Command *cmd, \
601 type * *ret) \
602 { \
603 if (NULL == cmd->traits) return GNUNET_SYSERR; \
604 return cmd->traits (cmd->cls, \
605 (const void **) ret, \
606 GNUNET_S (name), \
607 0); \
608 } \
609 struct GNUNET_TESTING_Trait \
610 prefix ## _make_trait_ ## name ( \
611 type * value) \
612 { \
613 struct GNUNET_TESTING_Trait ret = { \
614 .trait_name = GNUNET_S (name), \
615 .ptr = (const void *) value \
616 }; \
617 return ret; \
618 }
619
620
621/**
622 * Create headers for a trait with name @a name for
623 * statically allocated data of type @a type.
624 *
625 * @param prefix symbol prefix to use
626 * @param name name of the trait
627 * @param type data type for the trait
628 */
629#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \
630 enum GNUNET_GenericReturnValue \
631 prefix ## _get_trait_ ## name ( \
632 const struct GNUNET_TESTING_Command *cmd, \
633 unsigned int index, \
634 type **ret); \
635 struct GNUNET_TESTING_Trait \
636 prefix ## _make_trait_ ## name ( \
637 unsigned int index, \
638 type *value);
639
640
641/**
642 * Create C implementation for a trait with name @a name for statically
643 * allocated data of type @a type.
644 */
645#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \
646 enum GNUNET_GenericReturnValue \
647 prefix ## _get_trait_ ## name ( \
648 const struct GNUNET_TESTING_Command *cmd, \
649 unsigned int index, \
650 type * *ret) \
651 { \
652 if (NULL == cmd->traits) return GNUNET_SYSERR; \
653 return cmd->traits (cmd->cls, \
654 (const void **) ret, \
655 GNUNET_S (name), \
656 index); \
657 } \
658 struct GNUNET_TESTING_Trait \
659 prefix ## _make_trait_ ## name ( \
660 unsigned int index, \
661 type * value) \
662 { \
663 struct GNUNET_TESTING_Trait ret = { \
664 .index = index, \
665 .trait_name = GNUNET_S (name), \
666 .ptr = (const void *) value \
667 }; \
668 return ret; \
669 }
670
671
672/**
673 * Call #op on all simple traits needed by loop logic.
674 *
675 * @param op operation to perform
676 * @param prefix prefix to pass to @e op
677 */
678#define GNUNET_TESTING_LOOP_SIMPLE_TRAITS(op,prefix) \
679 op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
680
681
682GNUNET_TESTING_LOOP_SIMPLE_TRAITS(GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING)
683
684
685/**
686 * Call #op on all indexed traits needed by loop logic.
687 *
688 * @param op operation to perform
689 * @param prefix prefix to pass to @e op
690 */
691#define GNUNET_TESTING_LOOP_INDEXED_TRAITS(op,prefix) \
692 op (prefix, cmd, const struct GNUNET_TESTING_Command)
693
694GNUNET_TESTING_LOOP_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING)
695
696
697#endif
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
index 334f43c88..843fce0d5 100644
--- a/src/include/gnunet_testing_netjail_lib.h
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -27,9 +27,8 @@
27#ifndef GNUNET_TESTING_NETJAIL_LIB_H 27#ifndef GNUNET_TESTING_NETJAIL_LIB_H
28#define GNUNET_TESTING_NETJAIL_LIB_H 28#define GNUNET_TESTING_NETJAIL_LIB_H
29 29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_ng_lib.h" 30#include "gnunet_testing_ng_lib.h"
31#include "gnunet_testing_plugin.h"
33 32
34 33
35/** 34/**
@@ -52,7 +51,7 @@ struct GNUNET_TESTING_NetjailRouter
52/** 51/**
53 * Enum for the different types of nodes. 52 * Enum for the different types of nodes.
54 */ 53 */
55enum GNUNET_TESTING_NODE_TYPE 54enum GNUNET_TESTING_NodeType
56{ 55{
57 /** 56 /**
58 * Node in a subnet. 57 * Node in a subnet.
@@ -121,7 +120,7 @@ struct GNUNET_TESTING_NodeConnection
121 /** 120 /**
122 * The type of the node this connection points to. 121 * The type of the node this connection points to.
123 */ 122 */
124 enum GNUNET_TESTING_NODE_TYPE node_type; 123 enum GNUNET_TESTING_NodeType node_type;
125 124
126 /** 125 /**
127 * The node which establish the connection 126 * The node which establish the connection
@@ -145,6 +144,16 @@ struct GNUNET_TESTING_NodeConnection
145struct GNUNET_TESTING_NetjailNode 144struct GNUNET_TESTING_NetjailNode
146{ 145{
147 /** 146 /**
147 * Head of the DLL with the connections which shall be established to other nodes.
148 */
149 struct GNUNET_TESTING_NodeConnection *node_connections_head;
150
151 /**
152 * Tail of the DLL with the connections which shall be established to other nodes.
153 */
154 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
155
156 /**
148 * Plugin for the test case to be run on this node. 157 * Plugin for the test case to be run on this node.
149 */ 158 */
150 char *plugin; 159 char *plugin;
@@ -165,14 +174,19 @@ struct GNUNET_TESTING_NetjailNode
165 unsigned int node_n; 174 unsigned int node_n;
166 175
167 /** 176 /**
168 * Head of the DLL with the connections which shall be established to other nodes. 177 * The overall number of the node in the whole test system.
169 */ 178 */
170 struct GNUNET_TESTING_NodeConnection *node_connections_head; 179 unsigned int node_number;
171 180
172 /** 181 /**
173 * Tail of the DLL with the connections which shall be established to other nodes. 182 * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value.
174 */ 183 */
175 struct GNUNET_TESTING_NodeConnection *node_connections_tail; 184 unsigned int additional_connects;
185
186 /**
187 * The number of cmds waiting for a specific barrier.
188 */
189 unsigned int expected_reaches;
176}; 190};
177 191
178 192
@@ -232,6 +246,11 @@ struct GNUNET_TESTING_NetjailTopology
232 * Hash map containing the global known nodes which are not natted. 246 * Hash map containing the global known nodes which are not natted.
233 */ 247 */
234 struct GNUNET_CONTAINER_MultiShortmap *map_globals; 248 struct GNUNET_CONTAINER_MultiShortmap *map_globals;
249
250 /**
251 * Additional connects we do expect, beside the connects which are configured in the topology.
252 */
253 unsigned int additional_connects;
235}; 254};
236 255
237/** 256/**
@@ -245,13 +264,37 @@ GNUNET_TESTING_get_topo_from_file (const char *filename);
245 264
246 265
247/** 266/**
267 * FIXME: this could use a "to_string".
248 * Parse the topology data. 268 * Parse the topology data.
249 * 269 *
250 * @param data The topology data. 270 * @param data The topology data.
251 * @return The GNUNET_TESTING_NetjailTopology 271 * @return The GNUNET_TESTING_NetjailTopology
252 */ 272 */
253struct GNUNET_TESTING_NetjailTopology * 273struct GNUNET_TESTING_NetjailTopology *
254GNUNET_TESTING_get_topo_from_string (char *data); 274GNUNET_TESTING_get_topo_from_string (const char *data);
275
276
277/**
278 * Get the number of unintentional additional connections the node waits for.
279 *
280 * @param num The specific node we want the additional connects for.
281 * @return The number of additional connects
282 */
283unsigned int
284GNUNET_TESTING_get_additional_connects (unsigned int num,
285 struct GNUNET_TESTING_NetjailTopology *
286 topology);
287
288/**
289 * Get a node from the topology.
290 *
291 * @param num The specific node we want the connections for.
292 * @param topology The topology we get the connections from.
293 * @return The connections of the node.
294 */
295struct GNUNET_TESTING_NetjailNode *
296GNUNET_TESTING_get_node (unsigned int num,
297 struct GNUNET_TESTING_NetjailTopology *topology);
255 298
256 299
257/** 300/**
@@ -262,8 +305,8 @@ GNUNET_TESTING_get_topo_from_string (char *data);
262 * @return The connections of the node. 305 * @return The connections of the node.
263 */ 306 */
264struct GNUNET_TESTING_NodeConnection * 307struct GNUNET_TESTING_NodeConnection *
265GNUNET_TESTING_get_connections (unsigned int num, struct 308GNUNET_TESTING_get_connections (unsigned int num,
266 GNUNET_TESTING_NetjailTopology *topology); 309 const struct GNUNET_TESTING_NetjailTopology *topology);
267 310
268 311
269/** 312/**
@@ -275,7 +318,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
275 */ 318 */
276char * 319char *
277GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, 320GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
278 char *prefix); 321 const char *prefix);
279 322
280 323
281/** 324/**
@@ -288,7 +331,7 @@ GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
288 331
289 332
290/** 333/**
291 * Calculate the unique id identifying a node from a given connction. 334 * Calculate the unique id identifying a node from a given connection.
292 * 335 *
293 * @param node_connection The connection we calculate the id from. 336 * @param node_connection The connection we calculate the id from.
294 * @param topology The topology we get all needed information from. 337 * @param topology The topology we get all needed information from.
@@ -304,7 +347,7 @@ GNUNET_TESTING_calculate_num (struct
304 * Struct with information for callbacks. 347 * Struct with information for callbacks.
305 * 348 *
306 */ 349 */
307struct BlockState 350struct GNUNET_TESTING_BlockState
308{ 351{
309 /** 352 /**
310 * Context for our asynchronous completion. 353 * Context for our asynchronous completion.
@@ -326,7 +369,7 @@ struct BlockState
326 * Struct to hold information for callbacks. 369 * Struct to hold information for callbacks.
327 * 370 *
328 */ 371 */
329struct LocalPreparedState 372struct GNUNET_TESTING_LocalPreparedState
330{ 373{
331 /** 374 /**
332 * Context for our asynchronous completion. 375 * Context for our asynchronous completion.
@@ -337,28 +380,35 @@ struct LocalPreparedState
337 * Callback to write messages to the master loop. 380 * Callback to write messages to the master loop.
338 * 381 *
339 */ 382 */
340 TESTING_CMD_HELPER_write_cb write_message; 383 GNUNET_TESTING_cmd_helper_write_cb write_message;
341}; 384};
342 385
343 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 */
344struct GNUNET_TESTING_Command 394struct GNUNET_TESTING_Command
345GNUNET_TESTING_cmd_system_destroy (const char *label, 395GNUNET_TESTING_cmd_system_destroy (const char *label,
346 const char *create_label); 396 const char *create_label);
347 397
348 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 */
349struct GNUNET_TESTING_Command 405struct GNUNET_TESTING_Command
350GNUNET_TESTING_cmd_system_create (const char *label, 406GNUNET_TESTING_cmd_system_create (const char *label,
351 const char *testdir); 407 const char *testdir);
352 408
353 409
354int
355GNUNET_TESTING_get_trait_test_system (const struct
356 GNUNET_TESTING_Command *cmd,
357 struct GNUNET_TESTING_System **test_system);
358
359
360/** 410/**
361 * Create command. 411 * This command executes a shell script to setup the netjail environment.
362 * 412 *
363 * @param label name for command. 413 * @param label name for command.
364 * @param topology_config Configuration file for the test topology. 414 * @param topology_config Configuration file for the test topology.
@@ -372,7 +422,7 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
372 422
373 423
374/** 424/**
375 * Create command. 425 * This command executes a shell script to remove the netjail environment.
376 * 426 *
377 * @param label name for command. 427 * @param label name for command.
378 * @param topology_config Configuration file for the test topology. 428 * @param topology_config Configuration file for the test topology.
@@ -386,20 +436,23 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
386 436
387 437
388/** 438/**
389 * Create command. 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.
390 * 441 *
391 * @param label Name for the command. 442 * @param label Name for the command.
392 * @param topology The complete topology information. 443 * @param topology The complete topology information.
393 * @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. 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.
394 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. 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.
395 * @return command. 447 * @return command.
396 */ 448 */
397struct GNUNET_TESTING_Command 449struct GNUNET_TESTING_Command
398GNUNET_TESTING_cmd_netjail_start_testing_system ( 450GNUNET_TESTING_cmd_netjail_start_cmds_helper (
399 const char *label, 451 const char *label,
400 struct GNUNET_TESTING_NetjailTopology *topology, 452 struct GNUNET_TESTING_NetjailTopology *topology,
401 unsigned int *read_file, 453 unsigned int *read_file,
402 char *topology_data); 454 char *topology_data,
455 struct GNUNET_TIME_Relative timeout);
403 456
404 457
405/** 458/**
@@ -411,118 +464,83 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (
411 * @return command. 464 * @return command.
412 */ 465 */
413struct GNUNET_TESTING_Command 466struct GNUNET_TESTING_Command
414GNUNET_TESTING_cmd_stop_testing_system ( 467GNUNET_TESTING_cmd_stop_cmds_helper (
415 const char *label, 468 const char *label,
416 const char *helper_start_label, 469 const char *helper_start_label,
417 struct GNUNET_TESTING_NetjailTopology *topology); 470 struct GNUNET_TESTING_NetjailTopology *topology);
418 471
419 472
420/** 473/**
421 * Create a GNUNET_CMDS_LOCAL_FINISHED message. 474 * This command is used to block the loop, until the command is finished by other commands,
422 * 475 * using a trait to get this commands struct GNUNET_TESTING_AsyncContext.
423 * @param rv The result of the local test as GNUNET_GenericReturnValue.
424 * @return The GNUNET_CMDS_LOCAL_FINISHED message.
425*/
426struct GNUNET_MessageHeader *
427GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
428
429
430/**
431 * Function to get the trait with the async context.
432 *
433 * @param[out] ac GNUNET_TESTING_AsyncContext.
434 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
435 */
436int
437GNUNET_TESTING_get_trait_async_context (
438 const struct GNUNET_TESTING_Command *cmd,
439 struct GNUNET_TESTING_AsyncContext **ac);
440
441
442/**
443 * Offer handles to testing cmd helper from trait
444 *
445 * @param cmd command to extract the message from.
446 * @param pt pointer to message.
447 * @return #GNUNET_OK on success.
448 */
449enum GNUNET_GenericReturnValue
450GNUNET_TESTING_get_trait_helper_handles (
451 const struct GNUNET_TESTING_Command *cmd,
452 struct GNUNET_HELPER_Handle ***helper);
453
454
455struct GNUNET_TESTING_Command
456GNUNET_TESTING_cmd_block_until_all_peers_started (
457 const char *label,
458 unsigned int *all_peers_started);
459
460
461/**
462 * Create command.
463 * 476 *
464 * @param label name for command. 477 * @param label name for command.
465 * @param all_peers_started Flag which will be set from outside.
466 * @param asynchronous_finish If GNUNET_YES this command will not block.
467 * @return command. 478 * @return command.
468 */ 479 */
469struct GNUNET_TESTING_Command 480struct GNUNET_TESTING_Command
470GNUNET_TESTING_cmd_block_until_external_trigger ( 481GNUNET_TESTING_cmd_block_until_external_trigger (
471 const char *label); 482 const char *label);
472 483
473
474struct GNUNET_TESTING_Command
475GNUNET_TESTING_cmd_send_peer_ready (const char *label,
476 TESTING_CMD_HELPER_write_cb write_message);
477
478
479/** 484/**
480 * Create command. 485 * DEPRECATED
486 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
481 * 487 *
482 * @param label name for command. 488 * @param label name for command.
483 * @param write_message Callback to write messages to the master loop. 489 * @param write_message Callback to write messages to the master loop.
484 * @return command. 490 * @return command.
485 */ 491 */
486struct GNUNET_TESTING_Command 492struct GNUNET_TESTING_Command
487GNUNET_TESTING_cmd_local_test_finished ( 493GNUNET_TESTING_cmd_send_peer_ready (const char *label,
488 const char *label, 494 GNUNET_TESTING_cmd_helper_write_cb write_message);
489 TESTING_CMD_HELPER_write_cb write_message); 495
490 496
491/** 497/**
492 * Create command. 498 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop.
493 * 499 *
494 * @param label name for command. 500 * @param label name for command.
495 * @param write_message Callback to write messages to the master loop. 501 * @param write_message Callback to write messages to the master loop.
496 * @param all_local_tests_prepared Flag which will be set from outside.
497 * @return command. 502 * @return command.
498 */ 503 */
499struct GNUNET_TESTING_Command 504struct GNUNET_TESTING_Command
500GNUNET_TESTING_cmd_local_test_prepared (const char *label, 505GNUNET_TESTING_cmd_local_test_prepared (const char *label,
501 TESTING_CMD_HELPER_write_cb 506 GNUNET_TESTING_cmd_helper_write_cb
502 write_message); 507 write_message);
503 508
509
504/** 510/**
505 * Function to get the trait with the struct LocalPreparedState. 511 * Create command.
506 *
507 * @param[out] lfs struct LocalPreparedState.
508 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
509 * 512 *
513 * @param label name for command.
514 * @param system_label Label of the cmd to setup a test environment.
515 * @param no Decimal number representing the last byte of the IP address of this peer.
516 * @param node_ip The IP address of this node.
517 * @param cfgname Configuration file name for this peer.
518 * @param broadcast Flag indicating, if broadcast should be switched on.
519 * @return command.
510 */ 520 */
511enum GNUNET_GenericReturnValue 521struct GNUNET_TESTING_Command
512GNUNET_TESTING_get_trait_local_prepared_state ( 522GNUNET_TESTING_cmd_start_peer (const char *label,
513 const struct GNUNET_TESTING_Command *cmd, 523 const char *system_label,
514 struct LocalPreparedState **lfs); 524 uint32_t no,
525 const char *node_ip,
526 const char *cfgname,
527 unsigned int broadcast);
528
529
530/* ***** Netjail trait support ***** */
515 531
516 532
517/** 533/**
518 * Function to get the trait with the internal command state BlockState. 534 * Call #op on all simple traits.
519 *
520 * * @param[out] ac struct BlockState.
521* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
522 */ 535 */
523int 536#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op, prefix) \
524GNUNET_TESTING_get_trait_block_state ( 537 op (prefix, test_system, const struct GNUNET_TESTING_System) \
525 const struct GNUNET_TESTING_Command *cmd, 538 op (prefix, async_context, struct GNUNET_TESTING_AsyncContext) \
526 struct BlockState **bs); 539 op (prefix, helper_handles, const struct GNUNET_HELPER_Handle *) \
540 op (prefix, local_prepared_state, const struct GNUNET_TESTING_LocalPreparedState) \
541 op (prefix, block_state, struct GNUNET_TESTING_BlockState)
542
543GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING)
544
527 545
528#endif 546#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index c9f5e3e00..407f50bb7 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_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) 2021 GNUnet e.V. 3 Copyright (C) 2021, 2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @brief API for writing an interpreter to test GNUnet components 22 * @brief Meta-header for next-generation testing logic
23 * @author Christian Grothoff <christian@grothoff.org> 23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci 24 * @author Marcello Stanisci
25 * @author t3sserakt 25 * @author t3sserakt
@@ -27,401 +27,15 @@
27#ifndef GNUNET_TESTING_NG_LIB_H 27#ifndef GNUNET_TESTING_NG_LIB_H
28#define GNUNET_TESTING_NG_LIB_H 28#define GNUNET_TESTING_NG_LIB_H
29 29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_lib.h"
33
34
35/* ********************* Helper functions ********************* */
36
37/**
38 * Print failing line number and trigger shutdown. Useful
39 * quite any time after the command "run" method has been called.
40 */
41#define GNUNET_TESTING_FAIL(is) \
42 do \
43 { \
44 GNUNET_break (0); \
45 GNUNET_TESTING_interpreter_fail (is); \
46 return; \
47 } while (0)
48
49
50/* ******************* Generic interpreter logic ************ */
51
52/**
53 * Global state of the interpreter, used by a command
54 * to access information about other commands.
55 */
56struct GNUNET_TESTING_Interpreter;
57
58/**
59 * State each asynchronous command must have in its closure.
60 */
61struct GNUNET_TESTING_AsyncContext
62{
63
64 /**
65 * Interpreter we are part of.
66 */
67 struct GNUNET_TESTING_Interpreter *is;
68
69 /**
70 * Function to call when done.
71 */
72 GNUNET_SCHEDULER_TaskCallback cont;
73
74 /**
75 * Closure for @e cont.
76 */
77 void *cont_cls;
78
79 /**
80 * Indication if the command finished (#GNUNET_OK).
81 * #GNUNET_NO if it did not finish,
82 * #GNUNET_SYSERR if it failed.
83 */
84 enum GNUNET_GenericReturnValue finished;
85};
86
87
88/**
89 * A command to be run by the interpreter.
90 */
91struct GNUNET_TESTING_Command
92{
93
94 /**
95 * Closure for all commands with command-specific context information.
96 */
97 void *cls;
98
99 /**
100 * Label for the command.
101 */
102 const char *label;
103
104 /**
105 * Runs the command. Note that upon return, the interpreter
106 * will not automatically run the next command, as the command
107 * may continue asynchronously in other scheduler tasks. Thus,
108 * the command must ensure to eventually call
109 * #GNUNET_TESTING_interpreter_next() or
110 * #GNUNET_TESTING_interpreter_fail().
111 *
112 * If this function creates some asynchronous activity, it should
113 * initialize @e finish to a function that can be used to wait for
114 * the asynchronous activity to terminate.
115 *
116 * @param cls closure
117 * @param is interpreter state
118 */
119 void
120 (*run)(void *cls,
121 struct GNUNET_TESTING_Interpreter *is);
122
123 /**
124 * Pointer to the asynchronous context in the command's
125 * closure. Used by the
126 * #GNUNET_TESTING_async_finish() and
127 * #GNUNET_TESTING_async_fail() functions.
128 *
129 * Must be NULL if a command is synchronous.
130 */
131 struct GNUNET_TESTING_AsyncContext *ac;
132
133 /**
134 * Clean up after the command. Run during forced termination
135 * (CTRL-C) or test failure or test success.
136 *
137 * @param cls closure
138 */
139 void
140 (*cleanup)(void *cls);
141
142 /**
143 * Extract information from a command that is useful for other
144 * commands. Can be NULL if a command has no traits.
145 *
146 * @param cls closure
147 * @param[out] ret result (could be anything)
148 * @param trait name of the trait
149 * @param index index number of the object to extract.
150 * @return #GNUNET_OK on success,
151 * #GNUNET_NO if no trait was found
152 */
153 enum GNUNET_GenericReturnValue
154 (*traits)(void *cls,
155 const void **ret,
156 const char *trait,
157 unsigned int index);
158
159 /**
160 * When did the execution of this command start?
161 */
162 struct GNUNET_TIME_Absolute start_time;
163
164 /**
165 * When did the execution of this command finish?
166 */
167 struct GNUNET_TIME_Absolute finish_time;
168
169 /**
170 * When did we start the last run of this command? Delta to @e finish_time
171 * gives the latency for the last successful run. Useful in case @e
172 * num_tries was positive and the command was run multiple times. In that
173 * case, the @e start_time gives the time when we first tried to run the
174 * command, so the difference between @e start_time and @e finish_time would
175 * be the time all of the @e num_tries took, while the delta to @e
176 * last_req_time is the time the last (successful) execution took.
177 */
178 struct GNUNET_TIME_Absolute last_req_time;
179
180 /**
181 * In case @e asynchronous_finish is true, how long should we wait for this
182 * command to complete? If @e finish did not complete after this amount of
183 * time, the interpreter will fail. Should be set generously to ensure
184 * tests do not fail on slow systems.
185 */
186 struct GNUNET_TIME_Relative default_timeout;
187
188 /**
189 * How often did we try to execute this command? (In case it is a request
190 * that is repated.) Note that a command must have some built-in retry
191 * mechanism for this value to be useful.
192 */
193 unsigned int num_tries;
194
195 /**
196 * If "true", the interpreter should not immediately call
197 * @e finish, even if @e finish is non-NULL. Otherwise,
198 * #TALER_TESTING_cmd_finish() must be used
199 * to ensure that a command actually completed.
200 */
201 bool asynchronous_finish;
202
203};
204
205
206/**
207 * Lookup command by label.
208 * Only future commands are looked up.
209 *
210 * @param is interpreter to lookup command in
211 * @param label label of the command to lookup.
212 * @return the command, if it is found, or NULL.
213 */
214const struct GNUNET_TESTING_Command *
215GNUNET_TESTING_interpreter_lookup_future_command (
216 struct GNUNET_TESTING_Interpreter *is,
217 const char *label);
218
219
220/**
221 * Lookup command by label.
222 *
223 * @param is interpreter to lookup command in
224 * @param label label of the command to lookup.
225 * @return the command, if it is found, or NULL.
226 */
227const struct GNUNET_TESTING_Command *
228GNUNET_TESTING_interpreter_lookup_command (
229 struct GNUNET_TESTING_Interpreter *is,
230 const char *label);
231
232
233/**
234 * Lookup command by label.
235 * All commands, first into the past, then into the furture are looked up.
236 *
237 * @param is interpreter to lookup command in
238 * @param label label of the command to lookup.
239 * @return the command, if it is found, or NULL.
240 */
241const struct GNUNET_TESTING_Command *
242GNUNET_TESTING_interpreter_lookup_command_all (
243 struct GNUNET_TESTING_Interpreter *is,
244 const char *label);
245
246
247/**
248 * Obtain label of the command being now run.
249 *
250 * @param is interpreter state.
251 * @return the label.
252 */
253const char *
254GNUNET_TESTING_interpreter_get_current_label (
255 struct GNUNET_TESTING_Interpreter *is);
256
257
258/**
259 * Current command failed, clean up and fail the test case.
260 *
261 * @param is interpreter state.
262 */
263void
264GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
265
266
267/**
268 * The asynchronous command of @a ac has failed.
269 *
270 * @param ac command-specific context
271 */
272void
273GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
274
275
276/**
277 * The asynchronous command of @a ac has finished.
278 *
279 * @param ac command-specific context
280 */
281void
282GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
283
284
285/**
286 * Create command array terminator.
287 *
288 * @return a end-command.
289 */
290struct GNUNET_TESTING_Command
291GNUNET_TESTING_cmd_end (void);
292
293
294/**
295 * Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
296 *
297 * @param cmd command to make synchronous.
298 * @return a finish-command.
299 */
300struct GNUNET_TESTING_Command
301GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
302
303
304/**
305 * Create (synchronous) command that waits for another command to finish.
306 * If @a cmd_ref did not finish after @a timeout, this command will fail
307 * the test case.
308 *
309 * @param finish_label label for this command
310 * @param cmd_ref reference to a previous command which we should
311 * wait for (call `finish()` on)
312 * @param timeout how long to wait at most for @a cmd_ref to finish
313 * @return a finish-command.
314 */
315const struct GNUNET_TESTING_Command
316GNUNET_TESTING_cmd_finish (const char *finish_label,
317 const char *cmd_ref,
318 struct GNUNET_TIME_Relative timeout);
319
320
321/**
322 * Make the instruction pointer point to @a target_label
323 * only if @a counter is greater than zero.
324 *
325 * @param label command label
326 * @param target_label label of the new instruction pointer's destination after the jump;
327 * must be before the current instruction
328 * @param counter counts how many times the rewinding is to happen.
329 */
330struct GNUNET_TESTING_Command
331GNUNET_TESTING_cmd_rewind_ip (const char *label,
332 const char *target_label,
333 unsigned int counter);
334
335
336/**
337 * Function called with the final result of the test.
338 *
339 * @param cls closure
340 * @param rv #GNUNET_OK if the test passed
341 */
342typedef void
343(*GNUNET_TESTING_ResultCallback)(void *cls,
344 enum GNUNET_GenericReturnValue rv);
345
346
347/**
348 * Run the testsuite. Note, CMDs are copied into
349 * the interpreter state because they are _usually_
350 * defined into the "run" method that returns after
351 * having scheduled the test interpreter.
352 *
353 * @param commands the list of command to execute
354 * @param timeout how long to wait for each command to execute
355 * @param rc function to call with the final result
356 * @param rc_cls closure for @a rc
357 */
358void
359GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
360 struct GNUNET_TIME_Relative timeout,
361 GNUNET_TESTING_ResultCallback rc,
362 void *rc_cls);
363
364 30
365/** 31#include "gnunet_util_lib.h"
366 * Start a GNUnet scheduler event loop and
367 * run the testsuite. Return 0 upon success.
368 * Expected to be called directly from main().
369 *
370 * @param commands the list of command to execute
371 * @param timeout how long to wait for each command to execute
372 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
373 */
374int
375GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
376 struct GNUNET_TIME_Relative timeout);
377
378
379/**
380 * Look for substring in a programs' name.
381 *
382 * @param prog program's name to look into
383 * @param marker chunk to find in @a prog
384 * // FIXME: this does not belong here! => libgnunetutil, maybe?
385 * // FIXME: return bool? document return value!
386 */
387int
388GNUNET_TESTING_has_in_name (const char *prog,
389 const char *marker);
390
391
392/* ************** Specific interpreter commands ************ */
393
394
395/**
396 * Returns the actual running command.
397 *
398 * @param is Global state of the interpreter, used by a command
399 * to access information about other commands.
400 * @return The actual running command.
401 */
402struct GNUNET_TESTING_Command *
403GNUNET_TESTING_interpreter_get_current_command (
404 struct GNUNET_TESTING_Interpreter *is);
405
406
407/**
408 * Check if the command is running.
409 *
410 * @param cmd The command to check.
411 * @return GNUNET_NO if the command is not running, GNUNET_YES if it is running.
412 */
413enum GNUNET_GenericReturnValue
414GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
415 32
33/* FIXME: legacy test header, to be removed!! */
34#include "gnunet_testing_lib.h"
416 35
417/** 36#include "gnunet_testing_plugin.h"
418 * Check if a command is finished. 37#include "gnunet_testing_loop_lib.h"
419 * 38#include "gnunet_testing_netjail_lib.h"
420 * @param cmd The command to check.
421 * @return GNUNET_NO if the command is not finished, GNUNET_YES if it is finished.
422 */
423enum GNUNET_GenericReturnValue
424GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command);
425 39
426 40
427/** 41/**
@@ -429,14 +43,12 @@ GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command);
429 * 43 *
430 * @param label command label. 44 * @param label command label.
431 * @param process_label label of a command that has a process trait 45 * @param process_label label of a command that has a process trait
432 * @param process_index index of the process trait at @a process_label // FIXME: enum? needed?
433 * @param signal signal to send to @a process. 46 * @param signal signal to send to @a process.
434 * @return the command. 47 * @return the command.
435 */ 48 */
436struct GNUNET_TESTING_Command 49struct GNUNET_TESTING_Command
437GNUNET_TESTING_cmd_signal (const char *label, 50GNUNET_TESTING_cmd_signal (const char *label,
438 const char *process_label, 51 const char *process_label,
439 unsigned int process_index,
440 int signal); 52 int signal);
441 53
442 54
@@ -453,468 +65,51 @@ GNUNET_TESTING_cmd_sleep (const char *label,
453 65
454 66
455/** 67/**
456 * Create a "batch" command. Such command takes a end_CMD-terminated array of 68 * Command to execute a script synchronously.
457 * CMDs and executed them. Once it hits the end CMD, it passes the control to
458 * the next top-level CMD, regardless of it being another batch or ordinary
459 * CMD.
460 * 69 *
461 * @param label the command label. 70 * FIXME: is this accurate? How is this limited to BASH scripts or even scripts?
462 * @param batch array of CMDs to execute.
463 * @return the command.
464 */
465struct GNUNET_TESTING_Command
466GNUNET_TESTING_cmd_batch (const char *label,
467 struct GNUNET_TESTING_Command *batch);
468
469
470/**
471 * Performance counter.
472 * // FIXME: this might not belong here!
473 */
474struct GNUNET_TESTING_Timer
475{
476 /**
477 * For which type of commands.
478 */
479 const char *prefix;
480
481 /**
482 * Total time spend in all commands of this type.
483 */
484 struct GNUNET_TIME_Relative total_duration;
485
486 /**
487 * Total time spend waiting for the *successful* exeuction
488 * in all commands of this type.
489 */
490 struct GNUNET_TIME_Relative success_latency;
491
492 /**
493 * Number of commands summed up.
494 */
495 unsigned int num_commands;
496
497 /**
498 * Number of retries summed up.
499 */
500 unsigned int num_retries;
501};
502
503
504/**
505 * Getting the topology from file.
506 *
507 * @param filename The name of the topology file.
508 * @return The GNUNET_TESTING_NetjailTopology
509 */
510struct GNUNET_TESTING_NetjailTopology *
511GNUNET_TESTING_get_topo_from_file (const char *filename);
512
513
514/**
515 * Parse the topology data.
516 *
517 * @param data The topology data.
518 * @return The GNUNET_TESTING_NetjailTopology
519 */
520struct GNUNET_TESTING_NetjailTopology *
521GNUNET_TESTING_get_topo_from_string (char *data);
522
523
524/**
525 * Get the connections to other nodes for a specific node.
526 *
527 * @param num The specific node we want the connections for.
528 * @param topology The topology we get the connections from.
529 * @return The connections of the node.
530 */
531struct GNUNET_TESTING_NodeConnection *
532GNUNET_TESTING_get_connections (unsigned int num, struct
533 GNUNET_TESTING_NetjailTopology *topology);
534
535
536/**
537 * Get the address for a specific communicator from a connection.
538 *
539 * @param connection The connection we like to have the address from.
540 * @param prefix The communicator protocol prefix.
541 * @return The address of the communicator.
542 */
543char *
544GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
545 char *prefix);
546
547
548/**
549 * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
550 *
551 * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
552 */
553void
554GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
555
556
557/**
558 * Calculate the unique id identifying a node from a given connction.
559 *
560 * @param node_connection The connection we calculate the id from.
561 * @param topology The topology we get all needed information from.
562 * @return The unique id of the node from the connection.
563 */
564unsigned int
565GNUNET_TESTING_calculate_num (struct
566 GNUNET_TESTING_NodeConnection *node_connection,
567 struct GNUNET_TESTING_NetjailTopology *topology);
568
569
570/**
571 * Retrieve the public key from the test system with the unique node id.
572 *
573 * @param num The unique node id.
574 * @param tl_system The test system.
575 * @return The peer identity wrapping the public key.
576 */
577struct GNUNET_PeerIdentity *
578GNUNET_TESTING_get_pub_key (unsigned int num, struct
579 GNUNET_TESTING_System *tl_system);
580
581
582/**
583 * Obtain performance data from the interpreter.
584 *
585 * @param timers what commands (by label) to obtain runtimes for
586 * @return the command
587 */
588struct GNUNET_TESTING_Command
589GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
590
591
592/* *** Generic trait logic for implementing traits ********* */
593
594/**
595 * A trait.
596 */
597struct GNUNET_TESTING_Trait
598{
599 /**
600 * Index number associated with the trait. This gives the
601 * possibility to have _multiple_ traits on offer under the
602 * same name.
603 */
604 unsigned int index;
605
606 /**
607 * Trait type, for example "reserve-pub" or "coin-priv".
608 */
609 const char *trait_name;
610
611 /**
612 * Pointer to the piece of data to offer.
613 */
614 const void *ptr;
615};
616
617
618/**
619 * "end" trait. Because traits are offered into arrays,
620 * this type of trait is used to mark the end of such arrays;
621 * useful when iterating over those.
622 */
623struct GNUNET_TESTING_Trait
624GNUNET_TESTING_trait_end (void);
625
626
627/**
628 * Extract a trait.
629 *
630 * @param traits the array of all the traits.
631 * @param[out] ret where to store the result.
632 * @param trait type of the trait to extract.
633 * @param index index number of the trait to extract.
634 * @return #GNUNET_OK when the trait is found.
635 */
636enum GNUNET_GenericReturnValue
637GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
638 const void **ret,
639 const char *trait,
640 unsigned int index);
641
642
643/* ****** Specific traits supported by this component ******* */
644
645/**
646 * Obtain location where a command stores a pointer to a process.
647 *
648 * @param cmd command to extract trait from.
649 * @param index which process to pick if @a cmd
650 * has multiple on offer. -- FIXME: remove?
651 * @param[out] processp set to the address of the pointer to the
652 * process.
653 * @return #GNUNET_OK on success.
654 */
655enum GNUNET_GenericReturnValue
656GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd,
657 unsigned int index,
658 struct GNUNET_OS_Process ***processp);
659
660
661/**
662 * Offer location where a command stores a pointer to a process.
663 *
664 * @param index offered location index number, in case there are
665 * multiple on offer. // FIXME: remove?
666 * @param processp process location to offer.
667 * @return the trait.
668 */
669struct GNUNET_TESTING_Trait
670GNUNET_TESTING_make_trait_process (unsigned int index,
671 struct GNUNET_OS_Process **processp);
672
673
674/**
675 * Offer number trait, 32-bit version.
676 * 71 *
677 * @param index the number's index number. // FIXME: introduce enum? 72 * @param label Label of the command.
678 * @param n number to offer. 73 * @param script The name of the script.
679 */ 74 * @param script_argv The arguments of the script.
680struct GNUNET_TESTING_Trait 75*/
681GNUNET_TESTING_make_trait_uint32 (unsigned int index, 76const struct GNUNET_TESTING_Command
682 const uint32_t *n); 77GNUNET_TESTING_cmd_exec_bash_script (const char *label,
683 78 const char *script,
684 79 char *const script_argv[],
685/** 80 // FIXME: wtf are these two args here for!?
686 * Obtain a "number" value from @a cmd, 32-bit version. 81 int argc,
687 * 82 GNUNET_ChildCompletedCallback cb);
688 * @param cmd command to extract the number from.
689 * @param index the number's index number. // FIXME: introduce enum?
690 * @param[out] n set to the number coming from @a cmd.
691 * @return #GNUNET_OK on success.
692 */
693enum GNUNET_GenericReturnValue
694GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd,
695 unsigned int index,
696 const uint32_t **n);
697
698
699/**
700 * Offer number trait, 64-bit version.
701 *
702 * @param index the number's index number. // FIXME: introduce enum?
703 * @param n number to offer.
704 */
705struct GNUNET_TESTING_Trait
706GNUNET_TESTING_make_trait_uint64 (unsigned int index,
707 const uint64_t *n);
708
709
710/**
711 * Obtain a "number" value from @a cmd, 64-bit version.
712 *
713 * @param cmd command to extract the number from.
714 * @param index the number's index number. // FIXME: introduce enum?
715 * @param[out] n set to the number coming from @a cmd.
716 * @return #GNUNET_OK on success.
717 */
718enum GNUNET_GenericReturnValue
719GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd,
720 unsigned int index,
721 const uint64_t **n);
722
723
724/**
725 * Offer number trait, 64-bit signed version.
726 *
727 * @param index the number's index number. // FIXME: introduce enum?
728 * @param n number to offer.
729 */
730struct GNUNET_TESTING_Trait
731GNUNET_TESTING_make_trait_int64 (unsigned int index,
732 const int64_t *n);
733
734
735/**
736 * Obtain a "number" value from @a cmd, 64-bit signed version.
737 *
738 * @param cmd command to extract the number from.
739 * @param index the number's index number. // FIXME: introduce enum?
740 * @param[out] n set to the number coming from @a cmd.
741 * @return #GNUNET_OK on success.
742 */
743enum GNUNET_GenericReturnValue
744GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd,
745 unsigned int index,
746 const int64_t **n);
747
748
749/**
750 * Offer a number.
751 *
752 * @param index the number's index number.
753 * @param n the number to offer. // FIXME: introduce enum?
754 * @return #GNUNET_OK on success.
755 */
756struct GNUNET_TESTING_Trait
757GNUNET_TESTING_make_trait_uint (unsigned int index,
758 const unsigned int *i);
759
760
761/**
762 * Obtain a number from @a cmd.
763 *
764 * @param cmd command to extract the number from.
765 * @param index the number's index number. // FIXME: introduce enum?
766 * @param[out] n set to the number coming from @a cmd.
767 * @return #GNUNET_OK on success.
768 */
769enum GNUNET_GenericReturnValue
770GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd,
771 unsigned int index,
772 const unsigned int **n);
773
774/**
775 * Obtain a string from @a cmd.
776 *
777 * @param cmd command to extract the subject from.
778 * @param index index number associated with the transfer
779 * subject to offer. // FIXME: introduce enum?
780 * @param[out] s where to write the offered
781 * string.
782 * @return #GNUNET_OK on success.
783 */
784enum GNUNET_GenericReturnValue
785GNUNET_TESTING_get_trait_string (
786 const struct GNUNET_TESTING_Command *cmd,
787 unsigned int index,
788 const char **s);
789
790
791/**
792 * Offer string subject.
793 *
794 * @param index index number associated with the transfer
795 * subject being offered. // FIXME: introduce enum?
796 * @param s string to offer.
797 * @return the trait.
798 */
799struct GNUNET_TESTING_Trait
800GNUNET_TESTING_make_trait_string (unsigned int index,
801 const char *s);
802
803/**
804 * Offer a command in a trait.
805 *
806 * @param index always zero. Commands offering this
807 * kind of traits do not need this index. For
808 * example, a "meta" CMD returns always the
809 * CMD currently being executed. FIXME: remove!
810 * @param cmd wire details to offer.
811 * @return the trait.
812 */
813struct GNUNET_TESTING_Trait
814GNUNET_TESTING_make_trait_cmd (unsigned int index,
815 const struct GNUNET_TESTING_Command *cmd);
816
817
818/**
819 * Obtain a command from @a cmd.
820 *
821 * @param cmd command to extract the command from.
822 * @param index always zero. Commands offering this
823 * kind of traits do not need this index. For
824 * example, a "meta" CMD returns always the
825 * CMD currently being executed. FIXME: remove!
826 * @param[out] _cmd where to write the wire details.
827 * @return #GNUNET_OK on success.
828 */
829enum GNUNET_GenericReturnValue
830GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
831 unsigned int index,
832 struct GNUNET_TESTING_Command **_cmd);
833 83
834 84
835/**
836 * Obtain a uuid from @a cmd.
837 *
838 * @param cmd command to extract the uuid from.
839 * @param index which amount to pick if @a cmd has multiple
840 * on offer // FIXME: introduce enum?
841 * @param[out] uuid where to write the uuid.
842 * @return #GNUNET_OK on success.
843 */
844enum GNUNET_GenericReturnValue
845GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd,
846 unsigned int index,
847 struct GNUNET_Uuid **uuid);
848 85
849 86/* ****** Specific traits needed by this component ******* */
850/**
851 * Offer a uuid in a trait.
852 *
853 * @param index which uuid to offer, in case there are
854 * multiple available. // FIXME: introduce enum?
855 * @param uuid the uuid to offer.
856 * @return the trait.
857 */
858struct GNUNET_TESTING_Trait
859GNUNET_TESTING_make_trait_uuid (unsigned int index,
860 const struct GNUNET_Uuid *uuid);
861 87
862 88
863/** 89/**
864 * Obtain a absolute time from @a cmd. 90 * Call #op on all simple traits.
865 *
866 * @param cmd command to extract trait from
867 * @param index which time stamp to pick if
868 * @a cmd has multiple on offer // FIXME: introduce enum?
869 * @param[out] time set to the wanted WTID.
870 * @return #GNUNET_OK on success
871 */ 91 */
872enum GNUNET_GenericReturnValue 92#define GNUNET_TESTING_SIMPLE_TRAITS(op, prefix) \
873GNUNET_TESTING_get_trait_absolute_time ( 93 op (prefix, process, struct GNUNET_OS_Process *)
874 const struct GNUNET_TESTING_Command *cmd,
875 unsigned int index,
876 const struct GNUNET_TIME_Absolute **time);
877 94
878 95
879/** 96GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING)
880 * Offer a absolute time.
881 *
882 * @param index associate the object with this index
883 * @param time which object should be returned
884 * @return the trait.
885 */
886struct GNUNET_TESTING_Trait
887GNUNET_TESTING_make_trait_absolute_time (
888 unsigned int index,
889 const struct GNUNET_TIME_Absolute *time);
890
891 97
892/** 98/**
893 * Obtain a relative time from @a cmd. 99 * Call #op on all indexed traits.
894 *
895 * @param cmd command to extract trait from
896 * @param index which time to pick if
897 * @a cmd has multiple on offer.
898 * @param[out] time set to the wanted WTID.
899 * @return #GNUNET_OK on success
900 */ 100 */
901int 101#define GNUNET_TESTING_INDEXED_TRAITS(op, prefix) \
902GNUNET_TESTING_get_trait_relative_time ( 102 op (prefix, uint32, const uint32_t) \
903 const struct GNUNET_TESTING_Command *cmd, 103 op (prefix, uint64, const uint64_t) \
904 unsigned int index, 104 op (prefix, int64, const int64_t) \
905 const struct GNUNET_TIME_Relative **time); 105 op (prefix, uint, const unsigned int) \
106 op (prefix, string, const char) \
107 op (prefix, uuid, const struct GNUNET_Uuid) \
108 op (prefix, time, const struct GNUNET_TIME_Absolute) \
109 op (prefix, absolute_time, const struct GNUNET_TIME_Absolute) \
110 op (prefix, relative_time, const struct GNUNET_TIME_Relative)
906 111
112GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT, GNUNET_TESTING)
907 113
908/**
909 * Offer a relative time.
910 *
911 * @param index associate the object with this index
912 * @param time which object should be returned
913 * @return the trait.
914 */
915struct GNUNET_TESTING_Trait
916GNUNET_TESTING_make_trait_relative_time (
917 unsigned int index,
918 const struct GNUNET_TIME_Relative *time);
919 114
920#endif 115#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index b59d2cea1..b030bc8a8 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -28,6 +28,8 @@
28#ifndef GNUNET_TESTING_PLUGIN_H 28#ifndef GNUNET_TESTING_PLUGIN_H
29#define GNUNET_TESTING_PLUGIN_H 29#define GNUNET_TESTING_PLUGIN_H
30 30
31#include "gnunet_common.h"
32
31#ifdef __cplusplus 33#ifdef __cplusplus
32extern "C" 34extern "C"
33{ 35{
@@ -36,41 +38,101 @@ extern "C"
36#endif 38#endif
37#endif 39#endif
38 40
41
42/**
43 * Callback function to write messages from the helper process running on a netjail node to the master process.
44 *
45 * @param message The message to write.
46 * @param msg_length The length of the message.
47 */
39typedef void 48typedef void
40(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t 49(*GNUNET_TESTING_cmd_helper_write_cb) (struct GNUNET_MessageHeader *message,
41 msg_length); 50 size_t msg_length);
42 51
52/**
53 * 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.
54 */
43typedef void 55typedef void
44(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb 56(*GNUNET_TESTING_cmd_helper_finish_cb) ();
45 write_message, char *router_ip, 57
46 char *node_ip,
47 char *n,
48 char *m,
49 char *local_m,
50 char *topology_data,
51 unsigned int *read_file);
52 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) (
79 GNUNET_TESTING_cmd_helper_write_cb 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
88 finish_cb);
53 89
90/**
91 * DEPRECATED
92 * The helper process received a message of type
93 * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED. This will finish the blocking command
94 * GNUNET_TESTING_cmd_block_until_external_trigger which was execute right after the command
95 * GNUNET_TESTING_cmd_send_peer_ready.
96 */
54typedef void 97typedef void
55(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) (); 98(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
56 99
57 100/**
101 * DEPRECATED
102 * The helper process received a message of type
103 * GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED. This will finish the blocking command
104 * GNUNET_TESTING_cmd_local_test_prepared which was execute right after the command
105 * GNUNET_TRANSPORT_cmd_connect_peers.
106 * FIXME: do not use ALL CAPS
107 */
58typedef void 108typedef void
59(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) (); 109(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) ();
60 110
61 111
112/**
113 * This function returns a struct GNUNET_TESTING_BarrierList, which is a list of all barriers
114 * this test case will wait for.
115 *
116 * @return A struct GNUNET_TESTING_BarrierList.
117 * FIXME: do not use ALL CAPS
118 */
119typedef struct GNUNET_TESTING_BarrierList*
120(*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void);
121
122
123/**
124 * The plugin API every test case plugin has to implement.
125 */
62struct GNUNET_TESTING_PluginFunctions 126struct GNUNET_TESTING_PluginFunctions
63{ 127{
64 /**
65 * Closure for all of the callbacks.
66 */
67 void *cls;
68 128
69 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase; 129 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
70 130
71 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started; 131 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
72 132
73 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared; 133 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared;
134
135 GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS get_waiting_for_barriers;
74}; 136};
75 137
76#if 0 /* keep Emacsens' auto-indent happy */ 138#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 26b442066..88dafc62c 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -40,6 +44,7 @@ extern "C"
40#endif 44#endif
41#endif 45#endif
42 46
47
43#include "gnunet_common.h" 48#include "gnunet_common.h"
44 49
45/** 50/**
@@ -54,6 +59,17 @@ struct GNUNET_TIME_Absolute
54}; 59};
55 60
56/** 61/**
62 * Rounded time for timestamps used by GNUnet, in seconds.
63 */
64struct GNUNET_TIME_Timestamp
65{
66 /**
67 * The actual value. Must be round number in seconds.
68 */
69 struct GNUNET_TIME_Absolute abs_time;
70};
71
72/**
57 * Time for relative time used by GNUnet, in microseconds. 73 * Time for relative time used by GNUnet, in microseconds.
58 * Always positive, so we can only refer to future time. 74 * Always positive, so we can only refer to future time.
59 */ 75 */
@@ -89,17 +105,34 @@ struct GNUNET_TIME_AbsoluteNBO
89 */ 105 */
90 uint64_t abs_value_us__ GNUNET_PACKED; 106 uint64_t abs_value_us__ GNUNET_PACKED;
91}; 107};
108
109/**
110 * Time for timestamps used by GNUnet, in seconds and in network byte order.
111 */
112struct GNUNET_TIME_TimestampNBO
113{
114 /**
115 * The actual value. Must be round number in seconds.
116 */
117 struct GNUNET_TIME_AbsoluteNBO abs_time_nbo;
118};
119
92GNUNET_NETWORK_STRUCT_END 120GNUNET_NETWORK_STRUCT_END
93 121
94/** 122/**
95 * Relative time zero. 123 * Relative time zero.
96 */ 124 */
97#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_ () 125#define GNUNET_TIME_UNIT_ZERO ((struct GNUNET_TIME_Relative){0})
98 126
99/** 127/**
100 * Absolute time zero. 128 * Absolute time zero.
101 */ 129 */
102#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_ () 130#define GNUNET_TIME_UNIT_ZERO_ABS ((struct GNUNET_TIME_Absolute){0})
131
132/**
133 * Timestamp of zero.
134 */
135#define GNUNET_TIME_UNIT_ZERO_TS ((struct GNUNET_TIME_Timestamp){{0}})
103 136
104/** 137/**
105 * One microsecond, our basic time unit. 138 * One microsecond, our basic time unit.
@@ -154,13 +187,22 @@ GNUNET_NETWORK_STRUCT_END
154 * Constant used to specify "forever". This constant 187 * Constant used to specify "forever". This constant
155 * will be treated specially in all time operations. 188 * will be treated specially in all time operations.
156 */ 189 */
157#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ () 190#define GNUNET_TIME_UNIT_FOREVER_REL \
191 ((struct GNUNET_TIME_Relative){UINT64_MAX})
192
193/**
194 * Constant used to specify "forever". This constant
195 * will be treated specially in all time operations.
196 */
197#define GNUNET_TIME_UNIT_FOREVER_ABS \
198 ((struct GNUNET_TIME_Absolute){UINT64_MAX})
158 199
159/** 200/**
160 * Constant used to specify "forever". This constant 201 * Constant used to specify "forever". This constant
161 * will be treated specially in all time operations. 202 * will be treated specially in all time operations.
162 */ 203 */
163#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () 204#define GNUNET_TIME_UNIT_FOREVER_TS \
205 ((struct GNUNET_TIME_Timestamp){{UINT64_MAX}})
164 206
165 207
166/** 208/**
@@ -183,6 +225,47 @@ GNUNET_NETWORK_STRUCT_END
183 225
184 226
185/** 227/**
228 * Convert @a ts to human-readable timestamp.
229 * Note that the returned value will be overwritten if this function
230 * is called again.
231 *
232 * @param ts the timestamp to convert
233 * @return statically allocated string, will change on the next call
234 */
235const char *
236GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts);
237
238
239/**
240 * @ingroup time
241 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal
242 * absolute time (which is in UTC) to a string in local time.
243 * Note that the returned value will be overwritten if this function
244 * is called again.
245 *
246 * @param ts the absolute time to convert
247 * @return timestamp in human-readable form in local time
248 */
249const char *
250GNUNET_TIME_absolute2s (struct GNUNET_TIME_Absolute ts);
251
252
253/**
254 * @ingroup time
255 * Give relative time in human-readable fancy format.
256 * This is one of the very few calls in the entire API that is
257 * NOT reentrant!
258 *
259 * @param delta time in milli seconds
260 * @param do_round are we allowed to round a bit?
261 * @return string in human-readable form
262 */
263const char *
264GNUNET_TIME_relative2s (struct GNUNET_TIME_Relative delta,
265 bool do_round);
266
267
268/**
186 * Randomized exponential back-off, starting at 1 ms 269 * Randomized exponential back-off, starting at 1 ms
187 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up 270 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up
188 * to a maximum of the given threshold. 271 * to a maximum of the given threshold.
@@ -192,8 +275,8 @@ GNUNET_NETWORK_STRUCT_END
192 * @return the next backoff time 275 * @return the next backoff time
193 */ 276 */
194struct GNUNET_TIME_Relative 277struct GNUNET_TIME_Relative
195GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, struct 278GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
196 GNUNET_TIME_Relative threshold); 279 struct GNUNET_TIME_Relative threshold);
197 280
198 281
199/** 282/**
@@ -290,27 +373,69 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel);
290 373
291 374
292/** 375/**
293 * Round a time value so that it is suitable for transmission 376 * Convert relative time to a timestamp in the
294 * via JSON encodings. 377 * future.
378 *
379 * @param rel relative time to convert
380 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
381 */
382struct GNUNET_TIME_Timestamp
383GNUNET_TIME_relative_to_timestamp (struct GNUNET_TIME_Relative rel);
384
385
386/**
387 * Round an absolute time to a timestamp.
295 * 388 *
296 * @param at time to round 389 * @param at time to round
297 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if 390 * @return the result
298 * it was just now rounded
299 */ 391 */
300int 392struct GNUNET_TIME_Timestamp
301GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at); 393GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at);
302 394
303 395
304/** 396/**
305 * Round a time value so that it is suitable for transmission 397 * Get timestamp representing the current time.
306 * via JSON encodings.
307 * 398 *
308 * @param rt time to round 399 * @return current time, rounded down to seconds
309 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if
310 * it was just now rounded
311 */ 400 */
312int 401struct GNUNET_TIME_Timestamp
313GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt); 402GNUNET_TIME_timestamp_get (void);
403
404
405/**
406 * Compare two absolute times.
407 *
408 * @param t1 first time
409 * @param op compare operator
410 * @param t2 second time
411 * @return true if @a t1 @a op @a t2
412 */
413#define GNUNET_TIME_absolute_cmp(t1,op,t2) \
414 ((void) (1 op 2), (t1).abs_value_us op (t2).abs_value_us)
415
416
417/**
418 * Compare two timestamps
419 *
420 * @param t1 first timestamp
421 * @param op compare operator
422 * @param t2 second timestamp
423 * @return true if @a t1 @a op @a t2
424 */
425#define GNUNET_TIME_timestamp_cmp(t1,op,t2) \
426 GNUNET_TIME_absolute_cmp ((t1).abs_time,op,(t2).abs_time)
427
428
429/**
430 * Compare two relative times.
431 *
432 * @param t1 first time
433 * @param op compare operator
434 * @param t2 second time
435 * @return true if @a t1 @a op @a t2
436 */
437#define GNUNET_TIME_relative_cmp(t1,op,t2) \
438 ((void) (1 op 2), (t1).rel_value_us op (t2).rel_value_us)
314 439
315 440
316/** 441/**
@@ -362,6 +487,42 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
362 487
363 488
364/** 489/**
490 * Round down absolute time @a at to multiple of @a rt.
491 *
492 * @param at absolute time to round
493 * @param rt multiple to round to (non-zero)
494 * @return rounded time
495 */
496struct GNUNET_TIME_Absolute
497GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at,
498 struct GNUNET_TIME_Relative rt);
499
500
501/**
502 * Return the maximum of two timestamps.
503 *
504 * @param t1 first timestamp
505 * @param t2 other timestamp
506 * @return timestamp that is smaller
507 */
508struct GNUNET_TIME_Timestamp
509GNUNET_TIME_timestamp_max (struct GNUNET_TIME_Timestamp t1,
510 struct GNUNET_TIME_Timestamp t2);
511
512
513/**
514 * Return the minimum of two timestamps.
515 *
516 * @param t1 first timestamp
517 * @param t2 other timestamp
518 * @return timestamp that is smaller
519 */
520struct GNUNET_TIME_Timestamp
521GNUNET_TIME_timestamp_min (struct GNUNET_TIME_Timestamp t1,
522 struct GNUNET_TIME_Timestamp t2);
523
524
525/**
365 * Given a timestamp in the future, how much time 526 * Given a timestamp in the future, how much time
366 * remains until then? 527 * remains until then?
367 * 528 *
@@ -373,6 +534,21 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future);
373 534
374 535
375/** 536/**
537 * Test if @a a1 and @a a2 are equal within a margin of
538 * error of @a t.
539 *
540 * @param a1 time to compare
541 * @param a2 time to compare
542 * @param t tolerance to apply
543 * @return true if "|a1-a2|<=t" holds.
544 */
545bool
546GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1,
547 struct GNUNET_TIME_Absolute a2,
548 struct GNUNET_TIME_Relative t);
549
550
551/**
376 * Calculate the estimate time of arrival/completion 552 * Calculate the estimate time of arrival/completion
377 * for an operation. 553 * for an operation.
378 * 554 *
@@ -443,6 +619,17 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
443 * Multiply relative time by a given factor. 619 * Multiply relative time by a given factor.
444 * 620 *
445 * @param rel some duration 621 * @param rel some duration
622 * @param factor double to multiply with
623 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
624 */
625struct GNUNET_TIME_Relative
626GNUNET_TIME_relative_multiply_double (struct GNUNET_TIME_Relative rel,
627 double factor);
628
629/**
630 * Multiply relative time by a given factor.
631 *
632 * @param rel some duration
446 * @param factor integer to multiply with 633 * @param factor integer to multiply with
447 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 634 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
448 */ 635 */
@@ -530,6 +717,16 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
530 717
531 718
532/** 719/**
720 * Convert timestamp to network byte order.
721 *
722 * @param t time to convert
723 * @return converted time value
724 */
725struct GNUNET_TIME_TimestampNBO
726GNUNET_TIME_timestamp_hton (struct GNUNET_TIME_Timestamp t);
727
728
729/**
533 * Convert milliseconds after the UNIX epoch to absolute time. 730 * Convert milliseconds after the UNIX epoch to absolute time.
534 * 731 *
535 * @param ms_after_epoch millisecond timestamp to convert 732 * @param ms_after_epoch millisecond timestamp to convert
@@ -558,6 +755,15 @@ GNUNET_TIME_absolute_is_past (struct GNUNET_TIME_Absolute abs);
558 755
559 756
560/** 757/**
758 * Test if @a abs is truly zero.
759 *
760 * @return true if it is.
761 */
762bool
763GNUNET_TIME_absolute_is_zero (struct GNUNET_TIME_Absolute abs);
764
765
766/**
561 * Test if @a abs is truly in the future (excluding now). 767 * Test if @a abs is truly in the future (excluding now).
562 * 768 *
563 * @return true if it is. 769 * @return true if it is.
@@ -595,6 +801,26 @@ GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
595 801
596 802
597/** 803/**
804 * Convert seconds after the UNIX epoch to timestamp.
805 *
806 * @param s_after_epoch seconds after epoch to convert
807 * @return converted time value
808 */
809struct GNUNET_TIME_Timestamp
810GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch);
811
812
813/**
814 * Convert timestamp to number of seconds after the UNIX epoch.
815 *
816 * @param ts timestamp to convert
817 * @return converted time value
818 */
819uint64_t
820GNUNET_TIME_timestamp_to_s (struct GNUNET_TIME_Timestamp ts);
821
822
823/**
598 * Convert absolute time from network byte order. 824 * Convert absolute time from network byte order.
599 * 825 *
600 * @param a time to convert 826 * @param a time to convert
@@ -605,6 +831,16 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
605 831
606 832
607/** 833/**
834 * Convert timestamp from network byte order.
835 *
836 * @param tn time to convert
837 * @return converted time value
838 */
839struct GNUNET_TIME_Timestamp
840GNUNET_TIME_timestamp_ntoh (struct GNUNET_TIME_TimestampNBO tn);
841
842
843/**
608 * Set the timestamp offset for this instance. 844 * Set the timestamp offset for this instance.
609 * 845 *
610 * @param offset the offset to skew the locale time by 846 * @param offset the offset to skew the locale time by
@@ -690,4 +926,6 @@ GNUNET_TIME_absolute_get_monotonic (
690 926
691/** @} */ /* end of group time */ 927/** @} */ /* end of group time */
692 928
929/** @} */ /* end of group addition */
930
693/* end of gnunet_time_lib.h */ 931/* end of gnunet_time_lib.h */
diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h
index f5d4c4ee0..66512089a 100644
--- a/src/include/gnunet_transport_application_service.h
+++ b/src/include/gnunet_transport_application_service.h
@@ -18,23 +18,24 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @file 24 * @file
22 * Bandwidth allocation API for applications to interact with 25 * Bandwidth allocation API for applications to interact with
23 * 26 *
24 * @author Christian Grothoff 27 * @author Christian Grothoff
25 * @author Matthias Wachs 28 * @author Matthias Wachs
26 * 29 *
27 * @defgroup TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Bandwidth allocation
29 *
30 * @{ 31 * @{
31 */ 32 */
32#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H 33#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H
33#define GNUNET_TRANSPORT_APPLICATION_SERVICE_H 34#define GNUNET_TRANSPORT_APPLICATION_SERVICE_H
34 35
36
35#include "gnunet_constants.h" 37#include "gnunet_constants.h"
36#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
37#include "gnunet_nt_lib.h"
38#include "gnunet_testing_lib.h" 39#include "gnunet_testing_lib.h"
39#include "gnunet_testing_ng_lib.h" 40#include "gnunet_testing_ng_lib.h"
40 41
@@ -118,5 +119,7 @@ GNUNET_TRANSPORT_application_validate (
118 119
119/** @} */ /* end of group */ 120/** @} */ /* end of group */
120 121
122/** @} */ /* end of group addition */
123
121#endif 124#endif
122/* end of file gnunet_ats_application_service.h */ 125/* end of file gnunet_ats_application_service.h */
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index 81a382fb2..ea947911f 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
25 * API of the transport service towards the communicator processes. 28 * API of the transport service towards the communicator processes.
26 * 29 *
27 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Low-level communication with other peers 31 * Low-level communication with other peers
29 * 32 *
30 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -42,8 +45,8 @@ extern "C" {
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_nt_lib.h"
47 50
48/** 51/**
49 * Version number of the transport communication API. 52 * Version number of the transport communication API.
@@ -71,7 +74,7 @@ extern "C" {
71 * @param address where to send the message, human-readable 74 * @param address where to send the message, human-readable
72 * communicator-specific format, 0-terminated, UTF-8 75 * communicator-specific format, 0-terminated, UTF-8
73 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is 76 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is
74 * invalid 77 * invalid, #GNUNET_NO if this address is already (beging) connected to.
75 */ 78 */
76typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( 79typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) (
77 void *cls, 80 void *cls,
@@ -135,7 +138,8 @@ typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) (
135 * Connect to the transport service. 138 * Connect to the transport service.
136 * 139 *
137 * @param cfg configuration to use 140 * @param cfg configuration to use
138 * @param config_section section of the configuration to use for options 141 * @param config_section_name section of the configuration to use for
142 * options
139 * @param addr_prefix address prefix for addresses supported by this 143 * @param addr_prefix address prefix for addresses supported by this
140 * communicator, could be NULL for incoming-only communicators 144 * communicator, could be NULL for incoming-only communicators
141 * @param cc what characteristics does the communicator have? 145 * @param cc what characteristics does the communicator have?
@@ -280,7 +284,7 @@ GNUNET_TRANSPORT_communicator_mq_add (
280 * Notify transport service that an MQ was updated 284 * Notify transport service that an MQ was updated
281 * 285 *
282 * @param ch connection to transport service 286 * @param ch connection to transport service
283 * @param qh the queue to update 287 * @param u_qh the queue to update
284 * @param q_len number of messages that can be send through this queue 288 * @param q_len number of messages that can be send through this queue
285 * @param priority queue priority. Queues with highest priority should be 289 * @param priority queue priority. Queues with highest priority should be
286 * used 290 * used
@@ -383,4 +387,6 @@ GNUNET_TRANSPORT_communicator_notify (
383 387
384/** @} */ /* end of group */ 388/** @} */ /* end of group */
385 389
390/** @} */ /* end of group addition */
391
386/* end of gnunet_transport_communicator_service.h */ 392/* end of gnunet_transport_communicator_service.h */
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h
index 314eb342f..f7907a12d 100644
--- a/src/include/gnunet_transport_core_service.h
+++ b/src/include/gnunet_transport_core_service.h
@@ -18,12 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * 25 *
23 * @file 26 * @file
24 * API of the transport service towards the CORE service (TNG version) 27 * API of the transport service towards the CORE service (TNG version)
25 * 28 *
26 * @defgroup transport TRANSPORT service 29 * @defgroup TNG Transport Next Generation service
27 * Communication with other peers 30 * Communication with other peers
28 * 31 *
29 * @see [Documentation](https://gnunet.org/transport-service) 32 * @see [Documentation](https://gnunet.org/transport-service)
@@ -40,6 +43,7 @@ extern "C" {
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
44 48
45/** 49/**
@@ -174,4 +178,6 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
174 178
175/** @} */ /* end of group */ 179/** @} */ /* end of group */
176 180
181/** @} */ /* end of group addition */
182
177/* end of gnunet_transport_core_service.h */ 183/* end of gnunet_transport_core_service.h */
diff --git a/src/include/gnunet_transport_hello_service.h b/src/include/gnunet_transport_hello_service.h
deleted file mode 100644
index fecffd527..000000000
--- a/src/include/gnunet_transport_hello_service.h
+++ /dev/null
@@ -1,201 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * obtain information about our current address
26 *
27 * @deprecated, in TNG applications should query PEERSTORE directly!
28 *
29 * @defgroup transport Transport service
30 * address information
31 *
32 * @see [Documentation](https://gnunet.org/transport-service)
33 *
34 * @{
35 */
36#ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H
37#define GNUNET_TRANSPORT_HELLO_SERVICE_H
38
39#ifdef __cplusplus
40extern "C" {
41#if 0 /* keep Emacsens' auto-indent happy */
42}
43#endif
44#endif
45
46#include "gnunet_util_lib.h"
47#include "gnunet_ats_service.h"
48
49/**
50 * Version number of the transport API.
51 */
52#define GNUNET_TRANSPORT_HELLO_VERSION 0x00000000
53
54
55/**
56 * Some addresses contain sensitive information or are
57 * not suitable for global distribution. We use address
58 * classes to filter addresses by which domain they make
59 * sense to be used in. These are used in a bitmask.
60 */
61enum GNUNET_TRANSPORT_AddressClass
62{
63 /**
64 * No address.
65 */
66 GNUNET_TRANSPORT_AC_NONE = 0,
67
68 /**
69 * Addresses that fall into no other category
70 * (i.e. incoming which we cannot use elsewhere).
71 */
72 GNUNET_TRANSPORT_AC_OTHER = 1,
73
74 /**
75 * Addresses that are global and are insensitive
76 * (i.e. IPv4).
77 */
78 GNUNET_TRANSPORT_AC_GLOBAL = 2,
79
80 /**
81 * Addresses that are global and are sensitive
82 * (i.e. IPv6 with our MAC).
83 */
84 GNUNET_TRANSPORT_AC_GLOBAL_PRIVATE = 4,
85
86 /**
87 * Addresses useful in the local wired network,
88 * i.e. a MAC. Sensitive, but obvious to people nearby.
89 * Useful for broadcasts.
90 */
91 GNUNET_TRANSPORT_AC_LAN = 8,
92
93 /**
94 * Addresses useful in the local wireless network,
95 * i.e. a MAC. Sensitive, but obvious to people nearby.
96 * Useful for broadcasts.
97 */
98 GNUNET_TRANSPORT_AC_WLAN = 16,
99
100 /**
101 * Addresses useful in the local bluetooth network. Sensitive, but
102 * obvious to people nearby. Useful for broadcasts.
103 */
104 GNUNET_TRANSPORT_AC_BT = 32,
105
106 /**
107 * Bitmask for "any" address.
108 */
109 GNUNET_TRANSPORT_AC_ANY = 65535
110};
111
112
113/**
114 * Function called whenever there is an update to the
115 * HELLO of this peer.
116 *
117 * @param cls closure
118 * @param hello our updated HELLO
119 */
120typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (
121 void *cls,
122 const struct GNUNET_MessageHeader *hello);
123
124
125/**
126 * Handle to cancel a #GNUNET_TRANSPORT_hello_get() operation.
127 */
128struct GNUNET_TRANSPORT_HelloGetHandle;
129
130
131/**
132 * Obtain updates on changes to the HELLO message for this peer. The callback
133 * given in this function is never called synchronously.
134 *
135 * @param cfg configuration to use
136 * @param ac which network type should the addresses from the HELLO belong to?
137 * @param rec function to call with the HELLO
138 * @param rec_cls closure for @a rec
139 * @return handle to cancel the operation
140 */
141struct GNUNET_TRANSPORT_HelloGetHandle *
142GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
143 enum GNUNET_TRANSPORT_AddressClass ac,
144 GNUNET_TRANSPORT_HelloUpdateCallback rec,
145 void *rec_cls);
146
147
148/**
149 * Stop receiving updates about changes to our HELLO message.
150 *
151 * @param ghh handle to cancel
152 */
153void
154GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
155
156
157/**
158 * Function with addresses found in a HELLO.
159 *
160 * @param cls closure
161 * @param peer identity of the peer
162 * @param address the address (UTF-8, 0-terminated)
163 * @param nt network type of the address
164 * @param expiration when does this address expire?
165 */
166typedef void (*GNUNET_TRANSPORT_AddressCallback) (
167 void *cls,
168 const struct GNUNET_PeerIdentity *peer,
169 const char *address,
170 enum GNUNET_NetworkType nt,
171 struct GNUNET_TIME_Absolute expiration);
172
173
174/**
175 * Parse a HELLO message that we have received into its
176 * constituent addresses.
177 *
178 * @param hello message to parse
179 * @param cb function to call on each address found
180 * @param cb_cls closure for @a cb
181 * @return #GNUNET_OK if hello was well-formed, #GNUNET_SYSERR if not
182 */
183int
184GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello,
185 GNUNET_TRANSPORT_AddressCallback cb,
186 void *cb_cls);
187
188
189#if 0 /* keep Emacsens' auto-indent happy */
190{
191#endif
192#ifdef __cplusplus
193}
194#endif
195
196/* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */
197#endif
198
199/** @} */ /* end of group */
200
201/* end of gnunet_transport_hello_service.h */
diff --git a/src/include/gnunet_transport_manipulation_service.h b/src/include/gnunet_transport_manipulation_service.h
deleted file mode 100644
index 09fb138f8..000000000
--- a/src/include/gnunet_transport_manipulation_service.h
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2014, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Low-level P2P IO
26 *
27 * @defgroup transport Transport service
28 * Low-level P2P IO
29 *
30 * @see [Documentation](https://gnunet.org/transport-service)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
36#define GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
37
38
39#ifdef __cplusplus
40extern "C"
41{
42#if 0 /* keep Emacsens' auto-indent happy */
43}
44#endif
45#endif
46
47#include "gnunet_util_lib.h"
48#include "gnunet_ats_service.h"
49
50/**
51 * Version number of the transport API.
52 */
53#define GNUNET_TRANSPORT_MANIPULATION_VERSION 0x00000003
54
55/**
56 * Handle for transport manipulation.
57 */
58struct GNUNET_TRANSPORT_ManipulationHandle;
59
60
61/**
62 * Connect to the transport service. Note that the connection may
63 * complete (or fail) asynchronously.
64 *
65 * @param cfg configuration to use
66 * @return NULL on error
67 */
68struct GNUNET_TRANSPORT_ManipulationHandle *
69GNUNET_TRANSPORT_manipulation_connect (const struct
70 GNUNET_CONFIGURATION_Handle *cfg);
71
72
73/**
74 * Disconnect from the transport service.
75 *
76 * @param handle handle returned from connect
77 */
78void
79GNUNET_TRANSPORT_manipulation_disconnect (struct
80 GNUNET_TRANSPORT_ManipulationHandle *
81 handle);
82
83
84/**
85 * Set transport metrics for a peer and a direction
86 *
87 * @param handle transport handle
88 * @param peer the peer to set the metric for
89 * @param prop the performance metrics to set
90 * @param delay_in inbound delay to introduce
91 * @param delay_out outbound delay to introduce
92 *
93 * Note: Delay restrictions in receiving direction will be enforced
94 * with one message delay.
95 */
96void
97GNUNET_TRANSPORT_manipulation_set (struct
98 GNUNET_TRANSPORT_ManipulationHandle *handle,
99 const struct GNUNET_PeerIdentity *peer,
100 const struct GNUNET_ATS_Properties *prop,
101 struct GNUNET_TIME_Relative delay_in,
102 struct GNUNET_TIME_Relative delay_out);
103
104
105#if 0 /* keep Emacsens' auto-indent happy */
106{
107#endif
108#ifdef __cplusplus
109}
110#endif
111
112/* ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H */
113#endif
114
115/** @} */ /* end of group */
116
117/* end of gnunet_transport_manipulation_service.h */
diff --git a/src/include/gnunet_transport_monitor_service.h b/src/include/gnunet_transport_monitor_service.h
index f39be16d7..7c586b51e 100644
--- a/src/include/gnunet_transport_monitor_service.h
+++ b/src/include/gnunet_transport_monitor_service.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
25 * Monitoring / diagnostics API for the transport service 28 * Monitoring / diagnostics API for the transport service
26 * 29 *
27 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Communication with other peers 31 * Communication with other peers
29 * 32 *
30 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -42,8 +45,8 @@ extern "C"
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_ats_transport_service.h"
47#include "gnunet_transport_communication_service.h" 50#include "gnunet_transport_communication_service.h"
48 51
49 52
@@ -189,4 +192,6 @@ GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc);
189 192
190/** @} */ /* end of group */ 193/** @} */ /* end of group */
191 194
195/** @} */ /* end of group addition */
196
192/* end of gnunet_transport_monitor_service.h */ 197/* end of gnunet_transport_monitor_service.h */
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
deleted file mode 100644
index 74b27923a..000000000
--- a/src/include/gnunet_transport_plugin.h
+++ /dev/null
@@ -1,727 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009-2014 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Transport service plugin API
26 *
27 * @defgroup transport-plugin Transport Service plugin API
28 *
29 * Specifies the struct that is given to the plugin's entry method and the other
30 * struct that must be returned. Note that the destructors of transport plugins
31 * will be given the value returned by the constructor and is expected to return
32 * a NULL pointer.
33 *
34 * @{
35 */
36#ifndef PLUGIN_TRANSPORT_H
37#define PLUGIN_TRANSPORT_H
38
39#include "gnunet_configuration_lib.h"
40#include "gnunet_scheduler_lib.h"
41#include "gnunet_statistics_service.h"
42#include "gnunet_transport_service.h"
43#include "gnunet_ats_service.h"
44
45#define TRANSPORT_SESSION_INBOUND_STRING "<inbound>"
46
47/**
48 * Opaque pointer that plugins can use to distinguish specific
49 * connections to a given peer. Typically used by stateful plugins to
50 * allow the service to refer to specific streams instead of a more
51 * general notion of "some connection" to the given peer. This is
52 * useful since sometimes (e.g. for inbound TCP connections) a
53 * connection may not have an address that can be used for meaningful
54 * distinction between sessions to the same peer.
55 *
56 * Each 'struct GNUNET_ATS_Session' MUST start with the 'struct GNUNET_PeerIdentity'
57 * of the peer the session is for (which will be used for some error
58 * checking by the ATS code).
59 */
60struct GNUNET_ATS_Session;
61
62
63/**
64 * Function that will be called whenever the plugin internally
65 * cleans up a session pointer and hence the service needs to
66 * discard all of those sessions as well. Plugins that do not
67 * use sessions can simply omit calling this function and always
68 * use NULL wherever a session pointer is needed. This function
69 * should be called BEFORE a potential "TransmitContinuation"
70 * from the "TransmitFunction".
71 *
72 * @param cls closure
73 * @param peer which peer was the session for
74 * @param session which session is being destroyed
75 */
76typedef void
77(*GNUNET_TRANSPORT_SessionEnd) (void *cls,
78 const struct GNUNET_HELLO_Address *address,
79 struct GNUNET_ATS_Session *session);
80
81
82/**
83 * Plugin tells transport service about a new inbound session
84 *
85 * @param cls unused
86 * @param address the address
87 * @param session the new session
88 * @param net network information
89 */
90typedef void
91(*GNUNET_TRANSPORT_SessionStart) (void *cls,
92 const struct GNUNET_HELLO_Address *address,
93 struct GNUNET_ATS_Session *session,
94 enum GNUNET_NetworkType net);
95
96
97/**
98 * Function called by the transport for each received message.
99 * This function should also be called with "NULL" for the
100 * message to signal that the other peer disconnected.
101 *
102 * @param cls closure
103 * @param peer (claimed) identity of the other peer
104 * @param message the message, NULL if we only care about
105 * learning about the delay until we should receive again
106 * @param session identifier used for this session (NULL for plugins
107 * that do not offer bi-directional communication to the sender
108 * using the same "connection")
109 * @param sender_address binary address of the sender (if we established the
110 * connection or are otherwise sure of it; should be NULL
111 * for inbound TCP/UDP connections since it it not clear
112 * that we could establish ourselves a connection to that
113 * IP address and get the same system)
114 * @param sender_address_len number of bytes in @a sender_address
115 * @return how long the plugin should wait until receiving more data;
116 * returning #GNUNET_TIME_UNIT_FOREVER_REL means that the
117 * connection should be closed
118 */
119typedef struct GNUNET_TIME_Relative
120(*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
121 const struct
122 GNUNET_HELLO_Address *address,
123 struct GNUNET_ATS_Session *session,
124 const struct
125 GNUNET_MessageHeader *message);
126
127
128/**
129 * Function that can be called by plugins to figure if an address is
130 * an loopback, LAN or WAN address. Ultimately invokes
131 * #GNUNET_ATS_address_get_type().
132 *
133 * @param cls closure
134 * @param addr binary address
135 * @param addrlen length of the @a addr
136 * @return type of the network the address belongs to
137 */
138typedef enum GNUNET_NetworkType
139(*GNUNET_TRANSPORT_AddressToType)(void *cls,
140 const struct sockaddr *addr,
141 size_t addrlen);
142
143
144/**
145 * Function called when distance of an address changes.
146 *
147 * @param cls closure
148 * @param peer peer
149 * @param distance new distance
150 */
151typedef void
152(*GNUNET_TRANSPORT_UpdateAddressDistance) (void *cls,
153 const struct
154 GNUNET_HELLO_Address *address,
155 uint32_t distance);
156
157
158/**
159 * Function that will be called for each address the transport
160 * is aware that it might be reachable under.
161 *
162 * @param cls closure
163 * @param add_remove should the address added (#GNUNET_YES) or removed (#GNUNET_NO) from the
164 * set of valid addresses?
165 * @param address the address to add or remove
166 */
167typedef void
168(*GNUNET_TRANSPORT_AddressNotification) (void *cls,
169 int add_remove,
170 const struct
171 GNUNET_HELLO_Address *address);
172
173
174/**
175 * Function that will be called whenever the plugin receives data over
176 * the network and wants to determine how long it should wait until
177 * the next time it reads from the given peer. Note that some plugins
178 * (such as UDP) may not be able to wait (for a particular peer), so
179 * the waiting part is optional. Plugins that can wait should call
180 * this function, sleep the given amount of time, and call it again
181 * (with zero bytes read) UNTIL it returns zero and only then read.
182 *
183 * @param cls closure
184 * @param peer which peer did we read data from
185 * @param amount_recved number of bytes read (can be zero)
186 * @return how long to wait until reading more from this peer
187 * (to enforce inbound quotas); returning #GNUNET_TIME_UNIT_FOREVER_REL
188 * means that the connection should be closed
189 */
190typedef struct GNUNET_TIME_Relative
191(*GNUNET_TRANSPORT_TrafficReport) (void *cls,
192 const struct GNUNET_PeerIdentity *peer,
193 size_t amount_recved);
194
195
196/**
197 * Function that returns a HELLO message.
198 *
199 * @return HELLO message (FIXME with what?)
200 */
201typedef const struct GNUNET_MessageHeader *
202(*GNUNET_TRANSPORT_GetHelloCallback) (void);
203
204
205/**
206 * The transport service will pass a pointer to a struct
207 * of this type as the first and only argument to the
208 * entry point of each transport plugin.
209 */
210struct GNUNET_TRANSPORT_PluginEnvironment
211{
212 /**
213 * Configuration to use.
214 */
215 const struct GNUNET_CONFIGURATION_Handle *cfg;
216
217 /**
218 * Identity of this peer.
219 */
220 const struct GNUNET_PeerIdentity *my_identity;
221
222 /**
223 * Closure for the various callbacks.
224 */
225 void *cls;
226
227 /**
228 * Handle for reporting statistics.
229 */
230 struct GNUNET_STATISTICS_Handle *stats;
231
232 /**
233 * Function that should be called by the transport plugin
234 * whenever a message is received. If this field is "NULL",
235 * the plugin should load in 'stub' mode and NOT fully
236 * initialize and instead only return an API with the
237 * @e address_pretty_printer, @e address_to_string and
238 * @e string_to_address functions.
239 */
240 GNUNET_TRANSPORT_PluginReceiveCallback receive;
241
242 /**
243 * Function that returns our HELLO.
244 */
245 GNUNET_TRANSPORT_GetHelloCallback get_our_hello;
246
247 /**
248 * Function that must be called by each plugin to notify the
249 * transport service about the addresses under which the transport
250 * provided by the plugin can be reached.
251 */
252 GNUNET_TRANSPORT_AddressNotification notify_address;
253
254 /**
255 * Function that must be called by the plugin when a non-NULL
256 * session handle stops being valid (is destroyed).
257 */
258 GNUNET_TRANSPORT_SessionEnd session_end;
259
260 /**
261 * Function called by the plugin when a new (incoming) session was created
262 * not explicitly created using the the get_session function
263 */
264 GNUNET_TRANSPORT_SessionStart session_start;
265
266 /**
267 * Function that will be called to figure if an address is an loopback,
268 * LAN, WAN etc. address
269 */
270 GNUNET_TRANSPORT_AddressToType get_address_type;
271
272 /**
273 * Function that will be called by DV to update distance for
274 * an address.
275 */
276 GNUNET_TRANSPORT_UpdateAddressDistance update_address_distance;
277
278 /**
279 * What is the maximum number of connections that this transport
280 * should allow? Transports that do not have sessions (such as
281 * UDP) can ignore this value.
282 */
283 uint32_t max_connections;
284};
285
286
287/**
288 * Function called by the #GNUNET_TRANSPORT_TransmitFunction
289 * upon "completion". In the case that a peer disconnects,
290 * this function must be called for each pending request
291 * (with a 'failure' indication) AFTER notifying the service
292 * about the disconnect event (so that the service won't try
293 * to transmit more messages, believing the connection still
294 * exists...).
295 *
296 * @param cls closure
297 * @param target who was the recipient of the message?
298 * @param result #GNUNET_OK on success
299 * #GNUNET_SYSERR if the target disconnected;
300 * disconnect will ALSO be signalled using
301 * the ReceiveCallback.
302 * @param size_payload bytes of payload from transport service in message
303 * @param size_on_wire bytes required on wire for transmission,
304 * 0 if result == #GNUNET_SYSERR
305 */
306typedef void
307(*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
308 const struct
309 GNUNET_PeerIdentity *target,
310 int result,
311 size_t size_payload,
312 size_t size_on_wire);
313
314
315/**
316 * The new send function with just the session and no address
317 *
318 * Function that can be used by the transport service to transmit
319 * a message using the plugin. Note that in the case of a
320 * peer disconnecting, the continuation MUST be called
321 * prior to the disconnect notification itself. This function
322 * will be called with this peer's HELLO message to initiate
323 * a fresh connection to another peer.
324 *
325 * @param cls closure
326 * @param session which session must be used
327 * @param msgbuf the message to transmit
328 * @param msgbuf_size number of bytes in @a msgbuf
329 * @param priority how important is the message (most plugins will
330 * ignore message priority and just FIFO)
331 * @param to how long to wait at most for the transmission (does not
332 * require plugins to discard the message after the timeout,
333 * just advisory for the desired delay; most plugins will ignore
334 * this as well)
335 * @param cont continuation to call once the message has
336 * been transmitted (or if the transport is ready
337 * for the next transmission call; or if the
338 * peer disconnected...); can be NULL
339 * @param cont_cls closure for @a cont
340 * @return number of bytes used (on the physical network, with overheads);
341 * -1 on hard errors (i.e. address invalid); 0 is a legal value
342 * and does NOT mean that the message was not transmitted (DV)
343 */
344typedef ssize_t
345(*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
346 struct GNUNET_ATS_Session *session,
347 const char *msgbuf,
348 size_t msgbuf_size,
349 unsigned int priority,
350 struct GNUNET_TIME_Relative to,
351 GNUNET_TRANSPORT_TransmitContinuation cont,
352 void *cont_cls);
353
354
355/**
356 * Function that can be called to force a disconnect from the
357 * specified neighbour for the given session only. . This should
358 * also cancel all previously scheduled transmissions for this
359 * session. Obviously the transmission may have been partially
360 * completed already, which is OK. The plugin is supposed to close
361 * the connection (if applicable).
362 *
363 * @param cls closure with the `struct Plugin`
364 * @param session session to destroy
365 * @return #GNUNET_OK on success
366 */
367typedef int
368(*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls,
369 struct GNUNET_ATS_Session *
370 session);
371
372
373/**
374 * Function that is called to get the keepalive factor.
375 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
376 * calculate the interval between keepalive packets.
377 *
378 * @param cls closure with the `struct Plugin`
379 * @return keepalive factor
380 */
381typedef unsigned int
382(*GNUNET_TRANSPORT_QueryKeepaliveFactorFunction) (void *cls);
383
384
385/**
386 * Function that can be called to force a disconnect from the
387 * specified neighbour. This should also cancel all previously
388 * scheduled transmissions. Obviously the transmission may have been
389 * partially completed already, which is OK. The plugin is supposed
390 * to close the connection (if applicable) and no longer call the
391 * transmit continuation(s).
392 *
393 * @param cls closure
394 * @param target peer for which the last transmission is
395 * to be cancelled
396 */
397typedef void
398(*GNUNET_TRANSPORT_DisconnectPeerFunction) (void *cls,
399 const struct
400 GNUNET_PeerIdentity *target);
401
402
403/**
404 * Function called by the pretty printer for the resolved address for
405 * each human-readable address obtained. The callback can be called
406 * several times. The last invocation must be with a @a address of
407 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
408 * errors, the callback might be called first with @a address NULL and
409 * @a res being #GNUNET_SYSERR. In that case, there must still be a
410 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
411 *
412 * @param cls closure
413 * @param address one of the names for the host, NULL on last callback
414 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on failure,
415 * #GNUNET_OK on last callback
416 */
417typedef void
418(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
419 const char *address,
420 int res);
421
422
423/**
424 * Convert the transports address to a nice, human-readable
425 * format.
426 *
427 * @param cls closure
428 * @param type name of the transport that generated the address
429 * @param addr one of the addresses of the host, NULL for the last address
430 * the specific address format depends on the transport
431 * @param addrlen length of the @a addr
432 * @param numeric should (IP) addresses be displayed in numeric form?
433 * @param timeout after how long should we give up?
434 * @param asc function to call on each string
435 * @param asc_cls closure for @a asc
436 */
437typedef void
438(*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
439 const char *type,
440 const void *addr,
441 size_t addrlen,
442 int numeric,
443 struct GNUNET_TIME_Relative timeout,
444 GNUNET_TRANSPORT_AddressStringCallback
445 asc,
446 void *asc_cls);
447
448
449/**
450 * Another peer has suggested an address for this peer and transport
451 * plugin. Check that this could be a valid address. This function
452 * is not expected to 'validate' the address in the sense of trying to
453 * connect to it but simply to see if the binary format is technically
454 * legal for establishing a connection to this peer (and make sure that
455 * the address really corresponds to our network connection/settings
456 * and not some potential man-in-the-middle).
457 *
458 * @param addr pointer to the address
459 * @param addrlen length of @a addr
460 * @return #GNUNET_OK if this is a plausible address for this peer
461 * and transport, #GNUNET_SYSERR if not
462 */
463typedef int
464(*GNUNET_TRANSPORT_CheckAddress) (void *cls,
465 const void *addr,
466 size_t addrlen);
467
468
469/**
470 * Create a new session to transmit data to the target
471 * This session will used to send data to this peer and the plugin will
472 * notify us by calling the env->session_end function
473 *
474 * @param cls the plugin
475 * @param address the hello address
476 * @return the session if the address is valid, NULL otherwise
477 */
478typedef struct GNUNET_ATS_Session *
479(*GNUNET_TRANSPORT_CreateSession) (void *cls,
480 const struct GNUNET_HELLO_Address *address);
481
482
483/**
484 * Function that will be called whenever the transport service wants to
485 * notify the plugin that a session is still active and in use and
486 * therefore the session timeout for this session has to be updated
487 *
488 * @param cls closure
489 * @param peer which peer was the session for
490 * @param session which session is being updated
491 */
492typedef void
493(*GNUNET_TRANSPORT_UpdateSessionTimeout) (void *cls,
494 const struct
495 GNUNET_PeerIdentity *peer,
496 struct GNUNET_ATS_Session *session);
497
498
499/**
500 * Function that will be called whenever the transport service wants to
501 * notify the plugin that the inbound quota changed and that the plugin
502 * should update it's delay for the next receive value
503 *
504 * @param cls closure
505 * @param peer which peer was the session for
506 * @param session which session is being updated
507 * @param delay new delay to use for receiving
508 */
509typedef void
510(*GNUNET_TRANSPORT_UpdateInboundDelay) (void *cls,
511 const struct GNUNET_PeerIdentity *peer,
512 struct GNUNET_ATS_Session *session,
513 struct GNUNET_TIME_Relative delay);
514
515
516/**
517 * Function called for a quick conversion of the binary address to
518 * a numeric address. Note that the caller must not free the
519 * address and that the next call to this function is allowed
520 * to override the address again.
521 *
522 * @param cls closure
523 * @param addr binary address
524 * @param addr_len length of the @a addr
525 * @return string representing the same address
526 */
527typedef const char *
528(*GNUNET_TRANSPORT_AddressToString) (void *cls,
529 const void *addr,
530 size_t addrlen);
531
532
533/**
534 * Function called to convert a string address to
535 * a binary address.
536 *
537 * @param cls closure (`struct Plugin*`)
538 * @param addr string address
539 * @param addrlen length of the @a addr including \0 termination
540 * @param buf location to store the buffer
541 * If the function returns #GNUNET_SYSERR, its contents are undefined.
542 * @param added length of created address
543 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
544 */
545typedef int
546(*GNUNET_TRANSPORT_StringToAddress) (void *cls,
547 const char *addr,
548 uint16_t addrlen,
549 void **buf,
550 size_t *added);
551
552
553/**
554 * Function to obtain the network type for a session
555 *
556 * @param cls closure (`struct Plugin *`)
557 * @param session the session
558 * @return the network type
559 */
560typedef enum GNUNET_NetworkType
561(*GNUNET_TRANSPORT_GetNetworkType)(void *cls,
562 struct GNUNET_ATS_Session *session);
563
564
565/**
566 * Function to obtain the network type for an address.
567 *
568 * @param cls closure (`struct Plugin *`)
569 * @param address the address
570 * @return the network type
571 */
572typedef enum GNUNET_NetworkType
573(*GNUNET_TRANSPORT_GetNetworkTypeForAddress)(void *cls,
574 const struct
575 GNUNET_HELLO_Address *address);
576
577
578/**
579 * Function called by the plugin with information about the
580 * current sessions managed by the plugin (for monitoring).
581 *
582 * @param cls closure
583 * @param session session handle this information is about,
584 * NULL to indicate that we are "in sync" (initial
585 * iteration complete)
586 * @param info information about the state of the session,
587 * NULL if @a session is also NULL and we are
588 * merely signalling that the initial iteration is over
589 */
590typedef void
591(*GNUNET_TRANSPORT_SessionInfoCallback) (void *cls,
592 struct GNUNET_ATS_Session *session,
593 const struct
594 GNUNET_TRANSPORT_SessionInfo *info);
595
596
597/**
598 * Begin monitoring sessions of a plugin. There can only
599 * be one active monitor per plugin (i.e. if there are
600 * multiple monitors, the transport service needs to
601 * multiplex the generated events over all of them).
602 *
603 * @param cls closure of the plugin
604 * @param sic callback to invoke, NULL to disable monitor;
605 * plugin will being by iterating over all active
606 * sessions immediately and then enter monitor mode
607 * @param sic_cls closure for @a sic
608 */
609typedef void
610(*GNUNET_TRANSPORT_SessionMonitorSetup) (void *cls,
611 GNUNET_TRANSPORT_SessionInfoCallback
612 sic,
613 void *sic_cls);
614
615
616/**
617 * Each plugin is required to return a pointer to a struct of this
618 * type as the return value from its entry point.
619 */
620struct GNUNET_TRANSPORT_PluginFunctions
621{
622 /**
623 * Closure for all of the callbacks.
624 */
625 void *cls;
626
627 /**
628 * Function that the transport service will use to transmit data to
629 * another peer. May be NULL for plugins that only support
630 * receiving data. After this call, the plugin call the specified
631 * continuation with success or error before notifying us about the
632 * target having disconnected.
633 */
634 GNUNET_TRANSPORT_TransmitFunction send;
635
636 /**
637 * Function that can be used to force the plugin to disconnect from
638 * the given peer and cancel all previous transmissions (and their
639 * continuations).
640 */
641 GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer;
642
643 /**
644 * Function that can be used to force the plugin to disconnect from
645 * the given peer and cancel all previous transmissions (and their
646 * continuations).
647 */
648 GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session;
649
650 /**
651 * Function that will be called whenever the transport service wants to
652 * notify the plugin that a session is still active and in use and
653 * therefore the session timeout for this session has to be updated
654 */
655 GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout;
656
657 /**
658 * Function that will be called whenever the transport service wants to
659 * notify the plugin that the inbound quota changed and that the plugin
660 * should update it's delay for the next receive value
661 */
662 GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay;
663
664 /**
665 * Function that is used to query keepalive factor.
666 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
667 * calculate the interval between keepalive packets.
668 */
669 GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor;
670
671 /**
672 * Function to pretty-print addresses.
673 */
674 GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
675
676 /**
677 * Function that will be called to check if a binary address
678 * for this plugin is well-formed and corresponds to an
679 * address for THIS peer (as per our configuration). Naturally,
680 * if absolutely necessary, plugins can be a bit conservative in
681 * their answer, but in general plugins should make sure that the
682 * address does not redirect traffic to a 3rd party that might
683 * try to man-in-the-middle our traffic.
684 */
685 GNUNET_TRANSPORT_CheckAddress check_address;
686
687 /**
688 * Function that will be called to convert a binary address
689 * to a string (numeric conversion only).
690 */
691 GNUNET_TRANSPORT_AddressToString address_to_string;
692
693 /**
694 * Function that will be called to convert a string address
695 * to binary (numeric conversion only).
696 */
697 GNUNET_TRANSPORT_StringToAddress string_to_address;
698
699 /**
700 * Function that will be called tell the plugin to create a session
701 * object.
702 */
703 GNUNET_TRANSPORT_CreateSession get_session;
704
705 /**
706 * Function to obtain the network type for a session
707 */
708 GNUNET_TRANSPORT_GetNetworkType get_network;
709
710 /**
711 * Function to obtain the network type for an address
712 */
713 GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address;
714
715 /**
716 * Function to monitor the sessions managed by the plugin.
717 */
718 GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor;
719};
720
721
722/*#ifndef PLUGIN_TRANSPORT_H*/
723#endif
724
725/** @} */ /* end of group */
726
727/* end of gnunet_transport_plugin.h */
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
deleted file mode 100644
index 459efc506..000000000
--- a/src/include/gnunet_transport_service.h
+++ /dev/null
@@ -1,708 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Low-level P2P IO
26 *
27 * @defgroup transport Transport service
28 * Low-level P2P IO
29 *
30 * @see [Documentation](https://gnunet.org/transport-service)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TRANSPORT_SERVICE_H
36#define GNUNET_TRANSPORT_SERVICE_H
37
38#ifdef __cplusplus
39extern "C" {
40#if 0 /* keep Emacsens' auto-indent happy */
41}
42#endif
43#endif
44
45#include "gnunet_util_lib.h"
46#include "gnunet_ats_service.h"
47
48/**
49 * Version number of the transport API.
50 */
51#define GNUNET_TRANSPORT_VERSION 0x00000003
52
53
54/* *************************** HELLO *************************** */
55
56/**
57 * Handle for a #GNUNET_TRANSPORT_offer_hello operation
58 */
59struct GNUNET_TRANSPORT_OfferHelloHandle;
60
61
62/**
63 * Offer the transport service the HELLO of another peer. Note that
64 * the transport service may just ignore this message if the HELLO is
65 * malformed or useless due to our local configuration.
66 *
67 * @param cfg configuration
68 * @param hello the hello message
69 * @param cont continuation to call when HELLO has been sent,
70 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
71 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
72 * @param cont_cls closure for @a cont
73 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on
74 * failure, in case of failure @a cont will not be called
75 *
76 */
77struct GNUNET_TRANSPORT_OfferHelloHandle *
78GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
79 const struct GNUNET_MessageHeader *hello,
80 GNUNET_SCHEDULER_TaskCallback cont,
81 void *cont_cls);
82
83
84/**
85 * Cancel the request to transport to offer the HELLO message
86 *
87 * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
88 */
89void
90GNUNET_TRANSPORT_offer_hello_cancel (
91 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
92
93
94/* *********************** Address to String ******************* */
95
96/**
97 * Handle to cancel a pending address lookup.
98 */
99struct GNUNET_TRANSPORT_AddressToStringContext;
100
101
102/**
103 * Function to call with a textual representation of an address. This
104 * function will be called several times with different possible
105 * textual representations, and a last time with @a address being NULL
106 * to signal the end of the iteration. Note that @a address NULL
107 * always is the last call, regardless of the value in @a res.
108 *
109 * @param cls closure
110 * @param address NULL on end of iteration,
111 * otherwise 0-terminated printable UTF-8 string,
112 * in particular an empty string if @a res is #GNUNET_NO
113 * @param res result of the address to string conversion:
114 * if #GNUNET_OK: conversion successful
115 * if #GNUNET_NO: address was invalid (or not supported)
116 * if #GNUNET_SYSERR: communication error (IPC error)
117 */
118typedef void
119(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
120 const char *address,
121 int res);
122
123
124/**
125 * Convert a binary address into a human readable address.
126 *
127 * @param cfg configuration to use
128 * @param address address to convert (binary format)
129 * @param numeric should (IP) addresses be displayed in numeric form
130 * (otherwise do reverse DNS lookup)
131 * @param timeout how long is the lookup allowed to take at most
132 * @param aluc function to call with the results
133 * @param aluc_cls closure for @a aluc
134 * @return handle to cancel the operation, NULL on error
135 */
136struct GNUNET_TRANSPORT_AddressToStringContext *
137GNUNET_TRANSPORT_address_to_string (
138 const struct GNUNET_CONFIGURATION_Handle *cfg,
139 const struct GNUNET_HELLO_Address *address,
140 int numeric,
141 struct GNUNET_TIME_Relative timeout,
142 GNUNET_TRANSPORT_AddressToStringCallback aluc,
143 void *aluc_cls);
144
145
146/**
147 * Cancel request for address conversion.
148 *
149 * @param alc the context handle
150 */
151void
152GNUNET_TRANSPORT_address_to_string_cancel (
153 struct GNUNET_TRANSPORT_AddressToStringContext *alc);
154
155
156/* *********************** Monitoring ************************** */
157
158
159/**
160 * Possible state of a neighbour. Initially, we are
161 * #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
162 *
163 * Then, there are two main paths. If we receive a SYN message, we give
164 * the inbound address to ATS. After the check we ask ATS for a suggestion
165 * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
166 * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
167 * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
168 * (and notify everyone about the new connection). If the operation times out,
169 * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
170 *
171 * The other case is where we transmit a SYN message first. We
172 * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
173 * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
174 * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
175 * (and notify everyone about the new connection and send
176 * back a ACK). If the operation times out, we go to
177 * #GNUNET_TRANSPORT_PS_DISCONNECT.
178 *
179 * If the session is in trouble (i.e. transport-level disconnect or
180 * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a
181 * new address (we don't notify anyone about the disconnect yet). Once we have
182 * a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a SYN
183 * message. If we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
184 * and nobody noticed that we had trouble; we also send a ACK at this time just
185 * in case. If the operation times out, we go to
186 * #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone about the lost
187 * connection).
188 *
189 * If ATS decides to switch addresses while we have a normal
190 * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
191 * and send a SESSION_CONNECT. If we get a ACK back, we switch the
192 * primary connection to the suggested alternative from ATS, go back
193 * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
194 * sure. If the operation times out
195 * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given
196 * alternative address is "invalid").
197 *
198 * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and
199 * then goes to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an
200 * explicit disconnect request, we can go from any state to
201 * #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after generating disconnect
202 * notifications.
203 *
204 * Note that it is quite possible that while we are in any of these
205 * states, we could receive a 'SYN' request from the other peer.
206 * We then enter a 'weird' state where we pursue our own primary state
207 * machine (as described above), but with the 'send_connect_ack' flag
208 * set to 1. If our state machine allows us to send a 'SYN_ACK'
209 * (because we have an acceptable address), we send the 'SYN_ACK'
210 * and set the 'send_connect_ack' to 2. If we then receive a
211 * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
212 * to 0).
213 *
214 */
215enum GNUNET_TRANSPORT_PeerState
216{
217 /**
218 * Fresh peer or completely disconnected
219 */
220 GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
221
222 /**
223 * Asked to initiate connection, trying to get address from ATS
224 */
225 GNUNET_TRANSPORT_PS_INIT_ATS,
226
227 /**
228 * Sent SYN message to other peer, waiting for SYN_ACK
229 */
230 GNUNET_TRANSPORT_PS_SYN_SENT,
231
232 /**
233 * Received a SYN, asking ATS about address suggestions.
234 */
235 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
236
237 /**
238 * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
239 */
240 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
241
242 /**
243 * Got our SYN_ACK/ACK, connection is up.
244 */
245 GNUNET_TRANSPORT_PS_CONNECTED,
246
247 /**
248 * Connection got into trouble, rest of the system still believes
249 * it to be up, but we're getting a new address from ATS.
250 */
251 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
252
253 /**
254 * Sent SYN over new address (either by ATS telling us to switch
255 * addresses or from RECONNECT_ATS); if this fails, we need to tell
256 * the rest of the system about a disconnect.
257 */
258 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
259
260 /**
261 * We have some primary connection, but ATS suggested we switch
262 * to some alternative; we now sent a SYN message for the
263 * alternative session to the other peer and waiting for a
264 * SYN_ACK to make this our primary connection.
265 */
266 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
267
268 /**
269 * Disconnect in progress (we're sending the DISCONNECT message to the
270 * other peer; after that is finished, the state will be cleaned up).
271 */
272 GNUNET_TRANSPORT_PS_DISCONNECT,
273
274 /**
275 * We're finished with the disconnect; and are cleaning up the state
276 * now! We put the struct into this state when we are really in the
277 * task that calls 'free' on it and are about to remove the record
278 * from the map. We should never find a 'struct NeighbourMapEntry'
279 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
280 * in this state virtually always means using memory that has been
281 * freed (the exception being the cleanup code in #free_neighbour()).
282 */
283 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
284};
285
286
287/**
288 * Convert a transport state to a human readable string.
289 *
290 * @param state the state
291 */
292const char *
293GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
294
295
296/**
297 * Check if a state is defined as connected
298 *
299 * @param state the state value
300 * @return #GNUNET_YES or #GNUNET_NO
301 */
302int
303GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
304
305
306/**
307 * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
308 */
309struct GNUNET_TRANSPORT_PeerMonitoringContext;
310
311
312/**
313 * Function to call with information about a peer
314 *
315 * If one_shot was set to #GNUNET_YES to iterate over all peers once,
316 * a final call with NULL for peer and address will follow when done.
317 * In this case state and timeout do not contain valid values.
318 *
319 * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
320 * within this function!
321 *
322 *
323 * @param cls closure
324 * @param peer peer this update is about,
325 * NULL if this is the final last callback for a iteration operation
326 * @param address address, NULL if this is the final callback for iteration op
327 * @param state current state this peer is in
328 * @param state_timeout timeout for the current state of the peer
329 */
330typedef void
331(*GNUNET_TRANSPORT_PeerIterateCallback) (
332 void *cls,
333 const struct GNUNET_PeerIdentity *peer,
334 const struct GNUNET_HELLO_Address *address,
335 enum GNUNET_TRANSPORT_PeerState state,
336 struct GNUNET_TIME_Absolute state_timeout);
337
338
339/**
340 * Return information about a specific peer or all peers currently known to
341 * transport service once or in monitoring mode. To obtain information about
342 * a specific peer, a peer identity can be passed. To obtain information about
343 * all peers currently known to transport service, NULL can be passed as peer
344 * identity.
345 *
346 * For each peer, the callback is called with information about the address used
347 * to communicate with this peer, the state this peer is currently in and the
348 * the current timeout for this state.
349 *
350 * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
351 * more time with `NULL`. After this, the operation must no longer be
352 * explicitly canceled.
353 *
354 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
355 * the peer_callback!
356 *
357 * @param cfg configuration to use
358 * @param peer a specific peer identity to obtain information for,
359 * NULL for all peers
360 * @param one_shot #GNUNET_YES to return the current state and then end (with
361 * NULL+NULL), #GNUNET_NO to monitor peers continuously
362 * @param peer_callback function to call with the results
363 * @param peer_callback_cls closure for @a peer_callback
364 */
365struct GNUNET_TRANSPORT_PeerMonitoringContext *
366GNUNET_TRANSPORT_monitor_peers (
367 const struct GNUNET_CONFIGURATION_Handle *cfg,
368 const struct GNUNET_PeerIdentity *peer,
369 int one_shot,
370 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
371 void *peer_callback_cls);
372
373
374/**
375 * Cancel request to monitor peers
376 *
377 * @param pic handle for the request to cancel
378 */
379void
380GNUNET_TRANSPORT_monitor_peers_cancel (
381 struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
382
383
384/* *********************** Blacklisting ************************ */
385
386/**
387 * Handle for blacklisting peers.
388 */
389struct GNUNET_TRANSPORT_Blacklist;
390
391
392/**
393 * Function that decides if a connection is acceptable or not.
394 *
395 * @param cls closure
396 * @param pid peer to approve or disapproave
397 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
398 */
399typedef int
400(*GNUNET_TRANSPORT_BlacklistCallback) (
401 void *cls,
402 const struct GNUNET_PeerIdentity *pid);
403
404
405/**
406 * Install a blacklist callback. The service will be queried for all
407 * existing connections as well as any fresh connections to check if
408 * they are permitted. If the blacklisting callback is unregistered,
409 * all hosts that were denied in the past will automatically be
410 * whitelisted again. Cancelling the blacklist handle is also the
411 * only way to re-enable connections from peers that were previously
412 * blacklisted.
413 *
414 * @param cfg configuration to use
415 * @param cb callback to invoke to check if connections are allowed
416 * @param cb_cls closure for @a cb
417 * @return NULL on error, otherwise handle for cancellation
418 */
419struct GNUNET_TRANSPORT_Blacklist *
420GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
421 GNUNET_TRANSPORT_BlacklistCallback cb,
422 void *cb_cls);
423
424
425/**
426 * Abort the blacklist. Note that this function is the only way for
427 * removing a peer from the blacklist.
428 *
429 * @param br handle of the request that is to be cancelled
430 */
431void
432GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
433
434
435/**
436 * Handle for a plugin session state monitor.
437 */
438struct GNUNET_TRANSPORT_PluginMonitor;
439
440/**
441 * Abstract representation of a plugin's session.
442 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
443 */
444struct GNUNET_TRANSPORT_PluginSession;
445
446
447/**
448 * Possible states of a session in a plugin.
449 */
450enum GNUNET_TRANSPORT_SessionState
451{
452 /**
453 * The session was created (first call for each session object).
454 */
455 GNUNET_TRANSPORT_SS_INIT,
456
457 /**
458 * Initial session handshake is in progress.
459 */
460 GNUNET_TRANSPORT_SS_HANDSHAKE,
461
462 /**
463 * Session is fully UP.
464 */
465 GNUNET_TRANSPORT_SS_UP,
466
467 /**
468 * This is just an update about the session,
469 * the state did not change.
470 */
471 GNUNET_TRANSPORT_SS_UPDATE,
472
473 /**
474 * Session is being torn down and about to disappear.
475 * Last call for each session object.
476 */
477 GNUNET_TRANSPORT_SS_DONE
478};
479
480
481/**
482 * Information about a plugin's session.
483 */
484struct GNUNET_TRANSPORT_SessionInfo
485{
486 /**
487 * New state of the session.
488 */
489 enum GNUNET_TRANSPORT_SessionState state;
490
491 /**
492 * #GNUNET_YES if this is an inbound connection,
493 * #GNUNET_NO if this is an outbound connection,
494 * #GNUNET_SYSERR if connections of this plugin
495 * are so fundamentally bidirectional
496 * that they have no 'initiator'
497 */
498 int is_inbound;
499
500 /**
501 * Number of messages pending transmission for this session.
502 */
503 uint32_t num_msg_pending;
504
505 /**
506 * Number of bytes pending transmission for this session.
507 */
508 uint32_t num_bytes_pending;
509
510 /**
511 * Until when does this plugin refuse to receive to manage
512 * staying within the inbound quota? ZERO if receive is
513 * active.
514 */
515 struct GNUNET_TIME_Absolute receive_delay;
516
517 /**
518 * At what time will this session timeout (unless activity
519 * happens)?
520 */
521 struct GNUNET_TIME_Absolute session_timeout;
522
523 /**
524 * Address used by the session. Can be NULL if none is available.
525 */
526 const struct GNUNET_HELLO_Address *address;
527};
528
529
530/**
531 * Function called by the plugin with information about the
532 * current sessions managed by the plugin (for monitoring).
533 *
534 * @param cls closure
535 * @param session session handle this information is about,
536 * NULL to indicate that we are "in sync" (initial
537 * iteration complete)
538 * @param session_ctx storage location where the application
539 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
540 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
541 * @param info information about the state of the session,
542 * NULL if @a session is also NULL and we are
543 * merely signalling that the initial iteration is over;
544 * NULL with @a session being non-NULL if the monitor
545 * was being cancelled while sessions were active
546 */
547typedef void
548(*GNUNET_TRANSPORT_SessionMonitorCallback) (
549 void *cls,
550 struct GNUNET_TRANSPORT_PluginSession *session,
551 void **session_ctx,
552 const struct GNUNET_TRANSPORT_SessionInfo *info);
553
554
555/**
556 * Install a plugin session state monitor callback. The callback
557 * will be notified whenever the session changes.
558 *
559 * @param cfg configuration to use
560 * @param cb callback to invoke on events
561 * @param cb_cls closure for @a cb
562 * @return NULL on error, otherwise handle for cancellation
563 */
564struct GNUNET_TRANSPORT_PluginMonitor *
565GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
566 GNUNET_TRANSPORT_SessionMonitorCallback cb,
567 void *cb_cls);
568
569
570/**
571 * Cancel monitoring the plugin session state. The callback will be
572 * called once for each session that is up with the "info" argument
573 * being NULL (this is just to enable client-side cleanup).
574 *
575 * @param pm handle of the request that is to be cancelled
576 */
577void
578GNUNET_TRANSPORT_monitor_plugins_cancel (
579 struct GNUNET_TRANSPORT_PluginMonitor *pm);
580
581
582/**
583 * Opaque handle to the service.
584 */
585struct GNUNET_TRANSPORT_CoreHandle;
586
587
588/**
589 * Function called to notify transport users that another
590 * peer connected to us.
591 *
592 * @param cls closure
593 * @param peer the identity of the peer that connected; this
594 * pointer will remain valid until the disconnect, hence
595 * applications do not necessarily have to make a copy
596 * of the value if they only need it until disconnect
597 * @param mq message queue to use to transmit to @a peer
598 * @return closure to use in MQ handlers
599 */
600typedef void *
601(*GNUNET_TRANSPORT_NotifyConnect) (
602 void *cls,
603 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq);
605
606
607/**
608 * Function called to notify transport users that another peer
609 * disconnected from us. The message queue that was given to the
610 * connect notification will be destroyed and must not be used
611 * henceforth.
612 *
613 * @param cls closure from #GNUNET_TRANSPORT_core_connect
614 * @param peer the peer that disconnected
615 * @param handlers_cls closure of the handlers, was returned from the
616 * connect notification callback
617 */
618typedef void
619(*GNUNET_TRANSPORT_NotifyDisconnect) (
620 void *cls,
621 const struct GNUNET_PeerIdentity *peer,
622 void *handler_cls);
623
624
625/**
626 * Function called if we have "excess" bandwidth to a peer.
627 * The notification will happen the first time we have excess
628 * bandwidth, and then only again after the client has performed
629 * some transmission to the peer.
630 *
631 * Excess bandwidth is defined as being allowed (by ATS) to send
632 * more data, and us reaching the limit of the capacity build-up
633 * (which, if we go past it, means we don't use available bandwidth).
634 * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
635 *
636 * @param cls the closure
637 * @param neighbour peer that we have excess bandwidth to
638 * @param handlers_cls closure of the handlers, was returned from the
639 * connect notification callback
640 */
641typedef void
642(*GNUNET_TRANSPORT_NotifyExcessBandwidth) (
643 void *cls,
644 const struct GNUNET_PeerIdentity *neighbour,
645 void *handlers_cls);
646
647
648/**
649 * Connect to the transport service. Note that the connection may
650 * complete (or fail) asynchronously.
651 *
652 * @param cfg configuration to use
653 * @param self our own identity (API should check that it matches
654 * the identity found by transport), or NULL (no check)
655 * @param handlers array of message handlers; note that the
656 * closures provided will be ignored and replaced
657 * with the respective return value from @a nc
658 * @param handlers array with handlers to call when we receive messages, or NULL
659 * @param cls closure for the @a nc, @a nd and @a neb callbacks
660 * @param nc function to call on connect events, or NULL
661 * @param nd function to call on disconnect events, or NULL
662 * @param neb function to call if we have excess bandwidth to a peer, or NULL
663 * @return NULL on error
664 */
665struct GNUNET_TRANSPORT_CoreHandle *
666GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
667 const struct GNUNET_PeerIdentity *self,
668 const struct GNUNET_MQ_MessageHandler *handlers,
669 void *cls,
670 GNUNET_TRANSPORT_NotifyConnect nc,
671 GNUNET_TRANSPORT_NotifyDisconnect nd,
672 GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
673
674
675/**
676 * Disconnect from the transport service.
677 *
678 * @param handle handle returned from connect
679 */
680void
681GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
682
683
684/**
685 * Checks if a given peer is connected to us and get the message queue.
686 *
687 * @param handle connection to transport service
688 * @param peer the peer to check
689 * @return NULL if disconnected, otherwise message queue for @a peer
690 */
691struct GNUNET_MQ_Handle *
692GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
693 const struct GNUNET_PeerIdentity *peer);
694
695
696#if 0 /* keep Emacsens' auto-indent happy */
697{
698#endif
699#ifdef __cplusplus
700}
701#endif
702
703/* ifndef GNUNET_TRANSPORT_SERVICE_H */
704#endif
705
706/** @} */ /* end of group */
707
708/* end of gnunet_transport_service.h */
diff --git a/src/include/gnunet_transport_testing_ng_lib.h b/src/include/gnunet_transport_testing_ng_lib.h
new file mode 100644
index 000000000..be904cf4c
--- /dev/null
+++ b/src/include/gnunet_transport_testing_ng_lib.h
@@ -0,0 +1,211 @@
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_ng_lib.h"
31
32/**
33 * Application handle; FIXME: what exactly is this?
34 */
35struct GNUNET_TRANSPORT_ApplicationHandle;
36
37/**
38 * FIXME: what is this?
39 */
40struct GNUNET_TESTING_StartPeerState;
41
42
43// FIXME: breaks naming conventions
44typedef void *
45(*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
46 const struct GNUNET_PeerIdentity *peer);
47
48
49
50// FIXME: breaks naming conventions! Needed public?
51struct GNUNET_TESTING_StartPeerState
52{
53 /**
54 * Context for our asynchronous completion.
55 */
56 struct GNUNET_TESTING_AsyncContext ac;
57
58 /**
59 * The ip of a node.
60 */
61 char *node_ip;
62
63 /**
64 * Receive callback
65 */
66 struct GNUNET_MQ_MessageHandler *handlers;
67
68 /**
69 * GNUnet configuration file used to start a peer.
70 */
71 char *cfgname;
72
73 /**
74 * Peer's configuration
75 */
76 struct GNUNET_CONFIGURATION_Handle *cfg;
77
78 /**
79 * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
80 */
81 struct GNUNET_TESTING_Peer *peer;
82
83 /**
84 * Peer identity
85 */
86 struct GNUNET_PeerIdentity id;
87
88 /**
89 * Peer's transport service handle
90 */
91 struct GNUNET_TRANSPORT_CoreHandle *th;
92
93 /**
94 * Application handle
95 */
96 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
97
98 /**
99 * Peer's PEERSTORE Handle
100 */
101 struct GNUNET_PEERSTORE_Handle *ph;
102
103 /**
104 * Hello get task
105 */
106 struct GNUNET_SCHEDULER_Task *rh_task;
107
108 /**
109 * Peer's transport get hello handle to retrieve peer's HELLO message
110 */
111 struct GNUNET_PEERSTORE_IterateContext *pic;
112
113 /**
114 * Hello
115 */
116 char *hello;
117
118 /**
119 * Hello size
120 */
121 size_t hello_size;
122
123 /**
124 * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
125 */
126 char *system_label;
127
128 /**
129 * An unique number to identify the peer
130 */
131 unsigned int no;
132
133 /**
134 * A map with struct GNUNET_MQ_Handle values for each peer this peer
135 * is connected to.
136 */
137 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
138
139 /**
140 * Test setup for this peer.
141 */
142 const struct GNUNET_TESTING_System *tl_system;
143
144 /**
145 * Callback which is called on neighbour connect events.
146 */
147 GNUNET_TESTING_notify_connect_cb notify_connect;
148
149 /**
150 * Flag indicating, if udp broadcast should be switched on.
151 */
152 enum GNUNET_GenericReturnValue broadcast;
153};
154
155
156
157/**
158 * Create command.
159 *
160 * @param label name for command.
161 * @param system_label Label of the cmd to setup a test environment.
162 * @param no Decimal number representing the last byte of the IP address of this peer.
163 * @param node_ip The IP address of this node.
164 * @param cfgname Configuration file name for this peer.
165 * @param broadcast Flag indicating, if broadcast should be switched on.
166 * @return command.
167 */
168struct GNUNET_TESTING_Command
169GNUNET_TESTING_cmd_start_peer (const char *label,
170 const char *system_label,
171 uint32_t no,
172 const char *node_ip,
173 const char *cfgname,
174 unsigned int broadcast);
175
176
177struct GNUNET_TESTING_Command
178GNUNET_TESTING_cmd_stop_peer (const char *label,
179 const char *start_label);
180
181
182/**
183 * Retrieve peer identity from the test system with the unique node id.
184 *
185 * @param num The unique node id.
186 * @param tl_system The test system.
187 * @return The peer identity wrapping the public key.
188 */
189struct GNUNET_PeerIdentity *
190GNUNET_TESTING_get_peer (unsigned int num,
191 const struct GNUNET_TESTING_System *tl_system);
192
193
194
195
196/**
197 * Call #op on all simple traits.
198 */
199#define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix) \
200 op (prefix, connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \
201 op (prefix, peer_id, const struct GNUNET_PeerIdentity) \
202 op (prefix, hello_size, const size_t) \
203 op (prefix, hello, const char) \
204 op (prefix, application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \
205 op (prefix, state, const struct GNUNET_TESTING_StartPeerState) \
206 op (prefix, broadcast, const enum GNUNET_GenericReturnValue)
207
208
209GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TRANSPORT_TESTING)
210
211#endif
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 61880cea1..6c7d2cd42 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -18,7 +18,14 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup vpn_suite VPN services and libraries
27 * @{
28 *
22 * @author Philipp Toelke 29 * @author Philipp Toelke
23 * @author Christian Grothoff 30 * @author Christian Grothoff
24 * 31 *
@@ -34,9 +41,6 @@
34#ifndef GNUNET_TUN_LIB_H 41#ifndef GNUNET_TUN_LIB_H
35#define GNUNET_TUN_LIB_H 42#define GNUNET_TUN_LIB_H
36 43
37#include "gnunet_common.h"
38#include "gnunet_crypto_lib.h"
39
40 44
41/* see http://www.iana.org/assignments/ethernet-numbers */ 45/* see http://www.iana.org/assignments/ethernet-numbers */
42#ifndef ETH_P_IPV4 46#ifndef ETH_P_IPV4
@@ -546,6 +550,29 @@ struct GNUNET_TUN_DnsSrvRecord
546 550
547 551
548/** 552/**
553 * Payload of DNS URI record (header).
554 */
555struct GNUNET_TUN_DnsUriRecord
556{
557 /**
558 * Preference for this entry (lower value is higher preference). Clients
559 * will contact hosts from the lowest-priority group first and fall back
560 * to higher priorities if the low-priority entries are unavailable. (NBO)
561 */
562 uint16_t prio GNUNET_PACKED;
563
564 /**
565 * Relative weight for records with the same priority. Clients will use
566 * the hosts of the same (lowest) priority with a probability proportional
567 * to the weight given. (NBO)
568 */
569 uint16_t weight GNUNET_PACKED;
570
571 /* followed by 'target' name */
572};
573
574
575/**
549 * Payload of DNS CERT record. 576 * Payload of DNS CERT record.
550 */ 577 */
551struct GNUNET_TUN_DnsCertRecord 578struct GNUNET_TUN_DnsCertRecord
@@ -946,3 +973,5 @@ GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc,
946#endif 973#endif
947 974
948/** @} */ /* end of group */ 975/** @} */ /* end of group */
976
977/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index cc4f3a01e..ee850bc3c 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -30,6 +30,10 @@
30#ifndef GNUNET_UTIL_LIB_H 30#ifndef GNUNET_UTIL_LIB_H
31#define GNUNET_UTIL_LIB_H 31#define GNUNET_UTIL_LIB_H
32 32
33#define __GNUNET_UTIL_LIB_H_INSIDE__
34
35#include <sys/socket.h>
36
33#ifdef __cplusplus 37#ifdef __cplusplus
34extern "C" 38extern "C"
35{ 39{
@@ -59,9 +63,10 @@ extern "C"
59 * this service available to anyone but yourself. 63 * this service available to anyone but yourself.
60 */ 64 */
61#define GNUNET_AGPL_URL "https://git.gnunet.org/gnunet.git/tag/?h=v" \ 65#define GNUNET_AGPL_URL "https://git.gnunet.org/gnunet.git/tag/?h=v" \
62 PACKAGE_VERSION 66 GNUNET_VERSION
63
64 67
68#include "gnunet_config.h"
69#include "gnunet_common.h"
65#include "gnunet_crypto_lib.h" 70#include "gnunet_crypto_lib.h"
66#include "gnunet_bandwidth_lib.h" 71#include "gnunet_bandwidth_lib.h"
67#include "gnunet_bio_lib.h" 72#include "gnunet_bio_lib.h"
@@ -72,6 +77,7 @@ extern "C"
72#include "gnunet_helper_lib.h" 77#include "gnunet_helper_lib.h"
73#include "gnunet_mst_lib.h" 78#include "gnunet_mst_lib.h"
74#include "gnunet_mq_lib.h" 79#include "gnunet_mq_lib.h"
80#include "gnunet_nt_lib.h"
75#include "gnunet_nc_lib.h" 81#include "gnunet_nc_lib.h"
76#include "gnunet_op_lib.h" 82#include "gnunet_op_lib.h"
77#include "gnunet_os_lib.h" 83#include "gnunet_os_lib.h"
@@ -86,6 +92,53 @@ extern "C"
86#include "gnunet_dnsstub_lib.h" 92#include "gnunet_dnsstub_lib.h"
87#include "gnunet_dnsparser_lib.h" 93#include "gnunet_dnsparser_lib.h"
88#include "gnunet_child_management_lib.h" 94#include "gnunet_child_management_lib.h"
95#include "gnunet_error_codes.h"
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
106/**
107 * Try to compress the given block of data using libz. Only returns
108 * the compressed block if compression worked and the new block is
109 * actually smaller. Decompress using #GNUNET_decompress().
110 *
111 * @param data block to compress; if compression
112 * resulted in a smaller block, the first
113 * bytes of data are updated to the compressed
114 * data
115 * @param old_size number of bytes in data
116 * @param[out] result set to the compressed data, if compression worked
117 * @param[out] new_size set to size of result, if compression worked
118 * @return #GNUNET_YES if compression reduce the size,
119 * #GNUNET_NO if compression did not help
120 */
121int
122GNUNET_try_compression (const char *data,
123 size_t old_size,
124 char **result,
125 size_t *new_size);
126
127/**
128 * Decompress input, return the decompressed data as output. Dual to
129 * #GNUNET_try_compression(). Caller must set @a output_size to the
130 * number of bytes that were originally compressed.
131 *
132 * @param input compressed data
133 * @param input_size number of bytes in input
134 * @param output_size expected size of the output
135 * @return NULL on error, buffer of @a output_size decompressed bytes otherwise
136 */
137char *
138GNUNET_decompress (const char *input,
139 size_t input_size,
140 size_t output_size);
141
89 142
90#if 0 /* keep Emacsens' auto-indent happy */ 143#if 0 /* keep Emacsens' auto-indent happy */
91{ 144{
@@ -94,4 +147,6 @@ extern "C"
94} 147}
95#endif 148#endif
96 149
150#undef __GNUNET_UTIL_LIB_H_INSIDE__
151
97#endif 152#endif
diff --git a/src/include/gnunet_vpn_service.h b/src/include/gnunet_vpn_service.h
index 31476e140..f0a04ae1b 100644
--- a/src/include/gnunet_vpn_service.h
+++ b/src/include/gnunet_vpn_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite VPN services and libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_VPN_SERVICE_H 34#ifndef GNUNET_VPN_SERVICE_H
32#define GNUNET_VPN_SERVICE_H 35#define GNUNET_VPN_SERVICE_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35 39
36 40
@@ -159,3 +163,5 @@ GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
159#endif 163#endif
160 164
161/** @} */ /* end of group */ 165/** @} */ /* end of group */
166
167/** @} */ /* end of group addition */
diff --git a/src/include/meson.build b/src/include/meson.build
new file mode 100644
index 000000000..3127a6a40
--- /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_barrier.h',
108 'gnunet_testing_lib.h',
109 'gnunet_testing_plugin.h',
110 'gnunet_testing_ng_lib.h',
111 'gnunet_testing_netjail_lib.h',
112 'gnunet_time_lib.h',
113 'gnunet_transport_application_service.h',
114 'gnunet_transport_communication_service.h',
115 'gnunet_transport_core_service.h',
116 'gnunet_transport_monitor_service.h',
117 'gnunet_tun_lib.h',
118 'gnunet_uri_lib.h',
119 'gnunet_util_lib.h',
120 'gnunet_vpn_service.h',
121 install_dir: get_option('includedir')/'gnunet'
122 )
diff --git a/src/include/platform.h b/src/include/platform.h
index e44f9f51a..c04d8d487 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -34,7 +34,7 @@
34#ifndef HAVE_USED_CONFIG_H 34#ifndef HAVE_USED_CONFIG_H
35#define HAVE_USED_CONFIG_H 35#define HAVE_USED_CONFIG_H
36#if HAVE_CONFIG_H 36#if HAVE_CONFIG_H
37#include "gnunet_config.h" 37#include "gnunet_private_config.h"
38#endif 38#endif
39#endif 39#endif
40 40
@@ -44,6 +44,7 @@
44#ifdef HAVE_SYS_TYPES_H 44#ifdef HAVE_SYS_TYPES_H
45#include <sys/types.h> 45#include <sys/types.h>
46#endif 46#endif
47#include <inttypes.h>
47 48
48#ifdef __clang__ 49#ifdef __clang__
49#undef HAVE_STATIC_ASSERT 50#undef HAVE_STATIC_ASSERT
@@ -272,6 +273,10 @@ atoll (const char *nptr);
272#define EXIT_NOTRUNNING 7 273#define EXIT_NOTRUNNING 7
273#endif 274#endif
274 275
276#ifndef EXIT_NO_RESTART
277#define EXIT_NO_RESTART 9
278#endif
279
275/** 280/**
276 * clang et al do not have such an attribute 281 * clang et al do not have such an attribute
277 */ 282 */