Skip to content

Commit

Permalink
catch boost exceptions in log traces + documentation update (#158)
Browse files Browse the repository at this point in the history
* update README, modify cmakefile for static compilation

* update boost to 1.84 for ubuntu mac and windows CI

* edit README
  • Loading branch information
RogerZhongAWS authored Aug 15, 2024
1 parent c693c43 commit 27e1aa8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- name: Install boost
working-directory: ${{ github.workspace }}
run: |
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz
wget https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0.tar.gz -O /tmp/boost.tar.gz
tar xzvf /tmp/boost.tar.gz
cd boost_1_81_0
cd boost_1_84_0
./bootstrap.sh --with-toolset=clang
./b2 install toolset=clang link=static
sudo ./b2 install toolset=clang link=static
- name: Install protobuf
working-directory: ${{ github.workspace }}
run: |
Expand All @@ -38,7 +38,7 @@ jobs:
cd build_make
cmake ../cmake
make
make install
sudo make install
- name: Building localproxy
working-directory: ${{ github.workspace }}
run: |
Expand All @@ -65,9 +65,9 @@ jobs:
- name: Install boost
working-directory: ${{ github.workspace }}
run: |
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz -O /tmp/boost.tar.gz
wget https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0.tar.gz -O /tmp/boost.tar.gz
tar xzvf /tmp/boost.tar.gz
cd boost_1_81_0
cd boost_1_84_0
./bootstrap.sh
sudo ./b2 install link=static
- name: Install protobuf
Expand Down Expand Up @@ -117,9 +117,9 @@ jobs:
Invoke-WebRequest "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip" -OutFile "nasm-2.15.05-win64.zip"
Expand-Archive "nasm-2.15.05-win64.zip" -Force -DestinationPath "C:\NASM"
$env:Path += ";C:\NASM\nasm-2.15.05\"
git clone https://github.com/openssl/openssl.git
cd openssl
git checkout OpenSSL_1_1_1-stable
Invoke-WebRequest "https://github.com/openssl/openssl/archive/refs/tags/openssl-3.0.12.zip" -OutFile "openssl-3.0.12.zip"
Expand-Archive "openssl-3.0.12.zip" -Force
cd .\openssl-3.0.12\openssl-openssl-3.0.12\
perl Configure VC-WIN64A
nmake
nmake install
Expand All @@ -145,11 +145,11 @@ jobs:
$env:Path += ";C:\Program Files (x86)\zlib\bin"
- name: Install boost
run: |
Invoke-WebRequest "https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.zip" -OutFile "boost_1_76_0.zip"
Expand-Archive "boost_1_76_0.zip" -Force
cd .\boost_1_76_0\boost_1_76_0\
Invoke-WebRequest "https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0.zip" -OutFile "boost_1_84_0.zip"
Expand-Archive "boost_1_84_0.zip" -Force
cd .\boost_1_84_0\boost_1_84_0\
.\bootstrap.bat
.\b2 toolset=msvc-14.2 address-model=64 install define=BOOST_WINAPI_VERSION_WIN10 link=static
.\b2 toolset=msvc-14.2 address-model=64 install define=_WIN32_WINNT=0x0601 define=BOOST_WINAPI_VERSION_WIN7 link=static
- name: Install protobuf
run: |
cd \
Expand All @@ -169,7 +169,7 @@ jobs:
run: |
mkdir build
cd build
cmake -DBUILD_TESTS=OFF -DBOOST_PKG_VERSION=1.76.0 -DWIN32_WINNT=0x0A00 -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 16 2019" -A x64 ..\
cmake -DBUILD_TESTS=OFF -DBOOST_PKG_VERSION=1.84.0 -DWIN32_WINNT=0x0601 -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 16 2019" -A x64 ..\
msbuild localproxy.vcxproj -p:Configuration=Release
- name: Upload Artifact
uses: actions/upload-artifact@v3
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROJECT_SOURCE_DIR}/resources/Mess
#########################################
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)

include_directories(${OPENSSL_INCLUDE_DIR})
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY})
Expand Down Expand Up @@ -114,6 +115,9 @@ endif()
include_directories(${PROJECT_SOURCE_DIR}/src)

target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
# target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::SSL)
# target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::Crypto)
### uncomment above 2 lines and remove below 2 lines to link against OpenSSL shared libs
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Boost_STATIC_LIBRARIES})
Expand All @@ -123,8 +127,11 @@ set_property(TARGET ${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} APPEND_STRING PROPERTY

if(BUILD_TESTS)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_THREAD_LIBS_INIT})
# target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::SSL)
# target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::Crypto)
### uncomment above 2 lines and remove below 2 lines to link against OpenSSL shared libs
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Boost_STATIC_LIBRARIES})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Protobuf_LITE_STATIC_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_DL_LIBS})
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ Source install example:

Run the ./Configure command without any arguments to check the available platform configuration options and the documentation here: https://wiki.openssl.org/index.php/Compilation_and_Installation

##### Static vs. Dynamic linking OpenSSL
In the `CMakeLists.txt`, there are marked sections with commented code that when uncommented, allow users to switch between using static vs shared OpenSSL libraries. Choosing to do so is completely optional depending on your own operational requirements. This is following guidance from https://github.com/aws-samples/aws-iot-securetunneling-localproxy/pull/145. The localproxy uses static libs by default

#### 5. Download and install Catch2 test framework

git clone --branch v2.13.6 https://github.com/catchorg/Catch2.git
Expand Down
25 changes: 19 additions & 6 deletions src/TcpAdapterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ namespace aws { namespace iot { namespace securedtunneling {
}
BOOST_LOG_SEV(log, debug) << "Handling explicit reset by closing TCP for service id: " << service_id << " connection id: " << connection_id;

connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
std::shared_ptr<bool> web_socket_write_buffer_drain_complete = std::make_shared<bool>(false);
std::shared_ptr<bool> tcp_write_buffer_drain_complete = std::make_shared<bool>(false);

Expand Down Expand Up @@ -378,7 +377,14 @@ namespace aws { namespace iot { namespace securedtunneling {
{
tcp_connection::pointer connection_to_reset = get_tcp_connection(tac, service_id, connection_id);
BOOST_LOG_SEV(this->log, trace) << "Post-reset TCP drain complete. Closing TCP socket for service id " << service_id << " connection id " << connection_id;
BOOST_LOG_SEV(this->log, info) << "Disconnected from: " << connection_to_reset->socket().remote_endpoint();
try
{
BOOST_LOG_SEV(this->log, info) << "Disconnected from: " << connection_to_reset->socket().remote_endpoint();
}
catch (std::exception& e)
{
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found due to TCP connection already terminated";
}
connection_to_reset->socket_.close();
delete_tcp_socket(tac, service_id, connection_id);
*tcp_write_buffer_drain_complete = true;
Expand Down Expand Up @@ -417,7 +423,14 @@ namespace aws { namespace iot { namespace securedtunneling {
{
tcp_connection::pointer connection_to_reset = get_tcp_connection(tac, service_id, connection_id);
BOOST_LOG_SEV(this->log, trace) << "Post-reset TCP drain complete. Closing TCP socket for service id " << service_id << " connection id " << connection_id;
BOOST_LOG_SEV(this->log, info) << "Disconnected from: " << connection_to_reset->socket().remote_endpoint();
try
{
BOOST_LOG_SEV(this->log, info) << "Disconnected from: " << connection_to_reset->socket().remote_endpoint();
}
catch (std::exception& e)
{
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found due to TCP connection already terminated";
}
connection_to_reset->socket_.close();
delete_tcp_socket(tac, service_id, connection_id);
};
Expand Down Expand Up @@ -508,11 +521,11 @@ namespace aws { namespace iot { namespace securedtunneling {
}
catch (std::exception& e)
{
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found";
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found due to TCP connection already terminated";
}
connection->tcp_write_buffer_.consume(connection->tcp_write_buffer_.max_size());
// this works on Linux x86_64 but causes a bus error on Darwin arm64, commenting it out
//connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
// connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
connection->socket_.close();

connection->on_web_socket_write_buffer_drain_complete = [&, service_id, connection_id]()
Expand Down Expand Up @@ -2310,4 +2323,4 @@ namespace aws { namespace iot { namespace securedtunneling {
return false;
}
}
}}}
}}}

0 comments on commit 27e1aa8

Please sign in to comment.