diff --git a/services/tunnelbroker/CMakeLists.txt b/services/tunnelbroker/CMakeLists.txt index a01ea1e7e..28818758c 100644 --- a/services/tunnelbroker/CMakeLists.txt +++ b/services/tunnelbroker/CMakeLists.txt @@ -1,197 +1,221 @@ PROJECT(tunnelbroker C CXX) cmake_minimum_required(VERSION 3.16) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) set(CMAKE_CXX_STANDARD 17) # FIND LIBS set(protobuf_MODULE_COMPATIBLE TRUE) find_package(Protobuf CONFIG REQUIRED) message(STATUS "Using protobuf ${Protobuf_VERSION}") set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) +set(_REFLECTION gRPC::grpc++_reflection) set(_PROTOBUF_PROTOC $) # gRPC building parameters set(gRPC_BUILD_CSHARP_EXT OFF) set(gRPC_SSL_PROVIDER "package" CACHE STRING "SSL library provider") # Disable unused plugins set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF) set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF) set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF) set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF) # Find gRPC installation # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. find_package(gRPC CONFIG REQUIRED) message(STATUS "Using gRPC ${gRPC_VERSION}") set(_GRPC_GRPCPP gRPC::grpc++) set(_GRPC_CPP_PLUGIN_EXECUTABLE $) # Find AMQP-CPP installation set(AMQPCPP_ROOT "/usr/lib/AMQP-CPP") set(AMQPCPP_INCLUDE_DIR ${AMQPCPP_ROOT}/include) set(AMQPCPP_LIBRARIES ${AMQPCPP_ROOT}/build/bin/libamqpcpp.so) # Find Cryptopp installation set(CRYPTOPP_ROOT "/usr/lib/cryptopp/build") set(CRYPTOPP_INCLUDE_DIR ${CRYPTOPP_ROOT}/include) set(CRYPTOPP_LIBRARIES ${CRYPTOPP_ROOT}/lib/libcryptopp.a) # Find Libuv installation set(LIBUV_ROOT "/usr/lib/libuv") set(LIBUV_INCLUDE_DIR ${LIBUV_ROOT}/include) set(LIBUV_LIBRARIES ${LIBUV_ROOT}/build/libuv.so) set(BUILD_TESTING OFF CACHE BOOL "Turn off tests" FORCE) set(WITH_GFLAGS OFF CACHE BOOL "Turn off gflags" FORCE) find_package(AWSSDK REQUIRED COMPONENTS core dynamodb) find_package(Boost 1.40 COMPONENTS program_options thread system REQUIRED) find_package(OpenSSL REQUIRED) add_subdirectory(./lib/glog) +# Generated sources +get_filename_component(proto "protos/tunnelbroker.proto" ABSOLUTE) +get_filename_component(proto_path "${proto}" PATH) + +set(GENERATED_BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen") +set(GENERATED_CODE_DIR "${GENERATED_BASE_DIR}/_generated") +file(MAKE_DIRECTORY ${GENERATED_CODE_DIR}) + +set(proto_srcs "${GENERATED_CODE_DIR}/tunnelbroker.pb.cc") +set(proto_hdrs "${GENERATED_CODE_DIR}/tunnelbroker.pb.h") +set(grpc_srcs "${GENERATED_CODE_DIR}/tunnelbroker.grpc.pb.cc") +set(grpc_hdrs "${GENERATED_CODE_DIR}/tunnelbroker.grpc.pb.h") +add_custom_command( + OUTPUT "${proto_srcs}" "${proto_hdrs}" "${grpc_srcs}" "${grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${GENERATED_CODE_DIR}" + --cpp_out "${GENERATED_CODE_DIR}" + -I "${proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${proto}" + DEPENDS "${proto}" +) + file(GLOB SOURCE_CODE "./src/*.cpp" "./src/**/*.cpp") -file(GLOB GENERATED_CODE "./_generated/*.cc") +set(GENERATED_CODE ${proto_srcs} ${proto_hdrs} ${grpc_srcs} ${grpc_hdrs}) file(GLOB DOUBLE_CONVERSION_SOURCES "./lib/double-conversion/double-conversion/*.cc") add_definitions( -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=0 -DFOLLY_MOBILE=0 ) include_directories( ./src ./src/Database ./src/DeliveryBroker ./src/Service ./src/Tools ./src/Amqp - ./_generated + ${GENERATED_BASE_DIR} ./lib/folly ./lib/double-conversion ${Boost_INCLUDE_DIR} ${AMQPCPP_INCLUDE_DIR} ${CRYPTOPP_INCLUDE_DIR} ${LIBUV_INCLUDE_DIR} ) set( SOURCE_CODE - + # folly ./lib/folly/folly/detail/Futex.cpp ./lib/folly/folly/synchronization/ParkingLot.cpp ./lib/folly/folly/lang/SafeAssert.cpp ./lib/folly/folly/FileUtil.cpp ./lib/folly/folly/Subprocess.cpp ./lib/folly/folly/File.cpp ./lib/folly/folly/Format.cpp ./lib/folly/folly/Conv.cpp ./lib/folly/folly/io/IOBuf.cpp ./lib/folly/folly/memory/detail/MallocImpl.cpp ./lib/folly/folly/ScopeGuard.cpp ./lib/folly/folly/hash/SpookyHashV2.cpp ./lib/folly/folly/io/IOBufQueue.cpp ./lib/folly/folly/lang/Assume.cpp ./lib/folly/folly/String.cpp ./lib/folly/folly/portability/SysUio.cpp ./lib/folly/folly/net/NetOps.cpp ./lib/folly/folly/synchronization/Hazptr.cpp ./lib/folly/folly/detail/ThreadLocalDetail.cpp ./lib/folly/folly/SharedMutex.cpp ./lib/folly/folly/concurrency/CacheLocality.cpp ./lib/folly/folly/detail/StaticSingletonManager.cpp ./lib/folly/folly/executors/ThreadPoolExecutor.cpp ./lib/folly/folly/executors/GlobalThreadPoolList.cpp ./lib/folly/folly/Demangle.cpp ./lib/folly/folly/synchronization/AsymmetricMemoryBarrier.cpp ./lib/folly/folly/io/async/Request.cpp ./lib/folly/folly/detail/MemoryIdler.cpp ./lib/folly/folly/detail/AtFork.cpp ./lib/folly/folly/Executor.cpp ./lib/folly/folly/lang/CString.cpp ./lib/folly/folly/portability/SysMembarrier.cpp ./lib/folly/folly/container/detail/F14Table.cpp ./lib/folly/folly/detail/UniqueInstance.cpp ./lib/folly/folly/executors/QueuedImmediateExecutor.cpp ./lib/folly/folly/memory/MallctlHelper.cpp ${DOUBLE_CONVERSION_SOURCES} ${GENERATED_CODE} ${SOURCE_CODE} ) set( LIBS ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} - gRPC::grpc++_reflection + ${_REFLECTION} ${AWSSDK_LINK_LIBRARIES} ${AMQPCPP_LIBRARIES} ${CRYPTOPP_LIBRARIES} ${LIBUV_LIBRARIES} ${Boost_LIBRARIES} OpenSSL::SSL glog::glog ) #SERVER add_executable( tunnelbroker ${GENERATED_CODE} ${SOURCE_CODE} ) target_link_libraries( tunnelbroker ${LIBS} ) install( TARGETS tunnelbroker RUNTIME DESTINATION bin/ ) # TEST if ($ENV{COMM_TEST_SERVICES} MATCHES 1) file(GLOB TEST_CODE "./test/*.cpp") list(FILTER SOURCE_CODE EXCLUDE REGEX "./src/server.cpp") enable_testing() find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIR}) add_executable( runTests ${SOURCE_CODE} ${TEST_CODE} ) target_link_libraries( runTests - + ${LIBS} gtest gtest_main ) add_test( NAME runTests COMMAND runTests ) endif() diff --git a/services/tunnelbroker/Dockerfile b/services/tunnelbroker/Dockerfile index 72fb01b4d..14def90e5 100644 --- a/services/tunnelbroker/Dockerfile +++ b/services/tunnelbroker/Dockerfile @@ -1,41 +1,44 @@ FROM commapp/services-base:1.0 ENV SHELL=/bin/bash RUN apt-get update && apt-get install -y \ libcurl4-openssl-dev \ libssl-dev \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* +ARG MAKE_JOBS=4 +ENV MAKEFLAGS="-j${MAKE_JOBS}" + RUN mkdir /transferred/scripts WORKDIR /transferred/scripts # Install SDKs COPY services/tunnelbroker/docker/install_folly.sh . RUN ./install_folly.sh COPY services/tunnelbroker/docker/install_aws_sdk.sh . RUN ./install_aws_sdk.sh COPY services/tunnelbroker/docker/install_amqp_cpp.sh . RUN ./install_amqp_cpp.sh COPY services/tunnelbroker/docker/install_cryptopp.sh . RUN ./install_cryptopp.sh COPY services/tunnelbroker/docker/install_libuv.sh . RUN ./install_libuv.sh ARG COMM_TEST_SERVICES ENV COMM_TEST_SERVICES=${COMM_TEST_SERVICES} WORKDIR /transferred COPY native/cpp/CommonCpp/grpc/protos/tunnelbroker.proto protos/tunnelbroker.proto COPY services/tunnelbroker/docker/ scripts/ COPY services/tunnelbroker/ . RUN scripts/build_server.sh CMD if [ "$COMM_TEST_SERVICES" -eq 1 ]; then scripts/run_tests.sh; else scripts/run_server.sh; fi diff --git a/services/tunnelbroker/build.sh b/services/tunnelbroker/build.sh deleted file mode 100755 index d1c8002c2..000000000 --- a/services/tunnelbroker/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -e - -NPROC=0 - -NPROC=$(nproc 2> /dev/null || echo 1) -if [[ $NPROC -eq 1 ]] -then - NPROC=$(sysctl -n hw.physicalcpu 2> /dev/null || echo 1) -fi - -echo "building the server (nproc=$NPROC)..." - -pushd cmake/build -cmake ../.. -make -j $NPROC - -popd - -echo "success - server built" diff --git a/services/tunnelbroker/docker/build_server.sh b/services/tunnelbroker/docker/build_server.sh index 6d71ce53c..8af982b7c 100755 --- a/services/tunnelbroker/docker/build_server.sh +++ b/services/tunnelbroker/docker/build_server.sh @@ -1,23 +1,23 @@ #!/bin/bash set -e # folly hack - https://github.com/facebook/folly/pull/1231 sed -i 's/#if __has_include()/#if __has_include()/g' /usr/lib/folly/folly/detail/Demangle.h rm -rf lib mkdir lib pushd lib ln -s /usr/lib/folly ln -s /usr/lib/glog ln -s /usr/lib/double-conversion popd # lib -rm -rf _generated -mkdir _generated - rm -rf cmake/build mkdir -p cmake/build -./generate.sh -./build.sh +echo "building the server (MAKEFLAGS=$MAKEFLAGS)..." +pushd cmake/build +cmake ../.. +make +popd # cmake/build diff --git a/services/tunnelbroker/generate.sh b/services/tunnelbroker/generate.sh deleted file mode 100755 index 64a710ecf..000000000 --- a/services/tunnelbroker/generate.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -e - -echo "generating files from protos..." - -protoc -I=./protos --cpp_out=_generated --grpc_out=_generated --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./protos/tunnelbroker.proto - -echo "success - code generated from protos" diff --git a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.h b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.h index 99650702e..87f0c025c 100644 --- a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.h +++ b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.h @@ -1,43 +1,43 @@ #pragma once -#include "../_generated/tunnelbroker.grpc.pb.h" -#include "../_generated/tunnelbroker.pb.h" +#include <_generated/tunnelbroker.grpc.pb.h> +#include <_generated/tunnelbroker.pb.h> #include #include #include namespace comm { namespace network { class TunnelBrokerServiceImpl final : public tunnelbroker::TunnelbrokerService::Service { public: TunnelBrokerServiceImpl(); virtual ~TunnelBrokerServiceImpl(); grpc::Status SessionSignature( grpc::ServerContext *context, const tunnelbroker::SessionSignatureRequest *request, tunnelbroker::SessionSignatureResponse *reply) override; grpc::Status NewSession( grpc::ServerContext *context, const tunnelbroker::NewSessionRequest *request, tunnelbroker::NewSessionResponse *reply) override; grpc::Status Send( grpc::ServerContext *context, const tunnelbroker::SendRequest *request, google::protobuf::Empty *reply) override; grpc::Status Get(grpc::ServerContext *context, const tunnelbroker::GetRequest *request, grpc::ServerWriter *stream) override; }; } // namespace network } // namespace comm