You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
5.0 KiB

5 years ago
cmake_minimum_required(VERSION 3.12)
find_program(CCACHE_FOUND ccache)
5 years ago
if (CCACHE_FOUND)
5 years ago
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
5 years ago
endif (CCACHE_FOUND)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx20.cmake"
5 years ago
CACHE
FILEPATH
"Default toolchain"
)
cmake_policy(SET CMP0048 NEW)
Connection layers mechanism; Websocket layer (#201) * feature: layers of connections * feature: upgrade layers of connection * fix: tests * feature: test of layers upgrade * refactor: enable disabled upgrader tests * feature: sha-1 hash * feature: websocket layer * fix: read-buffer extending * feature: decide layers for connection upgrade by provided multiaddress * refactor: combine regular and websocket echo-client/-server to single one * refactor: rename peer::Protocol to peer::ProtocolName * refactor: implement addressToBytes, as replacement addressToHex * refactor: mark addressToHex as deprecated * feature: extend ConversionError * fix: multiaddress manipulations * feature: dummy protocols for tests * fix: tests of converters * fix: collision in DI * refactor: update outcome macros for tests * fix: connection upgrader in part of layers * fix: ws read-writer in case big data fragmented by frames * experiment: add delay of sending jumbo message, to give a chance for Id-protocol to end his work * experiment: log difference sent and received data for analyse * feature: control frames (ping/pong/close) * fix: sending huge portions of data * fix: echo sessions * feature: optional hex dump in dumpBin * fix: echo client * update: hunter package manager * fix: hardcoded request and response in http-to-ws upgraded * fix: add ws version header * fix: reduce length of ws-key header * fix: make ws-header check case-insensitive * fix: use locale independent predicate for ci-compare * fix: use boost endian conversion instead endian macros Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
2 years ago
cmake_policy(SET CMP0135 NEW)
include("cmake/Hunter/init.cmake")
project(libp2p VERSION 0.1.17 LANGUAGES C CXX)
5 years ago
5 years ago
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5 years ago
option(TESTING "Build tests" ON)
option(EXAMPLES "Build examples" ON)
5 years ago
option(CLANG_FORMAT "Enable clang-format target" ON)
option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
option(COVERAGE "Enable generation of coverage info" OFF)
# sanitizers will be enabled only for libp2p, and will be disabled for dependencies
option(ASAN "Enable address sanitizer" OFF)
option(LSAN "Enable leak sanitizer" OFF)
option(MSAN "Enable memory sanitizer" OFF)
option(TSAN "Enable thread sanitizer" OFF)
option(UBSAN "Enable UB sanitizer" OFF)
option(EXPOSE_MOCKS "Make mocks header files visible for child projects" ON)
option(METRICS_ENABLED "Enable libp2p metrics" OFF)
5 years ago
Cross compiling fixes and improvements (#59) * CMake: Expose CMake options to includes This change shuffles the order of several CMake steps to expose CMake options to included files. By defining options before inclusion, included files are able to access the input provided by the build system. * CMake: Exclude test dependencies when building tests * CMake: Allow build system to provide protobuf compiler When building without Hunter, it is desirable to pass the path to protoc and the protobuf include directory from the build system. Allow these variables to be overridden. Fixes the error: | CMake Error at cmake/functions.cmake:52 (message): | Protobuf_PROTOC_EXECUTABLE is empty | Call Stack (most recent call first): | cmake/functions.cmake:96 (compile_proto_to_cpp) | src/crypto/protobuf/CMakeLists.txt:6 (add_proto_library) * Fix build error due to missing include Error was: | literals.cpp: In function 'libp2p::common::Hash256 libp2p::common::operator""_hash256(const char*, size_t)': | literals.cpp:17:36: error: no matching function for call to 'min(size_t&, long unsigned int)' | 17 | std::copy_n(c, std::min(s, 32ul), hash.rbegin()); | | ^ * Fix build error due to mismatched types Error was: | literals.cpp: In function 'libp2p::common::Hash256 libp2p::common::operator""_hash256(const char*, size_t)': | literals.cpp:19:36: error: no matching function for call to 'min(size_t&, long unsigned int)' | 19 | std::copy_n(c, std::min(s, 32ul), hash.rbegin()); | | ^ * Fix compiler warning due to sign comparison When compiling with -Werror, this causes the build to fail. Warning was: | yamux_frame.cpp:103:28: error: comparison of integers of different signs: 'gsl::span::index_type' (aka 'int') and 'const uint32_t' (aka 'const unsigned int') [-Werror,-Wsign-compare] | if (frame_bytes.size() < YamuxFrame::kHeaderLength) { | ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
4 years ago
include(cmake/print.cmake)
print("C flags: ${CMAKE_C_FLAGS}")
print("CXX flags: ${CMAKE_CXX_FLAGS}")
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
# the property is out of "if TESTING" scope due to addtest func is out too
set_property(GLOBAL PROPERTY TEST_TARGETS)
Cross compiling fixes and improvements (#59) * CMake: Expose CMake options to includes This change shuffles the order of several CMake steps to expose CMake options to included files. By defining options before inclusion, included files are able to access the input provided by the build system. * CMake: Exclude test dependencies when building tests * CMake: Allow build system to provide protobuf compiler When building without Hunter, it is desirable to pass the path to protoc and the protobuf include directory from the build system. Allow these variables to be overridden. Fixes the error: | CMake Error at cmake/functions.cmake:52 (message): | Protobuf_PROTOC_EXECUTABLE is empty | Call Stack (most recent call first): | cmake/functions.cmake:96 (compile_proto_to_cpp) | src/crypto/protobuf/CMakeLists.txt:6 (add_proto_library) * Fix build error due to missing include Error was: | literals.cpp: In function 'libp2p::common::Hash256 libp2p::common::operator""_hash256(const char*, size_t)': | literals.cpp:17:36: error: no matching function for call to 'min(size_t&, long unsigned int)' | 17 | std::copy_n(c, std::min(s, 32ul), hash.rbegin()); | | ^ * Fix build error due to mismatched types Error was: | literals.cpp: In function 'libp2p::common::Hash256 libp2p::common::operator""_hash256(const char*, size_t)': | literals.cpp:19:36: error: no matching function for call to 'min(size_t&, long unsigned int)' | 19 | std::copy_n(c, std::min(s, 32ul), hash.rbegin()); | | ^ * Fix compiler warning due to sign comparison When compiling with -Werror, this causes the build to fail. Warning was: | yamux_frame.cpp:103:28: error: comparison of integers of different signs: 'gsl::span::index_type' (aka 'int') and 'const uint32_t' (aka 'const unsigned int') [-Werror,-Wsign-compare] | if (frame_bytes.size() < YamuxFrame::kHeaderLength) { | ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
4 years ago
include(CheckCXXCompilerFlag)
include(cmake/install.cmake)
include(cmake/libp2p_add_library.cmake)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)
if (METRICS_ENABLED)
add_compile_definitions("LIBP2P_METRICS_ENABLED")
endif ()
5 years ago
## setup compilation flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# enable those flags
add_flag(-Wall)
add_flag(-Wextra)
add_flag(-Woverloaded-virtual) # warn if you overload (not override) a virtual function
add_flag(-Wformat=2) # warn on security issues around functions that format output (ie printf)
add_flag(-Wmisleading-indentation) # (only in GCC >= 6.0) warn if indentation implies blocks where blocks do not exist
add_flag(-Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(-Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(-Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(-Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(-Wsign-compare)
5 years ago
add_flag(-Wtype-limits) # size_t - size_t >= 0 -> always true
5 years ago
Feature/reentrancy (#111) * gossip confirmance fixes #1 * gossip: bugfixes * gossip: more fixes * gossip: build related minor changes * gossip: one more fix * gossip: flush hello message asap * experiment with noise protocol * made injector creation fns inline to prevent multiple definitions * gossip restructured, interop issues fixed * Noise::write now reports the correct amount of bytes Signed-off-by: Igor Egorov <igor@soramitsu.co.jp> * refactoring: move prev implementation of Kademlia to other namespace Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: kademlia dependency injection Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: improve random generator Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: getting listened multiaddress in tcp listener Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: reduce logging in secio Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * draft: new implementation of kademlia Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * draft: processing with kademlia Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * draft: continue processing with kademlia Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * draft: continue Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * draft: kademlia Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: validation Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: DSA Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: CIDv1 encoding refactoring: replace deprecated sha256 function by hasher Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: multiaddress operations Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: make PeerId comparable to using in std::set Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * refactoring: addr repo Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: Go-implementation compatibility Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: rendezvous chat as example of Kademlia using Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: unit-test for kademlia parts Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: StorageBackend interface fix: ContentValue Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * wipe: remove previous implementation of Kademlia Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: cmake files Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> cmake Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: some warnings Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: resolve TODOes, comments, format Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: clang-tidy issues Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: clang-tidy issues Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: clang-tidy issues Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: using timeout for make new stream feature: smart using of peer routing Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: kademlia message parsing Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * refactoring: optimize executors' working Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * refactoring: optimize start of rendezvous chat Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * refactoring: headers including Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * refactoring: remaining request executors; naming Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * feature: add handle and timeout as argument of Host::connect Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * fix: some log messages Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> * injectors temp fix * gossip: uncommented writing bytes checking * removed redundant std::hash definition * Hack yamux to allow weighty messages processing Signed-off-by: Igor Egorov <igor@soramitsu.co.jp> * fix vtable * fixes in DI injectors * yamux test corrected according to curent window update policy * added buffering primitives * defer* functions in Reader/Writer interfaces and Yamux redesign pt.1 * scheduler fix regarding move assignment + cancel * write queue interface change * read buffer fix regarding subspan * some diagnostic logging * tcp connection fixes related to closing behavior * yamux bugfixes * yamux tests regression WIP * build fix * . * . * bugfixes * fixes * . * . * suppressed most verbose logging in yamux and multiselect * yamux stream adjustWindowSize adjusted * fixes regarding std::move of r/w callbacks (against possible ptrs invalidation) * test cases with jumbo messages transfer added for yamux on noise/tls/plaintext * bugfixes related to yamux window sizes, overflow, and acknowledgements * echo protocol and examples support very large msgs * changes in tests * all muxers acceptance test recovered * all muxers acceptance test: fixed issue with mock lifetime * CI fixes * yamux refactorings helped to avoid memory issues caused by reentrant callbacks * build fix for mac * another yamux fix to avoid memory issues caused by reentrant callbacks * gossip: hotfix related to unbanning peers * minor fixes reflecting review feedback * temp loggers workaround * Feature/multiselect upd (#121) * multiselect revised, WIP * multiselect: simple outbound stream negotiate * multiselect numerous fixes * multiselect: instances and reuse * multiselect: fixes * multiselect: removed old implementation * multiselect: interop with go impl fixes * multiselect: bugfixes * multiselect: ProtocolMuxer interface abstracts simple outbound stream negotiation * multiselect: cleanups and logging * trigger CI * temporarily disabled tests that required synchronous reaction of multiselect * just removed unused lines * reverted back ci.yml Co-authored-by: Igor Egorov <igor@soramitsu.co.jp> Co-authored-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com> Co-authored-by: turuslan <turuslan.devbox@gmail.com>
4 years ago
# suppress warnings if a certain compiler version doesn't know some of the warnings above
add_flag(-Wno-unknown-warning-option)
5 years ago
# disable those flags
add_flag(-Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
add_flag(-Wno-unused-parameter) # prints too many useless warnings
add_flag(-Wno-format-nonliteral) # prints way too many warnings from spdlog
add_flag(-Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore
# promote to errors
add_flag(-Werror-unused-lambda-capture) # error if lambda capture is unused
add_flag(-Werror-return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(-Werror-non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(-Werror-sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(-Werror-reorder) # field '$1' will be initialized after field '$2'
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
5 years ago
endif ()
5 years ago
5 years ago
if (CLANG_TIDY)
5 years ago
include(cmake/clang-tidy.cmake)
5 years ago
endif ()
if (CLANG_FORMAT)
set(RECOMMENDED_CLANG_FORMAT_VERSION 15)
5 years ago
include(cmake/clang-format.cmake)
endif ()
5 years ago
5 years ago
include_directories(
SYSTEM
5 years ago
# project includes
${PROJECT_SOURCE_DIR}/include
5 years ago
)
add_subdirectory(src)
if(EXAMPLES)
add_subdirectory(example)
endif()
if(TESTING OR COVERAGE)
enable_testing()
add_subdirectory(test)
endif()
if (COVERAGE)
include(cmake/coverage.cmake)
endif ()
include(CMakePackageConfigHelpers)
set(CONFIG_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR}/libp2p)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/libp2pConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
)