Skip to content

Commit 04fbd6b

Browse files
authored
Ensure all public types are under CCF namespace (#6684)
1 parent 7ad0ebc commit 04fbd6b

File tree

83 files changed

+414
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+414
-357
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [6.0.0-dev8]
9+
10+
[6.0.0-dev8]: https://github.com/microsoft/CCF/releases/tag/6.0.0-dev8
11+
12+
### Changed
13+
14+
- All definitions in CCF's public headers are now under the `ccf::` namespace. Any application code which references any of these types directly (notably `StartupConfig`, `http_status`, `LoggerLevel`), they will now need to be prefixed with the `ccf::` namespace.
15+
816
## [6.0.0-dev7]
917

1018
[6.0.0-dev7]: https://github.com/microsoft/CCF/releases/tag/6.0.0-dev7

include/ccf/ccf_deprecated.h

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
#pragma once
44

55
#define CCF_DEPRECATED(reason) [[deprecated(reason)]]
6+
7+
// ci-checks exception - only defines a macro
8+
namespace ccf
9+
{}

include/ccf/ds/enum_formatter.h

+4
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ struct formatter<E, std::enable_if_t<std::is_enum_v<E>, char>>
2727
}
2828
};
2929
FMT_END_NAMESPACE
30+
31+
// ci-checks exception - defines a struct in the fmt namespace
32+
namespace ccf
33+
{}

include/ccf/ds/logger.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ namespace ccf::logger
344344
// This allows:
345345
// CCF_LOG_OUT(DEBUG, "foo") << "this " << "msg";
346346
#define CCF_LOG_OUT(LVL, TAG) \
347-
ccf::logger::config::ok(LoggerLevel::LVL) && \
347+
ccf::logger::config::ok(ccf::LoggerLevel::LVL) && \
348348
ccf::logger::Out() == \
349-
ccf::logger::LogLine(LoggerLevel::LVL, TAG, __FILE__, __LINE__)
349+
ccf::logger::LogLine(ccf::LoggerLevel::LVL, TAG, __FILE__, __LINE__)
350350

351351
// To avoid repeating the (s, ...) args for every macro, we cheat with a curried
352352
// macro here by ending the macro with another macro name, which then accepts

include/ccf/ds/logger_level.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5-
enum LoggerLevel
5+
namespace ccf
66
{
7-
TRACE,
8-
DEBUG, // events useful for debugging
9-
INFO, // important events that should be logged even in release mode
10-
FAIL, // survivable failures that should always be logged
11-
FATAL, // fatal errors that may be non-recoverable
12-
MAX_LOG_LEVEL
13-
};
7+
enum LoggerLevel
8+
{
9+
TRACE,
10+
DEBUG, // events useful for debugging
11+
INFO, // important events that should be logged even in release mode
12+
FAIL, // survivable failures that should always be logged
13+
FATAL, // fatal errors that may be non-recoverable
14+
MAX_LOG_LEVEL
15+
};
16+
}

include/ccf/http_status.h

+13-10
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
#include <llhttp/llhttp.h>
66

7-
using http_status = llhttp_status;
8-
9-
/* Returns a string version of the HTTP status code. */
10-
static inline const char* http_status_str(http_status s)
7+
namespace ccf
118
{
12-
return llhttp_status_name(s);
13-
}
9+
using http_status = llhttp_status;
1410

15-
static inline bool is_http_status_client_error(http_status s)
16-
{
17-
return s >= 400 && s < 500;
18-
}
11+
/* Returns a string version of the HTTP status code. */
12+
static inline const char* http_status_str(http_status s)
13+
{
14+
return llhttp_status_name(s);
15+
}
16+
17+
static inline bool is_http_status_client_error(http_status s)
18+
{
19+
return s >= 400 && s < 500;
20+
}
21+
}

include/ccf/json_handler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ namespace ccf
6868
const nlohmann::json& result_payload);
6969

7070
jsonhandler::JsonAdapterResponse make_error(
71-
http_status status, const std::string& code, const std::string& msg);
71+
ccf::http_status status, const std::string& code, const std::string& msg);
7272

73-
jsonhandler::JsonAdapterResponse make_redirect(http_status status);
73+
jsonhandler::JsonAdapterResponse make_redirect(ccf::http_status status);
7474

7575
using HandlerJsonParamsAndForward =
7676
std::function<jsonhandler::JsonAdapterResponse(

include/ccf/node/cose_signatures_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ namespace ccf
1818

1919
DECLARE_JSON_TYPE(COSESignaturesConfig);
2020
DECLARE_JSON_REQUIRED_FIELDS(COSESignaturesConfig, issuer, subject);
21-
}
21+
}

include/ccf/node/node_configuration_interface.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ccf
1313
{
1414
struct NodeConfigurationState
1515
{
16-
const StartupConfig& node_config;
16+
const ccf::StartupConfig& node_config;
1717
std::map<NodeInfoNetwork::RpcInterfaceID, std::vector<std::regex>>
1818
rpc_interface_regexes;
1919
bool initialized = false;

include/ccf/node/startup_config.h

+81-78
Original file line numberDiff line numberDiff line change
@@ -16,106 +16,109 @@
1616
#include <string>
1717
#include <vector>
1818

19-
struct CCFConfig
19+
namespace ccf
2020
{
21-
size_t worker_threads = 0;
22-
23-
// 2**24.5 as per RFC8446 Section 5.5
24-
size_t node_to_node_message_limit = 23'726'566;
21+
struct CCFConfig
22+
{
23+
size_t worker_threads = 0;
2524

26-
ccf::ds::SizeString historical_cache_soft_limit = {"512MB"};
25+
// 2**24.5 as per RFC8446 Section 5.5
26+
size_t node_to_node_message_limit = 23'726'566;
2727

28-
ccf::consensus::Configuration consensus = {};
29-
ccf::NodeInfoNetwork network = {};
28+
ccf::ds::SizeString historical_cache_soft_limit = {"512MB"};
3029

31-
struct NodeCertificateInfo
32-
{
33-
std::string subject_name = "CN=CCF Node";
34-
std::vector<std::string> subject_alt_names = {};
35-
ccf::crypto::CurveID curve_id = ccf::crypto::CurveID::SECP384R1;
36-
size_t initial_validity_days = 1;
30+
ccf::consensus::Configuration consensus = {};
31+
ccf::NodeInfoNetwork network = {};
3732

38-
bool operator==(const NodeCertificateInfo&) const = default;
39-
};
40-
NodeCertificateInfo node_certificate = {};
33+
struct NodeCertificateInfo
34+
{
35+
std::string subject_name = "CN=CCF Node";
36+
std::vector<std::string> subject_alt_names = {};
37+
ccf::crypto::CurveID curve_id = ccf::crypto::CurveID::SECP384R1;
38+
size_t initial_validity_days = 1;
4139

42-
struct LedgerSignatures
43-
{
44-
size_t tx_count = 5000;
45-
ccf::ds::TimeString delay = {"1000ms"};
40+
bool operator==(const NodeCertificateInfo&) const = default;
41+
};
42+
NodeCertificateInfo node_certificate = {};
4643

47-
bool operator==(const LedgerSignatures&) const = default;
48-
};
49-
LedgerSignatures ledger_signatures = {};
44+
struct LedgerSignatures
45+
{
46+
size_t tx_count = 5000;
47+
ccf::ds::TimeString delay = {"1000ms"};
5048

51-
struct JWT
52-
{
53-
ccf::ds::TimeString key_refresh_interval = {"30min"};
49+
bool operator==(const LedgerSignatures&) const = default;
50+
};
51+
LedgerSignatures ledger_signatures = {};
5452

55-
bool operator==(const JWT&) const = default;
56-
};
57-
JWT jwt = {};
53+
struct JWT
54+
{
55+
ccf::ds::TimeString key_refresh_interval = {"30min"};
5856

59-
struct Attestation
60-
{
61-
ccf::pal::snp::EndorsementsServers snp_endorsements_servers = {};
62-
std::optional<std::string> snp_security_policy_file = std::nullopt;
63-
std::optional<std::string> snp_uvm_endorsements_file = std::nullopt;
57+
bool operator==(const JWT&) const = default;
58+
};
59+
JWT jwt = {};
6460

65-
struct Environment
61+
struct Attestation
6662
{
67-
std::optional<std::string> security_policy = std::nullopt;
68-
std::optional<std::string> uvm_endorsements = std::nullopt;
63+
ccf::pal::snp::EndorsementsServers snp_endorsements_servers = {};
64+
std::optional<std::string> snp_security_policy_file = std::nullopt;
65+
std::optional<std::string> snp_uvm_endorsements_file = std::nullopt;
6966

70-
bool operator==(const Environment&) const = default;
71-
};
72-
Environment environment = {};
67+
struct Environment
68+
{
69+
std::optional<std::string> security_policy = std::nullopt;
70+
std::optional<std::string> uvm_endorsements = std::nullopt;
7371

74-
bool operator==(const Attestation&) const = default;
72+
bool operator==(const Environment&) const = default;
73+
};
74+
Environment environment = {};
75+
76+
bool operator==(const Attestation&) const = default;
77+
};
78+
Attestation attestation = {};
7579
};
76-
Attestation attestation = {};
77-
};
7880

79-
struct StartupConfig : CCFConfig
80-
{
81-
StartupConfig() = default;
82-
StartupConfig(const CCFConfig& common_base) : CCFConfig(common_base) {}
81+
struct StartupConfig : CCFConfig
82+
{
83+
StartupConfig() = default;
84+
StartupConfig(const CCFConfig& common_base) : CCFConfig(common_base) {}
8385

84-
std::string startup_host_time;
85-
size_t snapshot_tx_interval = 10'000;
86+
std::string startup_host_time;
87+
size_t snapshot_tx_interval = 10'000;
8688

87-
// Only if starting or recovering
88-
size_t initial_service_certificate_validity_days = 1;
89-
std::string service_subject_name = "CN=CCF Service";
90-
ccf::COSESignaturesConfig cose_signatures;
89+
// Only if starting or recovering
90+
size_t initial_service_certificate_validity_days = 1;
91+
std::string service_subject_name = "CN=CCF Service";
92+
ccf::COSESignaturesConfig cose_signatures;
9193

92-
nlohmann::json service_data = nullptr;
94+
nlohmann::json service_data = nullptr;
9395

94-
nlohmann::json node_data = nullptr;
96+
nlohmann::json node_data = nullptr;
9597

96-
struct Start
97-
{
98-
std::vector<ccf::NewMember> members;
99-
std::string constitution;
100-
ccf::ServiceConfiguration service_configuration;
98+
struct Start
99+
{
100+
std::vector<ccf::NewMember> members;
101+
std::string constitution;
102+
ccf::ServiceConfiguration service_configuration;
101103

102-
bool operator==(const Start& other) const = default;
103-
};
104-
Start start = {};
104+
bool operator==(const Start& other) const = default;
105+
};
106+
Start start = {};
105107

106-
struct Join
107-
{
108-
ccf::NodeInfoNetwork::NetAddress target_rpc_address;
109-
ccf::ds::TimeString retry_timeout = {"1000ms"};
110-
std::vector<uint8_t> service_cert = {};
111-
bool follow_redirect = true;
112-
};
113-
Join join = {};
108+
struct Join
109+
{
110+
ccf::NodeInfoNetwork::NetAddress target_rpc_address;
111+
ccf::ds::TimeString retry_timeout = {"1000ms"};
112+
std::vector<uint8_t> service_cert = {};
113+
bool follow_redirect = true;
114+
};
115+
Join join = {};
114116

115-
struct Recover
116-
{
117-
std::optional<std::vector<uint8_t>> previous_service_identity =
118-
std::nullopt;
117+
struct Recover
118+
{
119+
std::optional<std::vector<uint8_t>> previous_service_identity =
120+
std::nullopt;
121+
};
122+
Recover recover = {};
119123
};
120-
Recover recover = {};
121-
};
124+
}

include/ccf/service/consensus_type.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5-
enum ConsensusType
5+
#include "ccf/ds/json.h"
6+
7+
namespace ccf
68
{
7-
CFT = 0,
8-
BFT = 1
9-
};
9+
enum ConsensusType
10+
{
11+
CFT = 0,
12+
BFT = 1
13+
};
14+
15+
DECLARE_JSON_ENUM(
16+
ConsensusType, {{ConsensusType::CFT, "CFT"}, {ConsensusType::BFT, "BFT"}})
17+
}

include/ccf/service/reconfiguration_type.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5-
enum ReconfigurationType
5+
#include "ccf/ds/json.h"
6+
7+
namespace ccf
68
{
7-
ONE_TRANSACTION = 0,
8-
TWO_TRANSACTION = 1
9-
};
9+
enum ReconfigurationType
10+
{
11+
ONE_TRANSACTION = 0,
12+
TWO_TRANSACTION = 1
13+
};
14+
15+
DECLARE_JSON_ENUM(
16+
ReconfigurationType,
17+
{{ReconfigurationType::ONE_TRANSACTION, "OneTransaction"},
18+
{ReconfigurationType::TWO_TRANSACTION, "TwoTransaction"}})
19+
}

include/ccf/tx.h

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5-
#include "ccf/ccf_assert.h"
65
#include "ccf/crypto/sha256_hash.h"
76
#include "ccf/tx_id.h"
87

python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "6.0.0-dev7"
7+
version = "6.0.0-dev8"
88
authors = [
99
{ name="CCF Team", email="[email protected]" },
1010
]

scripts/ci-checks.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@ if [[ -n "$violations" ]]; then
4949
echo "$violations"
5050
exit 1
5151
else
52-
echo "No public header violations"
52+
echo "No public-private include violations"
53+
fi
54+
endgroup
55+
56+
group "Public header namespaces"
57+
# Enforce that all public headers namespace their exports
58+
# NB: This only greps for a namespace definition in each file, doesn't precisely enforce that no types escape that namespace - mistakes are possible
59+
violations=$(find "$ROOT_DIR/include/ccf" -type f -name "*.h" -print0 | xargs --null grep -L "namespace ccf" | sort || true)
60+
if [[ -n "$violations" ]]; then
61+
echo "Public headers missing ccf namespace:"
62+
echo "$violations"
63+
exit 1
64+
else
65+
echo "No public header namespace violations"
5366
fi
5467
endgroup
5568

0 commit comments

Comments
 (0)