Giter Site home page Giter Site logo

cpp-libp2p's Introduction

CPP-Libp2p

Fully compatible C++17 implementation of libp2p library

Libp2p is a modular networking stack described in spec

Dependencies

All dependencies are managed using Hunter. It uses cmake to download required libraries and does not require downloading and installing packages manually. Target C++ compilers are:

  • GCC 7.4
  • Clang 6.0.1
  • AppleClang 11.0

Supported protocols

Development

Clone

To clone repository execute

git clone https://github.com/libp2p/libp2p-cpp.git

Build cpp-libp2p

First build will likely take long time. However, you can cache binaries to hunter-binary-cache or even download binaries from the cache in case someone has already compiled project with the same compiler. To do so you need to set up two environment variables:

GITHUB_HUNTER_USERNAME=<github account name>
GITHUB_HUNTER_TOKEN=<github token>

To generate github token follow the instructions. Make sure read:packages and write:packages permissions are granted (step 7 in instructions).

This project can be built with

mkdir build && cd build
cmake -DCLANG_TIDY=ON ..
make -j

It is suggested to build project with clang-tidy checks, however if you wish to omit clang-tidy step, you can use cmake .. instead.

Tests can be run with:

cd build
ctest

CodeStyle

We follow CppCoreGuidelines.

Please use provided .clang-format file to autoformat the code.

Examples

Please explore example section to read examples of how to use the library

Adding cpp-libp2p to the project

cpp-libp2p can be integrated using hunter. Adding hunter support to your project is really simple and require you only to add some cmake. Check hunter example project for details.

After hunter is integrated adding cpp-libp2p can be done by adding these lines to cmake:

hunter_add_package(libp2p)
find_package(libp2p REQUIRED)

To set which version of cpp-libp2p to use it is required to add these lines to Hunter/config.cmake file:

hunter_config(libp2p
    URL https://github.com/libp2p/cpp-libp2p/archive/dad84a03a9651c7c2bb8a8f17d0e5ea67bd10b4f.zip
    SHA1 860742c6e3e9736d68b392513d795e09572780aa
    )

Where URL is the link to archive of certain commit in cpp-libp2p repo and SHA1 is the checksum of this archive. By simply updating URL and SHA1 it is possible to change the version of cpp-libp2p in another project.

Example of adding cpp-libp2p to other project can be found here and here

Notable users

Maintenance

Maintainers: @Warchant, @kamilsa, @harrm, @masterjedy, @igor-egorov, @art-gor

Tickets: Can be opened in Github Issues.

cpp-libp2p's People

Contributors

akvinikym avatar alexey-n-chernyshov avatar andregri avatar art-gor avatar asmie avatar bulatsaif avatar dependabot[bot] avatar dhuseby avatar eigendude avatar florianfranzen avatar garorobe avatar harrm avatar iceseer avatar kamilsa avatar libp2p-mgmt-read-write[bot] avatar marcopolo avatar masterjedy avatar ortyomka avatar sergkaprovich avatar turuslan avatar vvarma avatar warchant avatar web-flow avatar woodsmc avatar xdimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-libp2p's Issues

Adding new maintainers

What should be the process of adding new maintainers? At the moment I need to add @turuslan. In future I might need some more members like some DevOps guys

Way to compile for embedded systems

Will there be any support for microcontrollers like esp32 in the future? I'm starting to build some peer to peer capable esp32 nodes though its hard for me as a novice developer to continue, the only working part so far using other libraries is the request and response from a stun server with my public ip and port.

Can't add libp2p to project using hunter( libp2p versions available: [] [hunter ** INTERNAL **] Unexpected empty string)

  • In manjaro Linux kernel 4.19.187-1-MANJARO
  • cmake 3.20.1
  • gcc 10.2

download HunterGate.cmake,

in main CMakeLists.txt

include("cmake/HunterGate.cmake")

HunterGate(
    URL "https://github.com/cpp-pm/hunter/archive/v0.23.297.tar.gz"
    SHA1 "3319fe6a3b08090df7df98dee75134d68e2ef5a3"
)
    
project(sync_db_cpp LANGUAGES CXX)
hunter_add_package(libp2p)
find_package(libp2p REQUIRED)

then I try to make project using command

cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON -DCMAKE_BUILD_TYPE=Release

-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HUNTER_ROOT set using HOME environment variable
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HUNTER_ROOT: /home/dev/.hunter
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Settings (initialize):
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HunterGate done (NO)
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Cache init (YES)
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Single-configuration generator
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Using default cache server
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] List of cache servers:
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] * https://github.com/cpp-pm/hunter-cache
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Settings (finalize):
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HunterGate done (NO)
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Cache init (YES)
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] Variables from HunterGate:
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HUNTER_GATE_ROOT: /home/dev/.hunter
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HUNTER_GATE_VERSION: 0.23.297
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] HUNTER_GATE_SHA1: 3319fe6a3b08090df7df98dee75134d68e2ef5a3
-- [hunter] Calculating Toolchain-SHA1
-- [hunter *** DEBUG *** 2021-04-25T17:05:02] [/home/dev/Projects/sync_db_cpp/_builds/_3rdParty/Hunter/toolchain] > "/usr/bin/cmake" "-DTOOLCHAIN_INFO_FILE=/home/dev/Projects/sync_db_cpp/_builds/_3rdParty/Hunter/toolchain/toolchain.info.NOLF" "-DHUNTER_SELF=/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked" "-GUnix Makefiles" "-H/home/dev/Projects/sync_db_cpp/_builds/_3rdParty/Hunter/toolchain" "-B/home/dev/Projects/sync_db_cpp/_builds/_3rdParty/Hunter/toolchain/_builds" "-DCMAKE_MAKE_PROGRAM=/usr/bin/make" "-DCMAKE_RELEASE_POSTFIX=" "-DCMAKE_DEBUG_POSTFIX=d"
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev/Projects/sync_db_cpp/_builds/_3rdParty/Hunter/toolchain/_builds
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] Already exists: /home/dev/.hunter/_Base/3319fe6/020aca2/toolchain.info
-- [hunter] Calculating Config-SHA1
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] Cache data is up-to-date
-- [hunter] HUNTER_ROOT: /home/dev/.hunter
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] HUNTER_TOOLCHAIN_ID_PATH: /home/dev/.hunter/_Base/3319fe6/020aca2
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] HUNTER_CONFIGURATION_TYPES: Release;Debug
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] HUNTER_BUILD_SHARED_LIBS:
-- [hunter] [ Hunter-ID: 3319fe6 | Toolchain-ID: 020aca2 | Config-ID: 65f8faa ]
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] File not found (injected package): /home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/projects/libp2p/hunter.cmake
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] Injected package 'libp2p'
-- [hunter *** DEBUG *** 2021-04-25T17:05:03] libp2p versions available: []

[hunter ** INTERNAL **] Unexpected empty string
[hunter ** INTERNAL **] [Directory:/home/dev/Projects/sync_db_cpp]

------------------------------ ERROR -----------------------------
https://hunter.readthedocs.io/en/latest/reference/errors/error.internal.html

CMake Error at /home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_error_page.cmake:12 (message):
Call Stack (most recent call first):
/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_internal_error.cmake:13 (hunter_error_page)
/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_assert_not_empty_string.cmake:9 (hunter_internal_error)
/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_get_package_sha1.cmake:26 (hunter_assert_not_empty_string)
/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_download.cmake:83 (hunter_get_package_sha1)
/home/dev/.hunter/_Base/Download/Hunter/0.23.297/3319fe6/Unpacked/cmake/modules/hunter_add_package.cmake:53 (hunter_download)
CMakeLists.txt:15 (hunter_add_package)

Hunter build errors from package soralog

I get the follow build error while trying to configure the project with CMake

/.hunter/_Base/64a1180/2f0b28a/8459457/Build/soralog/Source/src/logging_system.cpp: In member function ‘void soralog::LoggingSystem::setParentOfGroup(const std::shared_ptr<soralog::Group>&, const std::shared_ptr<soralog::Group>&)’:
/home/ashley/.hunter/_Base/64a1180/2f0b28a/8459457/Build/soralog/Source/src/logging_system.cpp:173:10: error: ‘function’ is not a member of ‘std’
  173 |     std::function<int(const std::shared_ptr<const Group> &)> fn =

Think its is the following issue xDimon/soralog#4
Maybe set hunter dependency to a fixed versions if they are not already or use a logging library that more stable (ie spdlog)

NAT Traversal

Does this library have any tools for NAT traversal?
There is definite lack of documentation and examples

inconsistent use of BOOST_ASIO_NO_DEPRECATED is unnecessary and dangerous

The usage of BOOST_ASIO_NO_DEPRECATED seems to change not only what symbols are available, but the implementation of some functions and maybe even the layout of some classes. As far as I can tell, ASIO is designed to be built either with this defined everywhere, or nowhere. Trying to use cpp-libp2p in a project that is already using Boost ASIO is thereby fraught with peril, as I'm getting inconsistent behaviors due to some symbols being exported from and merged from libp2p files, leading to segmentation faults.

FWIW, my code would work fine with either BOOST_ASIO_NO_DEPRECATED or not, but the core issue is that there are two files in libp2p that have a #define BOOST_ASIO_NO_DEPRECATED but a number of other files that rely on it not being defined. It is my understanding that you should not be defining this yourself in the header files: it should be done at the level of either Boost's build system or like, at most some custom build system that is taking over for Boost's build system, not defined in individual header files.

The code does seem to compile fine if you simply remove the two #defines without making any other changes (though I'm not using your build system to do it, so I'm not at all sure I'm covering all of your build possibilities).

#define BOOST_ASIO_NO_DEPRECATED

#define BOOST_ASIO_NO_DEPRECATED

Question: autoNAT implementation

Hello i got a bit confused because libp2p/implementations claims that autonat is implemented for cpp. But your readme doesn't mention it and i don't see any references to it in the code.
So is this because i am missing something, or is this feature being worked on by anyone?
Regardless thank you for your time.

Avoid reentrancy in all async calls

Avoid reentrancy in all async calls.

Dependent stuff to be resolved:

  1. Yamux refactorings;
  2. Scheduler availiable from objects to allow for deferring callbacks as well as timeouts;
  3. Low level interfaces are exteneded with defer calls functionality to simplify higher-level code

mismatched tags on IdentityManager prototype

struct IdentityManager {

In file included from cpp-libp2p/src/protocol/gossip/impl/gossip_core.cpp:13:
./cpp-libp2p/include/libp2p/peer/identity_manager.hpp:24:3: error: 'IdentityManager' defined as a struct here but previously declared as a class; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Werror,-Wmismatched-tags]
  struct IdentityManager {
  ^
./cpp-libp2p/include/libp2p/protocol/gossip/gossip.hpp:34:5: note: did you mean struct here?
    class IdentityManager;
    ^~~~~
    struct
1 error generated.

yamux stream destructor

Description

  • YamuxedConnection must hold weak_ptr<YamuxStream>
  • ~YamuxStream must cleanup resources immediately
  • remove YamuxedConnection cleanup timer

Motivation

close streams earlier to avoid CONNECTION_TOO_MANY_STREAMS

Current Implementation

streams are not closed until timer

Are you planning to do it yourself in a pull request ?

Maybe

License mismatch

LICENSE file should contain Apache 2, but there is GPL 3 instead

unable to build

it tries to upload something to the cache repo

Error:
  Repository not found 'https://github.com/soramitsu/hunter-binary-cache' or user 'shi-yan' has no access to it
Traceback (most recent call last):
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 594, in <module>
    cache.upload_raw(github)
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 292, in upload_raw
    i.upload_raw(github)
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 256, in upload_raw
    github.upload_raw_file(raw)
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 227, in upload_raw_file
    release_id, upload_url = self.get_release_by_tag(tagname)
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 55, in func_out
    raise err
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 49, in func_out
    return func_in(*args, **kwargs)
  File "/root/.hunter/_Base/Download/Hunter/0.23.216/a492a18/Unpacked/scripts/upload-cache-to-github.py", line 118, in get_release_by_tag
    format(repo_name, self.username)
__main__.Error: Repository not found 'https://github.com/soramitsu/hunter-binary-cache' or user 'shi-yan' has no access to it

[hunter ** INTERNAL **] Upload script failed

I don't have write access to https://github.com/soramitsu/hunter-binary-cache

migrate this implementation to the libp2p org?

We discussed this elsewhere, but the conversation died down and I want to resurface.

The work done here is brilliant, and a lot more folks could benefit from it – if they knew it existed! Transferring this repo to the libp2p org would help tremendously with discoverability.

Of course, all committers here would preserve their repo rights, and would officially join the libp2p organisation on GitHub -- with a cool new badge to display on their profiles.

Can we make it happen soon? 😇 The proposed repo name is libp2p/cpp-libp2p.

Can it be compiled on windows?

Hello!
I follow the steps of readme to compile the project.The following sentence will not continue.
Senetence
GTEST_ROOT: C:///Install (ver.: 1.8.0-hunter-p11)
What should I do?

Thanks!

uninitialized local variables - warning as error build issue

Hi Folks, while building I encountered a number of "warnings treated as errors" during the build, this prevented the build from completing. These were uninitialized local variables in:

  • crypto_provider_impl.cpp
  • rsa_provider_impl.cpp
  • kad_impl.cpp

I've a fix for this I can submit.

got failed to do cmake configuration -- Ubuntu-20.04 and gcc-9.4

user@ubuntu2004s01:~/works/cpp-libp2p/cpp-libp2p $ cmake -B build_x64 -DCMAKE_INSTALL_PREFIX=install_x64 -DTESTING=OFF -DEXAMPLES=OFF -DCLANG_FORMAT=OFF -DEXPOSE_MOCKS=OFF

CMake Error at CMakeLists.txt:17 (cmake_policy):
Policy "CMP0135" is not known to this version of CMake.

Binary cache uploading is DISABLED.
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [libp2p] C flags:
-- [libp2p] CXX flags:
-- [libp2p] Using CMAKE_TOOLCHAIN_FILE=/home/user/works/cpp-libp2p/cpp-libp2p/cmake/toolchain/cxx20.cmake
-- [hunter] Calculating Toolchain-SHA1
-- [hunter] Calculating Config-SHA1
-- [hunter] HUNTER_ROOT: /home/user/.hunter
-- [hunter] [ Hunter-ID: 4fb3b9a | Toolchain-ID: 50524fc | Config-ID: c8a28f0 ]
-- [hunter] BOOST_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.83.0)
-- [hunter] BOOST_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.83.0)
-- [hunter] BOOST_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.83.0)
-- [hunter] BOOST_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.83.0)
-- Boost version: 1.83.0
-- Found the following Boost libraries:
-- random
-- filesystem
-- program_options
-- [hunter] MICROSOFT.GSL_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 2.0.0-p0)
-- [hunter] OPENSSL_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.1.1t)
-- Found OpenSSL: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install/lib/libssl.a;/home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install/lib/libcrypto.a;dl (found version "1.1.1t")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- [hunter] PROTOBUF_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 3.11.2-p0)
-- Found ZLIB: ZLIB::zlib
-- [hunter] C-ARES_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.14.0-p0)
-- [hunter] FMT_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 10.1.1)
-- [hunter] YAML-CPP_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 0.6.2-0f9a586-p1)
-- [hunter] SORALOG_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 0.2.1)
-- [hunter] TSL_HAT_TRIE_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.0.0)
-- [hunter] BOOST.DI_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 1.1.0)
-- [hunter] SQLITEMODERNCPP_ROOT: /home/user/.hunter/Base/4fb3b9a/50524fc/c8a28f0/Install (ver.: 0.0.0)
-- Performing Test FLAG
-Wall
-- Performing Test FLAG
-Wall - Success
-- Performing Test FLAG
-Wextra
-- Performing Test FLAG
-Wextra - Success
-- Performing Test FLAG
-Woverloaded-virtual
-- Performing Test FLAG
-Woverloaded-virtual - Success
-- Performing Test FLAG
-Wformat=2
-- Performing Test FLAG
-Wformat=2 - Success
-- Performing Test FLAG
-Wmisleading-indentation
-- Performing Test FLAG
-Wmisleading-indentation - Success
-- Performing Test FLAG
-Wduplicated-cond
-- Performing Test FLAG
-Wduplicated-cond - Success
-- Performing Test FLAG
-Wduplicated-branches
-- Performing Test FLAG
-Wduplicated-branches - Success
-- Performing Test FLAG
-Wnull-dereference
-- Performing Test FLAG
-Wnull-dereference - Success
-- Performing Test FLAG_-Wdouble-promotion
-- Performing Test FLAG_-Wdouble-promotion - Success
-- Performing Test FLAG_-Wsign-compare
-- Performing Test FLAG_-Wsign-compare - Success
-- Performing Test FLAG_-Wtype-limits
-- Performing Test FLAG_-Wtype-limits - Success
-- Performing Test FLAG_-Wno-unknown-warning-option
-- Performing Test FLAG_-Wno-unknown-warning-option - Failed
-- Performing Test FLAG_-Wno-unused-command-line-argument
-- Performing Test FLAG_-Wno-unused-command-line-argument - Failed
-- Performing Test FLAG_-Wno-unused-parameter
-- Performing Test FLAG_-Wno-unused-parameter - Success
-- Performing Test FLAG_-Wno-format-nonliteral
-- Performing Test FLAG_-Wno-format-nonliteral - Success
-- Performing Test FLAG_-Wno-gnu-zero-variadic-macro-arguments
-- Performing Test FLAG_-Wno-gnu-zero-variadic-macro-arguments - Failed
-- Performing Test FLAG_-Werror-unused-lambda-capture
-- Performing Test FLAG_-Werror-unused-lambda-capture - Failed
-- Performing Test FLAG_-Werror-return-type
-- Performing Test FLAG_-Werror-return-type - Failed
-- Performing Test FLAG_-Werror-non-virtual-dtor
-- Performing Test FLAG_-Werror-non-virtual-dtor - Failed
-- Performing Test FLAG_-Werror-sign-compare
-- Performing Test FLAG_-Werror-sign-compare - Failed
-- Performing Test FLAG_-Werror-reorder
-- Performing Test FLAG_-Werror-reorder - Failed
-- Configuring incomplete, errors occurred!
See also "/home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeOutput.log".
See also "/home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeError.log".

=====================================================================================================

user@ubuntu2004s01:~/works/cpp-libp2p/cpp-libp2p $ more build_x64/CMakeFiles/CMakeError.log

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_a1fe9/fast && /usr/bin/make -f CMakeFiles/cmTC_a1fe9.dir/build.make CMakeFiles/cmTC_a1fe9.dir/build
make[1]: Entering directory '/home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a1fe9.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_a1fe9.dir/src.c.o -c /home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_a1fe9
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a1fe9.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_a1fe9.dir/src.c.o -o cmTC_a1fe9
/usr/bin/ld: CMakeFiles/cmTC_a1fe9.dir/src.c.o: in function main': src.c:(.text+0x46): undefined reference to pthread_create'
/usr/bin/ld: src.c:(.text+0x52): undefined reference to pthread_detach' /usr/bin/ld: src.c:(.text+0x63): undefined reference to pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_a1fe9.dir/build.make:87: cmTC_a1fe9] Error 1
make[1]: Leaving directory '/home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_a1fe9/fast] Error 2

Source file was:
#include <pthread.h>

void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_37ba9/fast && /usr/bin/make -f CMakeFiles/cmTC_37ba9.dir/build.make CMakeFiles/cmTC_37ba9.dir/build
make[1]: Entering directory '/home/user/works/cpp-libp2p/cpp-libp2p/build_x64/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_37ba9.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_37ba9.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_37ba9
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_37ba9.dir/link.txt --verbose=1

Example

Are examples developed of chat applications like the go-libp2p / chat-with-rendezvous? I searched but was not able to found it. Thanks
Megan

Too hard too build this project.

The cmake Hunter takes long time to setup dependency packages, and finally failed. I even can't find what it do every time it pause to wait something. And I can't understand why it failed, and I don't know what to do to help it to finish: Can I help it to download or compile or install package? I don't know.

Why don't choose a more traditional way to setup dependency packages, for example to use a shell or python script?
The cmake Hunter seems making things more complex than it need to be.

Does an open source project even like Linux Kernel harder to build than this?

Multiselect integration test

Testing of #111 uncovers that protocol negotiation happens more often than in the master branch. Moreover, that negotiation often fails due to unexpected messages which may indicate the error-prone messages flow and order.

The issue is to create some integration test for the multiselect protocol to reveal such errors and verify messages order correctness without any dependency on underlying implementation (either callbacks or tasks scheduling - #111 addresses it).

Log example of multiselect issues when #111 gets employed:

[2021-03-15 15:29:45.873680000][th:584649][info] multiselect got a unexpected request-response combination - sending 'ls'
[2021-03-15 15:29:45.873701000][th:584649][warning] listener_mgr can not negotiate protocols, other side has violated a protocol and sent an unexpected message
[2021-03-15 15:29:45.984183000][th:584649][info] multiselect got a unexpected request-response combination - sending 'ls'
[2021-03-15 15:29:45.984203000][th:584649][warning] listener_mgr can not negotiate protocols, other side has violated a protocol and sent an unexpected message

Yamux newStream does not work

There are two versions for new stream creation in cpp-libp2p yamux - sync and async. Async version is not working - we always will have an error "closed by remote peer" when we use it. The actual problem is that the stream is created in both cases, but in the case of the async version, it never returned to the user's callback. The second problem is that the stream creation in both cases is done via the same method under the hood, but in the case of the async approach, we have additional messages on the line, which look unnecessary to be sent over. Thus, the flow seems broken in the case of the async approach of streams creation which is generally preferred.

TLS support

Am I correct in understanding that support for TLS as a security protocol is not present in the C++ flavour and needs to be implemented? Is there a known (unofficial) module in existence that could be used for this?

Remove ambiguous argument

read, readSome, write, writeSome accept both span { ptr, size } and size.
size argument is ambiguos and must be removed.

Not able to see other machine's messages in gossip chat example

hey guys! glad to be here, I'm really having trouble as I don't see any tutorials and I cannot see the messages in GOSSIP chat example between 2 different machines.
Machine A:

./example/03-gossip/gossip_chat_example -p 4444
I am /ip4/127.0.0.1/tcp/4444/p2p/12D3KooWG1PJZvLidoYh1AfvZ9aytAaSmgHSW58xrsaEm9abSJgq

Machine B:

./gossip_chat_example -p 4444 -r /ip4/PUBLIC_IP/tcp/4444/p2p/12D3KooWG1PJZvLidoYh1AfvZ9aytAaSmgHSW58xrsaEm9abSJgq
I am /ip4/127.0.0.1/tcp/4444/p2p/12D3KooWNpH8bakYn6uPn4veXp8QFMGFn6sPiaZJPjozYQchReJ9

I'm supposed to connect like that? because I see only my own messages, not the other machine.
I really appreciate any help! It's taking me days to understand why is not working -_-U

this: https://github.com/libp2p/cpp-libp2p/tree/master/example/03-gossip

使用 example/02-kademlia/rendezvous_chat.cpp 遇到的问题

Hi, 我是第一次使用 libp2p, 在测试 rendezvous_chat 时, FindProviders 总是获取不到 Provider.

所以我修改了日志级别为Debug, 发现 src/protocol/kademlia/impl/session.cpp 中的 Session::onMessageWritten 函数, 在写完业务数据包后, 立即尝试调用 close(), 导致 Client 认为链接被重置.

请评估是否可以按如下方法进行修改?

void Session::onMessageWritten(
    outcome::result<size_t> res,
    const std::shared_ptr<ResponseHandler> &response_handler) {
  if (not res) {
    close(res.as_failure());
    return;
  }

  --writing_;

  if (not response_handlers_.empty()) {
    read();
  }

  // if (canBeClosed()) {
  //   close();
  // }
}

message signing [question]

I am using C++ libp2p with Rust libp2p peers in a gossip network (I use the gossip example as starting point).

Peers are connecting without issue.
I may send a message from a rust peer and the other rust and C++ peers get it.

But if the C++ peer sends a message, the rust peers are rejecting it:
the message is not signed and the gossip configuration of the rust peers want a message signed.

Is it possible for C++ libp2p to sign the message before sending it ?

Avoid useless vector coping by move semantic and using referenceness qualifier

For example:

const std::vector<uint8_t> &BlaBla::toBuffer() const {
  return data_;
}

If we use it to make BlaBla and get std::vector<uint8_t> from that and that all.

std::vector<uint8_t> vec = BlaBla().toBuffer(); // <= copy here

Will be better to use ref-qualifier to move data from sigle-used temp object:

const std::vector<uint8_t> &BlaBla::toBuffer() const & { // <= method for case of usual object
    return data_;
  }
std::vector<uint8_t> BlaBla::toBuffer() const && { // <= method for case of temp object
  return std::move(data_);
}
std::vector<uint8_t> &BlaBla::asBuffer() { // <= method to access internal vector
  return data_;
}
const std::vector<uint8_t> &BlaBla::asBuffer() const { // <= method to RO-access internal vector
  return data_;
}

It is unclear how to add cpp-libp2p to a new project

Hi, building cpp-libp2p from source has worked and all tests have successfully passed, however it is difficult for me to actually add libp2p to a project. The section "Adding cpp-libp2p to the project" is not clear to mel:

1.You put a github link to hunter-simple (btw this link might break at any point in time). From there it still is not clear to me how to add hunter to a project that is not officially supported by hunter. How exactly do we tell hunter to use the existing dependencies to add libp2p to our projects.

  1. Then at the end it says "Example of adding cpp-libp2p to other project can be found here and here", linking to other blobs. These examples did not help me due to lacking context. Please write down a full working example so make it more beginner friendly.

Thanks!

Cannot connect two machines in the same network with rendezvous chat example

Running two instances of the rendezvous_chat with cmd-line arg /ip4/127.0.0.1/tcp/0 on two different machines under the same network leads to them not connecting. Running two instances of rendezvous_chat on the same machine works fine.

The description stated that finding peers can take a while. But I have left the machines for ~30 minutes and they still do not discover eachother. Am I simply not waiting long enough?
On one of the machines I see "outgoing connection failed: Connection refused", so I believe there is an attempt to connect, but it is being refused for some reason.

Looking through the source code I see that this error is being returned from the dialer_impl.cpp

I would really appreciate some insight from someone who is familiar with this code since I have spent a few days looking through the source trying to understand/fix this with no success, and this is a blocker for my project. Thank you very much in advance!

Here is the relevant callstack:

#0 handleOutgoingStream (stream_res=...) at /home/anton/git/cpp-libp2p/example/02-kademlia/rendezvous_chat.cpp:141 #1 0x000055555561b198 in std::_Function_handler<void (boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::Stream>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::Stream>, std::error_code, void> >), void (*)(boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::Stream>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::Stream>, std::error_code, void> >)>::_M_invoke(std::_Any_data const&, boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::Stream>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::Stream>, std::error_code, void> >&&) (__functor=..., __args#0=...) at /usr/include/c++/9/bits/std_function.h:300 #2 0x0000555555784939 in std::function<void (boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::Stream>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::Stream>, std::error_code, void> >)>::operator()(boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::Stream>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::Stream>, std::error_code, void> >) const (this=0x555556c63450, __args#0=...) at /usr/include/c++/9/bits/std_function.h:688 #3 0x0000555555879486 in libp2p::network::DialerImpl::<lambda(libp2p::outcome::result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> >)>::operator()(libp2p::outcome::result) (__closure=0x555556c63440, rconn=...) at /home/anton/git/cpp-libp2p/src/network/impl/dialer_impl.cpp:165 #4 0x000055555587bb78 in std::_Function_handler<void(boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> >), libp2p::network::DialerImpl::newStream(const libp2p::peer::PeerInfo&, const Protocol&, libp2p::network::Dialer::StreamResultFunc, std::chrono::milliseconds)::<lambda(libp2p::outcome::result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> >)> >::_M_invoke(const std::_Any_data &, boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> > &&) (__functor=..., __args#0=...) at /usr/include/c++/9/bits/std_function.h:300 --Type <RET> for more, q to quit, c to continue without paging-- #5 0x000055555574347d in std::function<void (boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> >)>::operator()(boost::outcome_v2::basic_result<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<libp2p::connection::CapableConnection>, std::error_code, void> >) const (this=0x555556a53b78, __args#0=...) at /usr/include/c++/9/bits/std_function.h:688 #6 0x0000555555879020 in libp2p::network::DialerImpl::<lambda()>::operator()(void) const (__closure=0x555556a53b50) at /home/anton/git/cpp-libp2p/src/network/impl/dialer_impl.cpp:147 #7 0x000055555587b86a in std::_Function_handler<void(), libp2p::network::DialerImpl::completeDial(const libp2p::peer::PeerId&, const DialResult&)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/9/bits/std_function.h:300 #8 0x000055555561385e in std::function<void ()>::operator()() const (this=0x5555561c10f8) at /usr/include/c++/9/bits/std_function.h:688 #9 0x00005555558fbdd3 in libp2p::basic::SchedulerImpl::DeferredCallbacks::processNonCancellableItems (items=..., owner=std::shared_ptr<libp2p::basic::Scheduler> (use count 102, weak count 292) = {...}) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:185 #10 0x00005555558fc250 in libp2p::basic::SchedulerImpl::DeferredCallbacks::<lambda()>::operator()(void) const (__closure=0x7fffffffbf80) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:269 #11 0x00005555558fc42c in libp2p::basic::SchedulerImpl::DeferredCallbacks::onTimer (this=0x5555561b64d8, owner=std::shared_ptr<libp2p::basic::Scheduler> (empty) = {...}) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:286 #12 0x00005555558fb621 in libp2p::basic::SchedulerImpl::pulse (this=0x5555561b64a0, current_clock=...) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:84 #13 0x00005555558dfdf9 in libp2p::basic::AsioSchedulerBackend::<lambda()>::operator()(void) const (__closure=0x7fffffffc1a0) at /home/anton/git/cpp-libp2p/src/basic/scheduler/asio_scheduler_backend.cpp:26 #14 0x00005555558e1613 in boost::asio::asio_handler_invoke<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, ...) (function=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/handler_invoke_hook.hpp:69 #15 0x00005555558e1336 in boost_asio_handler_invoke_helpers::invoke<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()>, libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, libp2p::basic::AsioSchedulerBackend::<lambda()> &) (function=..., context=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 #16 0x00005555558e0e7f in boost::asio::detail::handler_work<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()>, boost::asio::system_executor, boost::asio::system_executor>::complete<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, libp2p::basic::AsioSchedulerBackend::<lambda()> &) (this=0x7fffffffc196, function=..., handler=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/handler_work.hpp:100 #17 0x00005555558e0bab in boost::asio::detail::completion_handler<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr<libp2p::basic::SchedulerBackendFeedback>)::<lambda()> >::do_complete(void *, boost::asio::detail::operation *, const boost::system::error_code &, std::size_t) (owner=0x5555561b6f40, base=0x555556b6ad50) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/completion_handler.hpp:70 #18 0x00005555555fe1e8 in boost::asio::detail::scheduler_operation::complete (this=0x555556b6ad50, owner=0x5555561b6f40, ec=..., bytes_transferred=0) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/scheduler_operation.hpp:40 #19 0x00005555556033f0 in boost::asio::detail::scheduler::do_run_one (this=0x5555561b6f40, lock=..., this_thread=..., ec=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/impl/scheduler.ipp:447 #20 0x0000555555602d10 in boost::asio::detail::scheduler::run (this=0x5555561b6f40, ec=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/impl/scheduler.ipp:200 #21 0x0000555555603f9a in boost::asio::io_context::run (this=0x5555561b94b0) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/impl/io_context.ipp:63 #22 0x00005555555e8625 in main (argc=2, argv=0x7fffffffda08) at /home/anton/git/cpp-libp2p/example/02-kademlia/rendezvous_chat.cpp:388

Can we have a chat community ?

Where i can talk fast with other maintenance man, before i make contribution to cpp-libp2p,
such as twitter, facebook, or telegram?

upgrade to a more recent version of boost

The version of Boost currently in use by this library is 1.72.0-p1, which is over a year and a half old. FWIW, I've had no issue compiling it with newer versions of Boost--and hadn't even noticed you had locked in such an old version, as I don't use cmake/hunter--until this week, with the release of 1.76.0, which finally removed support for the apparently-long-deprecated older way of using Boost Outcome's macros.

https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/changelog/upgrade_v21_v22.html

As cmake/hunter has in fact been updating to more recent versions of Boost as they come out, I'm honestly not sure exactly what is holding back the version being used by this project (this seems like some kind of secret decision being made by cmake hunter somewhere, maybe due to something buried in a dependency... not that I've so far found anything that looks like such anywhere in any of these projects).

Refactor unsafe code

  • read/write lambda captures Bytes - use sptr<Bytes> or SharedFn
    • src/protocol/gossip/impl/stream.cpp Stream::beginWrite

Adding libp2p to project using hunter fails

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)

include("cmake/HunterGate.cmake")
HunterGate(
    URL "https://github.com/cpp-pm/hunter/archive/v0.23.269.tar.gz"
    SHA1 "64024b7b95b4c86d50ae05b926814448c93a70a0"
)

# set the project name
project(MyProj)

hunter_add_package(Boost COMPONENTS regex system filesystem)
hunter_add_package(GTest)
hunter_add_package(libp2p)


find_package(GTest CONFIG REQUIRED) # GTest::main
find_package(Boost CONFIG REQUIRED regex system filesystem)
find_package(libp2p CONFIG REQUIRED) # GTest::main

set(SOURCES src/main.cpp src/chunker.cpp)

set(HEADERS src/chunker.h)

# add the executable
add_executable(MyProj ${SOURCES} ${HEADERS})
target_link_libraries(MyProj PUBLIC Boost::regex Boost::system Boost::filesystem GTest::main)


enable_testing()
add_subdirectory(test)

And this is my cmake/Hunter/config.cmake:

hunter_config(libp2p
    URL https://github.com/soramitsu/libp2p/archive/dad84a03a9651c7c2bb8a8f17d0e5ea67bd10b4f.zip
    SHA1 860742c6e3e9736d68b392513d795e09572780aa
    )

I get the following error when I run cmake -H. -B_builds -DHUNTER_STATUS_DEBUG=ON -DCMAKE_BUILD_TYPE=Release :

...   #other libs are downloaded/built fine


-- [hunter *** DEBUG *** 2020-09-02T10:54:45] Cleaning up build directories...
-- [hunter *** DEBUG *** 2020-09-02T10:54:45] Clean up done
-- [hunter *** DEBUG *** 2020-09-02T10:54:45] load: /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/projects/GTest/hunter.cmake ... end
-- [hunter *** DEBUG *** 2020-09-02T10:54:45] File not found (injected package): /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/projects/libp2p/hunter.cmake
-- [hunter *** DEBUG *** 2020-09-02T10:54:45] Injected package 'libp2p'
-- [hunter *** DEBUG *** 2020-09-02T10:54:45] libp2p versions available: []

[hunter ** INTERNAL **] Unexpected empty string
[hunter ** INTERNAL **] [Directory:/home/gov/dev/qtoken-cpp]

------------------------------ ERROR -----------------------------
    https://hunter.readthedocs.io/en/latest/reference/errors/error.internal.html
------------------------------------------------------------------

CMake Error at /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_error_page.cmake:12 (message):
Call Stack (most recent call first):
  /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_internal_error.cmake:13 (hunter_error_page)
  /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_assert_not_empty_string.cmake:9 (hunter_internal_error)
  /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_get_package_sha1.cmake:26 (hunter_assert_not_empty_string)
  /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_download.cmake:83 (hunter_get_package_sha1)
  /home/gov/.hunter/_Base/Download/Hunter/0.23.269/64024b7/Unpacked/cmake/modules/hunter_add_package.cmake:53 (hunter_download)
  CMakeLists.txt:14 (hunter_add_package)


-- Configuring incomplete, errors occurred!
See also "/home/gov/dev/qtoken-cpp/_builds/CMakeFiles/CMakeOutput.log".
See also "/home/gov/dev/qtoken-cpp/_builds/CMakeFiles/CMakeError.log".

Segmentation fault when receiving empty protobuf message

The problem occurs when there is a need to receive message like (protobuf definition):

message BlockResponse {
    repeated bytes block_data = 1;
}

and block_data has zero length. According to protobuf standard 'repeated' means zero or more occurs so it is possible for message with only one repeated field to have no data.

Such correct message is read in MessageReadWriterUvarint::read (message_read_writer_uvarint.cpp). If there is no error during read, that method check if message length is zero and if so, it calls callback with ResultType:

cb(ResultType{});

But the result type is:
using ResultType = std::shared_ptr<std::vector<uint8_t>>;

In fact, the previous callback execution is done using shared pointer that contain nullptr inside.

Read method of ProtobufMessageReadWriter (protobuf_message_read_writer.hpp) contains lambda called from MessageReadWriter, which checks if result is correct and if so it executes the following code:

auto &&buf = res.value();
ProtoMsgType msg;
msg.ParseFromArray(buf->data(), buf->size());

So right after getting shared pointer (res.value()) it's dereferenced without checking if it's empty (buf->data(), buf->size()). This causes segmentation fault.

Above behaviour can lead to DoS attack as potential attacker can prepare empty messages (if there are suitable proto structures) to crash any application using this library. So potential attacker can crash application remotely just by sending appropriate formatted messages that will be parsed by protobuf.

Timeout of opening new stream

Right now we can not to control timeout at opening new stream. If connection is not established, and other side don't answer for connect, callback can be happened too late.
Suggesting to add timeout mechanism for that (e.g. as optional argiment in interface).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.