aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
IoTSDKMetricsPrivate.h
Go to the documentation of this file.
1
6#pragma once
12#include <aws/crt/Types.h>
17#include <aws/io/tls_channel_handler.h>
18
19// Private constants and encoder for IoT SDK metrics.
20// Not part of the public API — include only from CRT implementation files.
21
22namespace Aws
23{
24 namespace Crt
25 {
26 namespace Mqtt
27 {
28 // Forward declaration
29 class MqttConnectionCore;
30
31 // Feature ID Constants
32 //
33 // Single-char IDs used to encode feature usage in the metrics string.
34 // IDs are assigned sequentially and are never reused to ensure
35 // historical data consistency.
36 namespace MetricsFeatureId
37 {
38 constexpr char RetryJitterMode = 'A';
39 constexpr char SessionBehavior = 'B';
40 constexpr char OfflineQueueBehavior = 'C';
41 constexpr char OutboundTopicAliasBehavior = 'D';
42 constexpr char InboundTopicAliasBehavior = 'E';
43 constexpr char ProtocolVersion = 'F';
44 constexpr char SocketImplementation = 'G';
45 constexpr char HttpProxyType = 'H';
46 constexpr char CertificateSource = 'I';
47 constexpr char TlsCipherPreference = 'J';
48 constexpr char MinimumTlsVersion = 'K';
49 } // namespace MetricsFeatureId
50
51 // The current version of the IoT SDK metrics feature encoding format.
52 // Included in the IoTSDKMetricsVersion metadata field.
53 // Increment this when the feature encoding format changes.
54 constexpr int IoTSDKMetricsFeatureVersion = 1;
55
56 // Feature Value Constants for protocol version
57 namespace MetricsProtocolVersionValue
58 {
59 constexpr char Mqtt311 = '3';
60 constexpr char Mqtt5 = '5';
61 } // namespace MetricsProtocolVersionValue
62
63 // Feature Value Constants for socket implementation
64 namespace MetricsSocketImplementationValue
65 {
66 constexpr char Posix = 'A';
67 constexpr char Winsock = 'B';
68 constexpr char AppleNetworkFramework = 'C';
69 } // namespace MetricsSocketImplementationValue
70
71 // Feature Value Constants for HTTP proxy type
72 namespace MetricsHttpProxyTypeValue
73 {
74 constexpr char Http = 'A';
75 constexpr char Https = 'B';
76 } // namespace MetricsHttpProxyTypeValue
77
78 // Feature Value Constants for certificate source
79 namespace MetricsCertificateSourceValue
80 {
81 constexpr char CertificateFiles = 'A';
82 constexpr char Pkcs11 = 'B';
83 constexpr char WindowsCertStore = 'C';
84 // 'D' is reserved for Java keystore (not applicable to C++)
85 constexpr char Pkcs12File = 'E';
86 } // namespace MetricsCertificateSourceValue
87
88 // Feature Value Constants for TLS cipher preference
89 // Assigned sequentially by aws_tls_cipher_pref enum value (1-11), skipping SYSTEM_DEFAULT (0).
90 namespace MetricsTlsCipherPreferenceValue
91 {
92 constexpr char KmsPqTlsv10_2019_06 = 'A'; // enum 1, deprecated
93 constexpr char KmsPqSikeTlsv10_2019_11 = 'B'; // enum 2, deprecated
94 constexpr char KmsPqTlsv10_2020_02 = 'C'; // enum 3, deprecated
95 constexpr char KmsPqSikeTlsv10_2020_02 = 'D'; // enum 4, deprecated
96 constexpr char KmsPqTlsv10_2020_07 = 'E'; // enum 5, deprecated
97 constexpr char PqTlsv10_2021_05 = 'F'; // enum 6, deprecated
98 constexpr char PqTlsv12_2024_10 = 'G'; // enum 7
99 constexpr char PqDefault = 'H'; // enum 8
100 constexpr char Tlsv12_2025_07 = 'I'; // enum 9
101 constexpr char Tlsv10_2023_06 = 'J'; // enum 10
102 constexpr char NonPqDefault = 'K'; // enum 11
103 } // namespace MetricsTlsCipherPreferenceValue
104
105 // Feature Value Constants for minimum TLS version
106 namespace MetricsMinimumTlsVersionValue
107 {
108 constexpr char SSLv3 = 'A';
109 constexpr char TLSv1 = 'B';
110 constexpr char TLSv1_1 = 'C';
111 constexpr char TLSv1_2 = 'D';
112 constexpr char TLSv1_3 = 'E';
113 } // namespace MetricsMinimumTlsVersionValue
114
118 class IoTSDKMetricsEncoder
119 {
120 public:
121 // Default library name identifier used when no custom name is provided for metrics.
122 static constexpr const char *DEFAULT_METRICS_LIBRARY_NAME = "IoTDeviceSDK/CPP";
123
131 static AWSIoTMetrics createMetricsForMqtt5(const Mqtt5::Mqtt5ClientOptions &options);
132
139 static AWSIoTMetrics createMetricsForMqtt311(const MqttConnectionCore &connectionCore);
140
141 private:
142 // Appends a "featureId/value" token to the feature list string.
143 // Skips the token if value is '\0' (default — omit from list).
144 static void appendFeature(Crt::String &featureList, char featureId, char value);
145
146 /*
147 * This function create and update the final metrics from the userMetrics and crtFeatureList
148 *
149 * According to the following rules:
150 * - libraryName: set to default SDK Name. If the libraryName field is set from
151 * user metrics, overwrite the default value.
152 * - Metadata - CRTVersion: not modifiable by user, automatically set to CRT version.
153 * - Metadata - IoTSDKMetricsVersion: If set by user metrics, validates whether the
154 * metrics version matches the library's metrics version and processes IoTSDKFeature.
155 * - Metadata - IoTSDKFeature: merge the CRT feature and the input feature if the
156 * metrics version matches.
157 * - Other user metadata: preserved in the output (excluding reserved keys).
158 */
159 static void createMetricsFromFeatureList(
160 const Crt::String &crtFeatureList,
161 const AWSIoTMetrics *userMetrics,
162 AWSIoTMetrics &outMetrics);
163
173 static Crt::String getEncodedFeatureListForMqtt5(const Mqtt5::Mqtt5ClientOptions &options);
174
182 static Crt::String getEncodedFeatureListForMqtt311(const MqttConnectionCore &connectionCore);
183
193 static Crt::String mergeFeatureLists(const Crt::String &crtFeatures, const Crt::String &userFeatures);
194
195 // Extension mappings from existing enums to metrics values.
196 // Returns '\0' for default/unset values (omit from the encoded feature list).
197
198 // Maps ExponentialBackoffJitterMode to its metrics value char.
199 static char metricsValueForRetryJitterMode(Mqtt5::ExponentialBackoffJitterMode mode);
200
201 // Maps ClientSessionBehaviorType to its metrics value char.
202 static char metricsValueForSessionBehavior(Mqtt5::ClientSessionBehaviorType behavior);
203
204 // Maps ClientOperationQueueBehaviorType to its metrics value char.
205 static char metricsValueForOfflineQueueBehavior(Mqtt5::ClientOperationQueueBehaviorType behavior);
206
207 // Maps outbound topic alias behavior to its metrics value char.
208 static char metricsValueForOutboundTopicAliasBehavior(Mqtt5::OutboundTopicAliasBehaviorType behavior);
209
210 // Maps inbound topic alias behavior to its metrics value char.
211 static char metricsValueForInboundTopicAliasBehavior(Mqtt5::InboundTopicAliasBehaviorType behavior);
212
213 // Maps Io::CertificateSource to its metrics value char.
214 // Returns '\0' for CertificateSource::None (omit from encoded list).
215 static char metricsValueForCertificateSource(Io::CertificateSource source);
216
217 // Maps aws_tls_cipher_pref to its metrics value char.
218 // Returns '\0' for AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT (omit from encoded list).
219 static char metricsValueForTlsCipherPreference(aws_tls_cipher_pref pref);
220
221 // Maps aws_tls_versions to its metrics value char.
222 // Returns '\0' for AWS_IO_TLS_VER_SYS_DEFAULTS (omit from encoded list).
223 static char metricsValueForMinimumTlsVersion(aws_tls_versions version);
224
225 // Returns the metrics value char for the socket implementation on the current platform.
226 // Detected at compile time: Winsock on Windows, Apple Network Framework on Apple, POSIX elsewhere.
227 static char detectSocketImplementation();
228 };
229
230 } // namespace Mqtt
231 } // namespace Crt
232} // namespace Aws
Definition Allocator.h:11