Skip to content
Snippets Groups Projects

C API integration layer

Merged Daniel Lyubomirov requested to merge cpp-integration-layer into master
10 unresolved threads

This MR includes the C API layer for starting/stopping the gRPC server.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
77 * "<host>:" (for example "localhost:"), in which case the port is not provided by the user but
78 * from the OS.
79 *
80 * When the gRPC server cannot bind, `err` will have code VEREIGN_ERR_GRPC_BIND_FAILED.
81 * Any other failures will set `err` with code VEREIGN_ERR_INTERNAL.
82 *
83 * **NOTE: On failure the `err` object must be freed with vereign_error_free method.**
84 *
85 * @param listen_address gRPC listen address, for example "localhost:".
86 * @param vereignHost Vereign restapi host.
87 * @param vereignPort Vereign restapi port - https, 443...
88 * @param err On failure err is initialized with the reason of the failure,
89 * otherwise err is set to nullptr.
90 * @returns vereign_service object if the gRPC is up and running, otherwise returns nullptr.
91 */
92 PUBLIC_API vereign_service* vereign_service_start(
  • 27 const char* vereign_host,
    28 const char* vereign_port,
    29 const char* public_key,
    30 vereign_error** err
    31 ) -> vereign_service* {
    32 if (err != nullptr) {
    33 *err = nullptr;
    34 }
    35
    36 std::unique_ptr<vereign::grpc::Server> serviceImpl;
    37
    38 try {
    39 serviceImpl = std::make_unique<vereign::grpc::Server>(
    40 listen_address,
    41 vereign_host,
    42 vereign_port,
    • I think here address must be defined to localhost and port must be auto selected?

    • The user can pass listen_address as "localhost:" in which case the port will be auto selected. I prefer not to hard code anything, since sometimes the user can decide to use other listen address in the local range, for example he can choose "127.0.0.11:" for an address with auto selected port.

    • Please register or sign in to reply
  • Gospodin Bodurov
  • 1 #include <vereign/vereign.h>
    2 #include <util/env.hh>
    3 #include <vereign/client_library/types.gen.pb.h>
    4 #include <vereign/client_library/passport_api.gen.grpc.pb.h>
    5 #include <vereign/core/scope_guard.hh>
    6 #include <grpcpp/create_channel.h>
    7
    8 #include <catch2/catch.hpp>
    9
    10 TEST_CASE("C API integration", "[.integration]") {
  • 1 cmake_minimum_required (VERSION 3.16.5)
    2
    3 if (WIN32)
    4 set(CMAKE_IGNORE_PATH "C:/Strawberry/c/bin")
  • 9 set(_build_command <SOURCE_DIR>/b2 install --prefix=<INSTALL_DIR> ${_boost_libs} link=static)
    10 set(_install_command "")
    11 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    12 set(_boost_toolset clang)
    13 set(_boost_cxx_flags "-std=c++${CMAKE_CXX_STANDARD} -fPIC")
    14 set(_boost_c_flags "-fPIC")
    15 string(REPLACE ";" "," _boost_libs "${_boost_libs}")
    16
    17 set(_configure_command <SOURCE_DIR>/bootstrap.sh --prefix=<INSTALL_DIR> --with-toolset=${_boost_toolset} --with-libraries=${_boost_libs})
    18 set(_build_command <SOURCE_DIR>/b2 toolset=${_boost_toolset} cxxflags=${_boost_cxx_flags} cflags=${_boost_c_flags})
    19 set(_install_command <SOURCE_DIR>/b2 install)
    20 endif()
    21
    22 ExternalProject_Add(boostlib
    23 PREFIX boost
    24 URL https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.zip
    • Probably this must be an ENV variable as well?

    • I can set a cmake cache var with default for this, if this is what you mean ?

      But the URL here represents the version of the dependency. It must be changed only by the developer, its like a version lock file. And if the the URL is changed then it is not guaranteed that whole ExternalProjectAdd will work. I mean the configuration, build, install commands is not guaranteed to work with other version of the library.

      Edited by Daniel Lyubomirov
    • Please register or sign in to reply
  • 3 set(_install_command
    4 ${CMAKE_COMMAND} -E copy crypto.lib <INSTALL_DIR>/lib/crypto.lib
    5 COMMAND ${CMAKE_COMMAND} -E copy ssl.lib <INSTALL_DIR>/lib/ssl.lib
    6 COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/src/include <INSTALL_DIR>/include
    7 )
    8 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    9 set(_install_command
    10 ${CMAKE_COMMAND} -E copy libcrypto.a <INSTALL_DIR>/lib/libcrypto.a
    11 COMMAND ${CMAKE_COMMAND} -E copy libssl.a <INSTALL_DIR>/lib/libssl.a
    12 COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/src/include <INSTALL_DIR>/include
    13 )
    14 endif()
    15
    16 ExternalProject_Add(boringssllib
    17 PREFIX boringssl
    18 GIT_REPOSITORY git@github.com:google/boringssl.git
  • 1
    2 ExternalProject_Add(fmtlib
    3 PREFIX fmt
    4 GIT_REPOSITORY git@github.com:fmtlib/fmt.git
  • cpp/README.md 0 → 100644
    68
    69 After the service is started you can use your favorite language generated gRPC client to communicate
    70 with the service.
    71
    72 Use the `vereign_service_selected_port` function to get the listen port of the gRPC server.
    73
    74 When you are finished with the service, for example upon shutdown of the application, one must use
    75 the `vereign_service_shutdown` API. It will shutdown the service and free any acquired resources.
    76 Afterwards the returned `vereign_service` pointer from the start call is invalid and must not be used anymore.
    77
    78 For more detailed info check the source code documentation in the header
    79 [include/vereign/vereign.h](cpp/include/vereign/vereign.h).
    80 You can also look at C++ usage example in the C API integration test
    81 [tests/integration/integration_test.cc](cpp/tests/integration/integration_test.cc).
    82
    83 The gRPC APIs are located here [https://code.vereign.com/code/vcl-proto/-/tree/master/proto%2Fvereign%2Fclient_library](https://code.vereign.com/code/vcl-proto/-/tree/master/proto%2Fvereign%2Fclient_library).
  • cpp/README.md 0 → 100644
    1 # Vereign C++ Client Library
    2
    3 ## Overview
    4
    5 TODO
  • 10 10 option(VEREIGN_USE_LLD "Use the lld linker" OFF)
    11 11 option(VEREIGN_USE_PRECOMPILED_HEADERS "Use precompiled headers" OFF)
    12 12 option(VEREIGN_USE_TIME_TRACE "Use compilation profiler" OFF)
    13 option(VEREIGN_ENABLE_BENCHMARKING "Enable tests benchmarks" ON)
  • added reviewed label

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • mentioned in commit 3815637b

  • Please register or sign in to reply
    Loading