Skip to content

Commit 8980ea8

Browse files
authored
Merge pull request #34 from MiaoZhangAWS/master
Add support for tunnel multi-port feature
2 parents 6d1377a + 5d2be62 commit 8980ea8

17 files changed

+2183
-455
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
run: |
5252
mkdir build
5353
cd build
54-
cmake .. -DOPENSSL_ROOT_DIR=/usr/local/Cellar/[email protected]/1.1.1g/ -DOPENSSL_LIBRARIES=/usr/local/Cellar/[email protected]/1.1.1g/lib/
54+
cmake .. -DOPENSSL_ROOT_DIR=/usr/local/Cellar/[email protected]/1.1.1h/ -DOPENSSL_LIBRARIES=/usr/local/Cellar/[email protected]/1.1.1h/lib/
5555
make
5656
ubuntu:
5757
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ find_package(Catch2 REQUIRED)
6666
#########################################
6767
# Boost dependencies #
6868
#########################################
69-
set_property(GLOBAL PROPERTY Boost_USE_STATIC_LIBS ON)
69+
set_property(GLOBAL PROPERTY Boost_USE_STATIC_LIBS ON)
7070
set_property(GLOBAL PROPERTY Boost_USE_DEBUG_RUNTIME OFF)
7171
#set_property(GLOBAL PROPERTY Boost_USE_MULTITHREADED ON)
72-
find_package(Boost 1.68.0 REQUIRED COMPONENTS system log log_setup thread program_options date_time)
72+
find_package(Boost 1.68.0 REQUIRED COMPONENTS system log log_setup thread program_options date_time filesystem)
7373
include_directories(${Boost_INCLUDE_DIRS})
7474
foreach(BOOST_LIB ${Boost_LIBRARIES})
7575
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} BOOST_STATIC_LIB ${BOOST_LIB})
@@ -81,9 +81,10 @@ endforeach()
8181
#########################################
8282
file(GLOB ALL_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
8383

84+
set(UTIL_SOURCE ${PROJECT_SOURCE_DIR}/src/config/ConfigFile.cpp)
8485
set(CORE_SOURCES ${PROJECT_SOURCE_DIR}/src/TcpAdapterProxy.cpp ${PROJECT_SOURCE_DIR}/src/ProxySettings.cpp ${PROTO_HDRS} ${PROTO_SRCS})
85-
set(MAIN_SOURCES ${PROJECT_SOURCE_DIR}/src/main.cpp ${CORE_SOURCES})
86-
set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/AdapterTests.cpp ${CORE_SOURCES} ${PROJECT_SOURCE_DIR}/test/TestWebsocketServer.cpp)
86+
set(MAIN_SOURCES ${PROJECT_SOURCE_DIR}/src/main.cpp ${CORE_SOURCES} ${UTIL_SOURCE})
87+
set(TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/AdapterTests.cpp ${CORE_SOURCES} ${UTIL_SOURCE} ${PROJECT_SOURCE_DIR}/test/TestWebsocketServer.cpp)
8788

8889
add_executable(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${MAIN_SOURCES})
8990
add_executable(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${TEST_SOURCES})

README.md

Lines changed: 153 additions & 9 deletions
Large diffs are not rendered by default.

WebsocketProtocolGuide.md renamed to V1WebSocketProtocolGuide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
The reference implementation of the local proxy provides features that may require OS facilities not available on all device runtime environments in the industry. This guide provides details about the communication that occurs between the service and client to enable integration without or beyond the local proxy reference implementation choices.
1+
The reference implementation of the local proxy provides features that may require OS facilities not available on all device runtime environments in the industry. This guide provides details about the communication that occurs between the service and client to enable integration without or beyond the local proxy reference implementation choices. This protocol guide is only applicable for v1 local proxy.
22

33
## Core implementation requirements
44

5-
In order to properly connect with and interpret messages from the AWS IoT Secure Tunneling service, the bare minimum is required:
5+
In order to properly connect with and interpret messages from the AWS IoT Secure Tunneling service, the following is required:
66

77
**Communications Protocols:**
88
* Websocket protocol ([RFC6455](https://tools.ietf.org/html/rfc6455)) over TCP/IP

V2WebSocketProtocolGuide.md

Lines changed: 287 additions & 0 deletions
Large diffs are not rendered by default.

resources/Message.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ message Message {
1212
int32 streamId = 2;
1313
bool ignorable = 3;
1414
bytes payload = 4;
15+
string serviceId = 5;
16+
repeated string availableServiceIds = 6;
1517

1618
enum Type {
1719
UNKNOWN = 0;
1820
DATA = 1;
1921
STREAM_START = 2;
2022
STREAM_RESET = 3;
2123
SESSION_RESET = 4;
24+
SERVICE_IDS = 5;
2225
}
2326
}

src/ProxySettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace aws { namespace iot { namespace securedtunneling { namespace settings
4848
bool const DEFAULT_WEB_SOCKET_DATA_ERROR_RETRY = true;
4949

5050
char const * const KEY_WEB_SOCKET_SUBPROTOCOL = "tunneling.proxy.websocket.subprotocol";
51-
std::string const DEFAULT_WEB_SOCKET_SUBPROTOCOL = "aws.iot.securetunneling-1.0";
51+
std::string const DEFAULT_WEB_SOCKET_SUBPROTOCOL = "aws.iot.securetunneling-2.0";
5252

5353
char const * const KEY_WEB_SOCKET_MAX_FRAME_SIZE = "tunneling.proxy.websocket.max_frame_size";
5454
std::size_t const DEFAULT_WEB_SOCKET_MAX_FRAME_SIZE = DEFAULT_MAX_DATA_FRAME_SIZE * 2;

src/TcpAdapterProxy.cpp

Lines changed: 903 additions & 263 deletions
Large diffs are not rendered by default.

src/TcpAdapterProxy.h

Lines changed: 98 additions & 84 deletions
Large diffs are not rendered by default.

src/TcpClient.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
#pragma once
4+
#include <boost/beast/core/flat_buffer.hpp>
5+
#include <boost/asio.hpp>
6+
#include <boost/asio/ip/tcp.hpp>
7+
#include "Message.pb.h"
8+
9+
namespace aws { namespace iot { namespace securedtunneling { namespace connection {
10+
class tcp_client
11+
{
12+
public:
13+
typedef boost::shared_ptr<tcp_client> pointer;
14+
tcp_client(boost::asio::io_context & io_context, std::size_t write_buf_size, std::size_t read_buf_size, std::size_t ws_write_buf_size)
15+
: resolver_(io_context)
16+
{
17+
connection_ =
18+
tcp_connection::create(io_context, write_buf_size, read_buf_size, ws_write_buf_size);
19+
}
20+
static pointer create(boost::asio::io_context& io_context, std::size_t const & write_buf_size, std::size_t const & read_buf_size, std::size_t const & ws_write_buf_size)
21+
{
22+
return pointer(new tcp_client(io_context, write_buf_size, read_buf_size, ws_write_buf_size));
23+
}
24+
25+
tcp_connection::pointer connection_;
26+
tcp::resolver resolver_;
27+
// function object defines what to do after set up a tcp socket
28+
std::function<void()> after_setup_tcp_socket = nullptr;
29+
// function object defines what to do receiving control message: stream start
30+
std::function<void()> on_receive_stream_start = nullptr;
31+
};
32+
}}}}

0 commit comments

Comments
 (0)