From f460fdfd2cd294bb436e666639c1b80b108235e5 Mon Sep 17 00:00:00 2001 From: Shane Gable <76533041+shangabl@users.noreply.github.com> Date: Thu, 2 Feb 2023 19:54:50 -0600 Subject: [PATCH] Boost 1.81 (#122) * Upgrade to Boost 1.81 --- .github/workflows/ci.yml | 8 ++--- CMakeLists.txt | 4 +-- Dockerfile | 4 +-- README.md | 6 ++-- src/TcpAdapterProxy.cpp | 6 ++-- src/config/ConfigFile.cpp | 5 --- src/main.cpp | 74 ++++++++++++++++++++++----------------- test/TestHttpServer.cpp | 7 ++-- 8 files changed, 59 insertions(+), 55 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a88b326..001fa37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,9 +24,9 @@ jobs: - name: Install boost working-directory: ${{ github.workspace }} run: | - wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz -O /tmp/boost.tar.gz + wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz tar xzvf /tmp/boost.tar.gz - cd boost_1_79_0 + cd boost_1_81_0 ./bootstrap.sh --with-toolset=clang ./b2 install toolset=clang link=static - name: Install protobuf @@ -66,9 +66,9 @@ jobs: - name: Install boost working-directory: ${{ github.workspace }} run: | - wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz -O /tmp/boost.tar.gz + wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz tar xzvf /tmp/boost.tar.gz - cd boost_1_79_0 + cd boost_1_81_0 ./bootstrap.sh sudo ./b2 install link=static - name: Install protobuf diff --git a/CMakeLists.txt b/CMakeLists.txt index d1b6609..831892c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,8 +75,8 @@ endif(BUILD_TESTS) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_DEBUG_RUNTIME OFF) #set_property(GLOBAL PROPERTY Boost_USE_MULTITHREADED ON) -set(BOOST_PKG_VERSION "1.79.0" CACHE STRING "") -find_package(Boost ${BOOST_PKG_VERSION} REQUIRED COMPONENTS system log log_setup thread program_options date_time filesystem) +set(BOOST_PKG_VERSION "1.81.0" CACHE STRING "") +find_package(Boost ${BOOST_PKG_VERSION} REQUIRED COMPONENTS system log log_setup thread program_options date_time filesystem chrono) include_directories(${Boost_INCLUDE_DIRS}) foreach(BOOST_LIB ${Boost_LIBRARIES}) string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} BOOST_STATIC_LIB ${BOOST_LIB}) diff --git a/Dockerfile b/Dockerfile index 69c8979..d639404 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,9 +22,9 @@ RUN wget https://www.zlib.net/zlib-1.2.13.tar.gz -O /tmp/zlib-1.2.13.tar.gz && \ make install && \ cd /home/dependencies -RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz -O /tmp/boost.tar.gz && \ +RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz && \ tar xzvf /tmp/boost.tar.gz && \ - cd boost_1_79_0 && \ + cd boost_1_81_0 && \ ./bootstrap.sh && \ ./b2 install link=static && \ cd /home/dependencies diff --git a/README.md b/README.md index eba0928..f67599d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ previous step, or you can run `./docker-run.sh -p ` to expose a por * C++ 14 compiler * CMake 3.6+ * Development libraries required: - * Boost 1.79 + * Boost 1.81 * Protobuf 3.17.x * zlib 1.12.13+ * OpenSSL 1.0+ OR OpenSSL 3 @@ -63,9 +63,9 @@ Fedora example: #### 2. Download and install Boost dependency - wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz -O /tmp/boost.tar.gz + wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz tar xzvf /tmp/boost.tar.gz - cd boost_1_79_0 + cd boost_1_81_0 ./bootstrap.sh sudo ./b2 install link=static diff --git a/src/TcpAdapterProxy.cpp b/src/TcpAdapterProxy.cpp index c715cd9..435dc72 100644 --- a/src/TcpAdapterProxy.cpp +++ b/src/TcpAdapterProxy.cpp @@ -184,7 +184,7 @@ namespace aws { namespace iot { namespace securedtunneling { { throw e; } - BOOST_LOG_SEV(log, error) << "Failed web socket session ID: " << tac.wss_response["channel-id"].to_string(); + BOOST_LOG_SEV(log, error) << "Failed web socket session ID: " << tac.wss_response["channel-id"]; } } } @@ -836,12 +836,12 @@ namespace aws { namespace iot { namespace securedtunneling { tac.wss->binary(true); tac.wss->auto_fragment(true); //output this first because it'll be necessary to have this if any further errors need support/debugging - BOOST_LOG_SEV(log, info) << "Web socket session ID: " << tac.wss_response["channel-id"].to_string(); + BOOST_LOG_SEV(log, info) << "Web socket session ID: " << tac.wss_response["channel-id"]; if (!tac.wss_response.count(boost::beast::http::field::sec_websocket_protocol)) { throw proxy_exception("No websocket subprotocol returned from proxy server!"); } - BOOST_LOG_SEV(log, debug) << "Web socket subprotocol selected: " << tac.wss_response[boost::beast::http::field::sec_websocket_protocol].to_string(); + BOOST_LOG_SEV(log, debug) << "Web socket subprotocol selected: " << tac.wss_response[boost::beast::http::field::sec_websocket_protocol]; BOOST_LOG_SEV(log, info) << "Successfully established websocket connection with proxy server: wss://" << tac.adapter_config.proxy_host << ":" << tac.adapter_config.proxy_port; std::shared_ptr ping_data = std::make_shared(); do_ping_data(tac, *ping_data); diff --git a/src/config/ConfigFile.cpp b/src/config/ConfigFile.cpp index 71fbf62..9afb7ca 100644 --- a/src/config/ConfigFile.cpp +++ b/src/config/ConfigFile.cpp @@ -1,15 +1,10 @@ // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#include #include #include #include #include -#include -#include #include -#include -#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 491614e..902e796 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include @@ -99,41 +99,52 @@ void log_formatter(boost::log::formatting_ostream& strm, boost::log::record_view " " << rec["Message"].extract(); } -void set_logging_filter(std::uint16_t level_numeric) +void init_logging(std::uint16_t &logging_level) { - level_numeric = level_numeric > 6 ? 6 : level_numeric; + boost::log::add_common_attributes(); + logging_level = logging_level > 6 ? 6 : logging_level; - switch (level_numeric) + switch (logging_level) { - case 6: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::trace); - break; - case 5: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug); - break; - case 4: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); - break; - case 3: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::warning); - break; - case 2: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::error); - break; - case 1: - boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::fatal); - break; - case 0: - boost::log::core::get()->set_logging_enabled(false); - break; + case 6: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::trace); + break; + case 5: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug); + break; + case 4: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); + break; + case 3: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::warning); + break; + case 2: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::error); + break; + case 1: + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::fatal); + break; + case 0: + boost::log::core::get()->set_logging_enabled(false); + break; } -} -void init_logging(std::uint16_t &logging_level) -{ - boost::log::add_common_attributes(); - boost::log::add_console_log(std::cout, boost::log::keywords::format = boost::phoenix::bind(&log_formatter, boost::log::expressions::stream, boost::log::expressions::record)); - set_logging_filter(logging_level); + /* log formatter: + * [TimeStamp] [ThreadId] [Severity Level] [Scope] Log message + */ + auto fmtTimeStamp = boost::log::expressions:: + format_date_time("TimeStamp", "%Y-%m-%d %H:%M:%S.%f"); + auto fmtThreadId = boost::log::expressions:: + attr("ThreadID"); + auto fmtSeverity = boost::log::expressions:: + attr("Severity"); + boost::log::formatter logFmt = + boost::log::expressions::format("[%1%] (%2%) [%3%] %4%") + % fmtTimeStamp % fmtThreadId % fmtSeverity % boost::log::expressions::smessage; + + auto consoleSink = boost::log::add_console_log(std::clog); + consoleSink->set_formatter(logFmt); + } bool process_cli(int argc, char ** argv, LocalproxyConfig &cfg, ptree &settings, std::uint16_t &logging_level) @@ -400,7 +411,6 @@ int main(int argc, char ** argv) if (process_cli(argc, argv, cfg, settings, logging_level)) { - set_logging_filter(logging_level); tcp_adapter_proxy proxy{ settings, cfg }; return proxy.run_proxy(); } diff --git a/test/TestHttpServer.cpp b/test/TestHttpServer.cpp index 5a5bae2..e807f4f 100644 --- a/test/TestHttpServer.cpp +++ b/test/TestHttpServer.cpp @@ -10,7 +10,6 @@ #include -using boost::beast::string_view; namespace base64 = boost::beast::detail::base64; /** @@ -25,17 +24,17 @@ template void handle_request(http::request>&& req, Send&& send) { // Returns a 4xx response auto const client_error = - [&req](string_view why, http::status status) { + [&req](std::string why, http::status status) { http::response res{status, req.version()}; res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body() = why.to_string(); + res.body() = why; res.prepare_payload(); return res; }; // Returns a 500 response auto const server_error = - [&req](boost::beast::string_view what) + [&req](std::string what) { http::response res{http::status::internal_server_error, req.version()}; res.set(http::field::content_type, "text/html");