Skip to content

Commit

Permalink
Boost 1.81 (#122)
Browse files Browse the repository at this point in the history
* Upgrade to Boost 1.81
  • Loading branch information
shangabl authored Feb 3, 2023
1 parent 851de4c commit f460fdf
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ previous step, or you can run `./docker-run.sh -p <port_number>` 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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/TcpAdapterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
}
}
}
Expand Down Expand Up @@ -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<boost::beast::websocket::ping_data> ping_data = std::make_shared<boost::beast::websocket::ping_data>();
do_ping_data(tac, *ping_data);
Expand Down
5 changes: 0 additions & 5 deletions src/config/ConfigFile.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#include <cstdlib>
#include <chrono>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <utility>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#include <boost/phoenix.hpp>
#include <boost/program_options.hpp>
Expand Down
74 changes: 42 additions & 32 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <utility>
#include <tuple>

#include <boost/phoenix.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/property_tree/ptree.hpp>
Expand All @@ -21,6 +20,7 @@
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/expressions.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/log/support/date_time.hpp>

#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
Expand Down Expand Up @@ -99,41 +99,52 @@ void log_formatter(boost::log::formatting_ostream& strm, boost::log::record_view
" " << rec["Message"].extract<std::string>();
}

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<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S.%f");
auto fmtThreadId = boost::log::expressions::
attr<boost::log::attributes::current_thread_id::value_type>("ThreadID");
auto fmtSeverity = boost::log::expressions::
attr<boost::log::trivial::severity_level>("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)
Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 3 additions & 4 deletions test/TestHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <memory>


using boost::beast::string_view;
namespace base64 = boost::beast::detail::base64;

/**
Expand All @@ -25,17 +24,17 @@ template<class Body, class Allocator, class Send>
void handle_request(http::request<Body, http::basic_fields<Allocator>>&& 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<http::string_body> 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<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::content_type, "text/html");
Expand Down

0 comments on commit f460fdf

Please sign in to comment.