AWS IoT Device SDK C++ v2: secure_tunneling/include/aws/iotsecuretunneling/SecureTunnel.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

SecureTunnel.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/http/HttpConnection.h>
8#include <aws/crt/io/Bootstrap.h>
9#include <aws/crt/io/SocketOptions.h>
10#include <aws/iotdevice/secure_tunneling.h>
11#include <aws/iotsecuretunneling/Exports.h>
12
13namespace Aws
14{
15 namespace Iotsecuretunneling
16 {
17 class SecureTunnel;
18
19 // Client callback type definitions
20 using OnConnectionComplete = std::function<void(void)>;
21 using OnConnectionShutdown = std::function<void(void)>;
22 using OnSendDataComplete = std::function<void(int errorCode)>;
23 using OnDataReceive = std::function<void(const Crt::ByteBuf &data)>;
24 using OnStreamStart = std::function<void()>;
25 using OnStreamReset = std::function<void(void)>;
26 using OnSessionReset = std::function<void(void)>;
27
28 class AWS_IOTSECURETUNNELING_API SecureTunnelBuilder final
29 {
30 public:
34 SecureTunnelBuilder(
35 Crt::Allocator *allocator, // Should out live this object
36 Aws::Crt::Io::ClientBootstrap &clientBootstrap, // Should out live this object
37 const Aws::Crt::Io::SocketOptions &socketOptions, // Make a copy and save in this object
38 const std::string &accessToken, // Make a copy and save in this object
39 aws_secure_tunneling_local_proxy_mode localProxyMode,
40 const std::string &endpointHost); // Make a copy and save in this object
41
45 SecureTunnelBuilder &WithRootCa(const std::string &rootCa);
46 SecureTunnelBuilder &WithHttpClientConnectionProxyOptions(
47 const Aws::Crt::Http::HttpClientConnectionProxyOptions &httpClientConnectionProxyOptions);
48 SecureTunnelBuilder &WithOnConnectionComplete(OnConnectionComplete onConnectionComplete);
49 SecureTunnelBuilder &WithOnConnectionShutdown(OnConnectionShutdown onConnectionShutdown);
50 SecureTunnelBuilder &WithOnSendDataComplete(OnSendDataComplete onSendDataComplete);
51 SecureTunnelBuilder &WithOnDataReceive(OnDataReceive onDataReceive);
52 SecureTunnelBuilder &WithOnStreamStart(OnStreamStart onStreamStart);
53 SecureTunnelBuilder &WithOnStreamReset(OnStreamReset onStreamReset);
54 SecureTunnelBuilder &WithOnSessionReset(OnSessionReset onSessionReset);
55
62 std::shared_ptr<SecureTunnel> Build() noexcept;
63
64 private:
68 Crt::Allocator *m_allocator;
69 Aws::Crt::Io::ClientBootstrap *m_clientBootstrap;
70 Aws::Crt::Io::SocketOptions m_socketOptions;
71 std::string m_accessToken;
72 aws_secure_tunneling_local_proxy_mode m_localProxyMode;
73 std::string m_endpointHost;
74
78 std::string m_rootCa;
79 Crt::Optional<Crt::Http::HttpClientConnectionProxyOptions> m_httpClientConnectionProxyOptions;
80
84 OnConnectionComplete m_OnConnectionComplete;
85 OnConnectionShutdown m_OnConnectionShutdown;
86 OnSendDataComplete m_OnSendDataComplete;
87 OnDataReceive m_OnDataReceive;
88 OnStreamStart m_OnStreamStart;
89 OnStreamReset m_OnStreamReset;
90 OnSessionReset m_OnSessionReset;
91
92 friend class SecureTunnel;
93 };
94
95 class AWS_IOTSECURETUNNELING_API SecureTunnel final
96 {
97 public:
98 SecureTunnel(
99 Crt::Allocator *allocator, // Should out live this object
100 Aws::Crt::Io::ClientBootstrap *clientBootstrap, // Should out live this object
101 const Aws::Crt::Io::SocketOptions &socketOptions, // Make a copy and save in this object
102
103 const std::string &accessToken, // Make a copy and save in this object
104 aws_secure_tunneling_local_proxy_mode localProxyMode,
105 const std::string &endpointHost, // Make a copy and save in this object
106 const std::string &rootCa, // Make a copy and save in this object
107
108 OnConnectionComplete onConnectionComplete,
109 OnConnectionShutdown onConnectionShutdown,
110 OnSendDataComplete onSendDataComplete,
111 OnDataReceive onDataReceive,
112 OnStreamStart onStreamStart,
113 OnStreamReset onStreamReset,
114 OnSessionReset onSessionReset);
115 SecureTunnel(const SecureTunnel &) = delete;
116 SecureTunnel(SecureTunnel &&) noexcept;
117
118 virtual ~SecureTunnel();
119
120 SecureTunnel &operator=(const SecureTunnel &) = delete;
121 SecureTunnel &operator=(SecureTunnel &&) noexcept;
122
123 bool IsValid();
124
125 int Connect();
126
127 int Close();
128
129 int SendData(const Crt::ByteCursor &data);
130
131 int SendStreamStart();
132
133 int SendStreamReset();
134
135 aws_secure_tunnel *GetUnderlyingHandle();
136
137 private:
142 SecureTunnel(
143 Crt::Allocator *allocator,
144 Aws::Crt::Io::ClientBootstrap *clientBootstrap,
145 const Aws::Crt::Io::SocketOptions &socketOptions,
146 const std::string &accessToken,
147 aws_secure_tunneling_local_proxy_mode localProxyMode,
148 const std::string &endpointHost,
149
150 const std::string &rootCa,
151 Aws::Crt::Http::HttpClientConnectionProxyOptions *httpClientConnectionProxyOptions,
152
153 OnConnectionComplete onConnectionComplete,
154 OnConnectionShutdown onConnectionShutdown,
155 OnSendDataComplete onSendDataComplete,
156 OnDataReceive onDataReceive,
157 OnStreamStart onStreamStart,
158 OnStreamReset onStreamReset,
159 OnSessionReset onSessionReset);
160
161 // aws-c-iot callbacks
162 static void s_OnConnectionComplete(void *user_data);
163 static void s_OnConnectionShutdown(void *user_data);
164 static void s_OnSendDataComplete(int error_code, void *user_data);
165 static void s_OnDataReceive(const struct aws_byte_buf *data, void *user_data);
166 static void s_OnStreamStart(void *user_data);
167 static void s_OnStreamReset(void *user_data);
168 static void s_OnSessionReset(void *user_data);
169
170 // Client callbacks
171 OnConnectionComplete m_OnConnectionComplete;
172 OnConnectionShutdown m_OnConnectionShutdown;
173 OnSendDataComplete m_OnSendDataComplete;
174 OnDataReceive m_OnDataReceive;
175 OnStreamStart m_OnStreamStart;
176 OnStreamReset m_OnStreamReset;
177 OnSessionReset m_OnSessionReset;
178 aws_secure_tunnel *m_secure_tunnel;
179
180 friend class SecureTunnelBuilder;
181 };
182 } // namespace Iotsecuretunneling
183} // namespace Aws
Bootstrap.h
HttpConnection.h
SocketOptions.h
Aws::Crt::Http::HttpClientConnectionProxyOptions
Definition: HttpConnection.h:270
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::Io::SocketOptions
Definition: SocketOptions.h:48
Aws::Crt::Optional
Definition: Optional.h:17
Aws::Iotsecuretunneling::SecureTunnelBuilder
Definition: SecureTunnel.h:29
Aws::Iotsecuretunneling::SecureTunnel
Definition: SecureTunnel.h:96
Aws::Iotsecuretunneling::SecureTunnel::SecureTunnel
SecureTunnel(const SecureTunnel &)=delete
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:33
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:32
Aws::Iotsecuretunneling::OnConnectionShutdown
std::function< void(void)> OnConnectionShutdown
Definition: SecureTunnel.h:21
Aws::Iotsecuretunneling::OnSessionReset
std::function< void(void)> OnSessionReset
Definition: SecureTunnel.h:26
Aws::Iotsecuretunneling::OnStreamStart
std::function< void()> OnStreamStart
Definition: SecureTunnel.h:24
Aws::Iotsecuretunneling::OnConnectionComplete
std::function< void(void)> OnConnectionComplete
Definition: SecureTunnel.h:20
Aws::Iotsecuretunneling::OnDataReceive
std::function< void(const Crt::ByteBuf &data)> OnDataReceive
Definition: SecureTunnel.h:23
Aws::Iotsecuretunneling::OnStreamReset
std::function< void(void)> OnStreamReset
Definition: SecureTunnel.h:25
Aws::Iotsecuretunneling::OnSendDataComplete
std::function< void(int errorCode)> OnSendDataComplete
Definition: SecureTunnel.h:22
Aws
Definition: Api.h:17
Aws::string
const char *const string
Definition: cJSON.h:190
std
Definition: StringView.h:851
Exports.h
AWS_IOTSECURETUNNELING_API
#define AWS_IOTSECURETUNNELING_API
Definition: Exports.h:30