Skip to content

Commit 24899c0

Browse files
kamilsaxDimon
andauthored
vcpkg example (#298)
* Initial example * update: qtils & scale Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * Add README.md * update: soralog Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * update: bump version Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> --------- Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> Co-authored-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 0116614 commit 24899c0

28 files changed

+557
-8
lines changed

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ if (PACKAGE_MANAGER STREQUAL "hunter")
4040
include("cmake/Hunter/init.cmake")
4141
endif ()
4242

43-
project(libp2p VERSION 0.1.17 LANGUAGES C CXX)
43+
project(libp2p VERSION 0.1.32 LANGUAGES C CXX)
4444

4545
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
46+
set(CMAKE_CXX_STANDARD 20)
47+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4648

4749
option(TESTING "Build tests" ON)
4850
option(EXAMPLES "Build examples" ON)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CPP-Libp2p
22

3-
> Fully compatible C++17 implementation of libp2p library
3+
> Fully compatible C++20 implementation of libp2p library
44
55
Libp2p is a modular networking stack described in [spec](https://github.com/libp2p/specs)
66

cmake/Hunter/config.cmake

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
hunter_config(
1919
soralog
20-
URL https://github.com/xDimon/soralog/archive/4dfffd3d949b1c16a04db2e5756555a4031732f7.tar.gz
21-
SHA1 60e3dcaab2d8e43f0ed4fd22087677663c618716
22-
# VERSION 0.2.4
20+
VERSION 0.2.5
21+
URL https://github.com/qdrvm/soralog/archive/refs/tags/v0.2.5.tar.gz
22+
SHA1 67da2d17e93954c198b4419daa55911342c924a9
2323
KEEP_PACKAGE_SOURCES
2424
)
2525

@@ -32,8 +32,9 @@ hunter_config(
3232

3333
hunter_config(
3434
qtils
35-
URL https://github.com/qdrvm/qtils/archive/1e492cf09a3640570cae59a951502614320c0797.tar.gz
36-
SHA1 033dd907e2566c95ce2ccf1fa6dd9766bc896894
35+
VERSION 0.1.0
36+
URL https://github.com/qdrvm/qtils/archive/refs/tags/v0.1.0.tar.gz
37+
SHA1 acc28902af7dc5d74ac33d486ad2261906716f5e
3738
CMAKE_ARGS
3839
FORMAT_ERROR_WITH_FULLTYPE=ON
3940
KEEP_PACKAGE_SOURCES
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(libp2p-example CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
find_package(libsecp256k1 CONFIG REQUIRED)
8+
find_package(ZLIB REQUIRED)
9+
10+
find_package(libp2p CONFIG REQUIRED)
11+
12+
add_executable(example main.cpp)
13+
target_link_libraries(example PRIVATE p2p::p2p)

example/00-vcpkg-install/README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# LibP2P Example with vcpkg
2+
3+
This example demonstrates how to build and run a simple LibP2P application using vcpkg as the package manager.
4+
5+
## Prerequisites
6+
7+
- CMake 3.15 or higher
8+
- A C++20 compatible compiler
9+
- Git
10+
- vcpkg
11+
12+
## Getting Started
13+
14+
1. Clone vcpkg if you haven't already:
15+
16+
```bash
17+
git clone https://github.com/microsoft/vcpkg.git
18+
19+
./vcpkg/bootstrap-vcpkg.sh # For Linux/macOS
20+
.\vcpkg\bootstrap-vcpkg.bat # For Windows
21+
```
22+
23+
2. Clone this repository:
24+
25+
```bash
26+
git clone https://github.com/libp2p/libp2p.git
27+
cd libp2p/example/00-vcpkg-install
28+
```
29+
30+
3. Install LibP2P dependencies using vcpkg:
31+
32+
```bash
33+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake
34+
cmake --build build
35+
```
36+
37+
4. Run the example:
38+
39+
```bash
40+
./build/example
41+
```
42+
43+
## Notes
44+
45+
- This example assumes you have a working vcpkg installation. If you encounter any issues, please refer to the [vcpkg documentation](https://vcpkg.io/en/getting-started.html) for troubleshooting.
46+
- The example demonstrates how to build and run a simple LibP2P application using vcpkg as the package manager.

example/00-vcpkg-install/main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
#include <libp2p/multi/multiaddress.hpp>
3+
#include <libp2p/peer/peer_id.hpp>
4+
5+
int main() {
6+
auto ma_res = libp2p::multi::Multiaddress::create("/ip4/127.0.0.1/tcp/8080");
7+
if (ma_res.has_value()) {
8+
std::cout << "Created multiaddress: "
9+
<< ma_res.value().getStringAddress() << std::endl;
10+
}
11+
return 0;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "fe1cde61e971d53c9687cf9a46308f8f55da19fa",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"overlay-ports": [
8+
"vcpkg-overlay"
9+
]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
2+
vcpkg_from_github(
3+
OUT_SOURCE_PATH SOURCE_PATH
4+
REPO qdrvm/boost-di
5+
REF d5de6c9840c7fc2e44bf37134b4a14b88151ecc4
6+
SHA512 98e924d02bde23940ab59330730de6d4198d1e98cbb303ef713e3ee06f88e90707a952e6aa9a0372213b46d6c9d3478e86ed5cd64d74899861984e786e21c319
7+
)
8+
vcpkg_cmake_configure(
9+
SOURCE_PATH "${SOURCE_PATH}"
10+
OPTIONS
11+
-DBOOST_DI_OPT_BUILD_TESTS=OFF
12+
-DBOOST_DI_OPT_BUILD_EXAMPLES=OFF
13+
)
14+
vcpkg_cmake_install()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "boost-di",
3+
"version": "1.1.0.1",
4+
"dependencies": [
5+
{ "name": "vcpkg-cmake", "host": true },
6+
{ "name": "vcpkg-cmake-config", "host": true }
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO fmtlib/fmt
4+
REF 10.1.1
5+
SHA512 288c349baac5f96f527d5b1bed0fa5f031aa509b4526560c684281388e91909a280c3262a2474d963b5d1bf7064b1c9930c6677fe54a0d8f86982d063296a54c
6+
)
7+
8+
vcpkg_cmake_configure(
9+
SOURCE_PATH "${SOURCE_PATH}"
10+
OPTIONS
11+
-DFMT_DOC=OFF
12+
-DFMT_TEST=OFF
13+
-DFMT_INSTALL=ON
14+
-DCMAKE_CXX_STANDARD=20
15+
)
16+
17+
vcpkg_cmake_install()
18+
vcpkg_copy_pdbs()
19+
vcpkg_cmake_config_fixup(PACKAGE_NAME fmt CONFIG_PATH lib/cmake/fmt)
20+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "fmt",
3+
"version": "10.1.1",
4+
"dependencies": [
5+
{ "name": "vcpkg-cmake", "host": true },
6+
{ "name": "vcpkg-cmake-config", "host": true }
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 65c4776..5d4086a 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -60,12 +60,12 @@ ENDIF()
6+
7+
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
8+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
9+
- IF(CMAKE_C_COMPILER MATCHES "clang" AND
10+
- NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
11+
- NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
12+
- SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
13+
- SET(LIBS ${LIBS} -fsanitize=address)
14+
- ENDIF()
15+
+ # IF(CMAKE_C_COMPILER MATCHES "clang" AND
16+
+ # NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
17+
+ # NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
18+
+ # SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
19+
+ # SET(LIBS ${LIBS} -fsanitize=address)
20+
+ # ENDIF()
21+
# Uncomment to enable cleartext protocol mode (no crypto):
22+
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1")
23+
ELSE()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 5d4086a..e085a83 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -120,10 +120,12 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
6+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
7+
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
8+
#SET(LIBS ${LIBS} fiu)
9+
+ SET(LIB_NAME ssld cryptod)
10+
ELSE()
11+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
12+
# Comment out the following line to compile out debug messages:
13+
#SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
14+
+ SET(LIB_NAME ssl crypto)
15+
ENDIF()
16+
17+
ENDIF() #MSVC
18+
@@ -191,7 +193,7 @@ IF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR)
19+
ELSE()
20+
21+
22+
- FOREACH(LIB_NAME ssl crypto)
23+
+ FOREACH(LIB ${LIB_NAME})
24+
# If BORINGSSL_LIB is defined, try find each lib. Otherwise, user should define BORINGSSL_LIB_ssl,
25+
# BORINGSSL_LIB_crypto and so on explicitly. For example, including boringssl and lsquic both via
26+
# add_subdirectory:
27+
@@ -201,20 +203,20 @@ ELSE()
28+
# add_subdirectory(third_party/lsquic)
29+
IF (DEFINED BORINGSSL_LIB)
30+
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
31+
- FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
32+
- NAMES ${LIB_NAME}
33+
+ FIND_LIBRARY(BORINGSSL_LIB_${LIB}
34+
+ NAMES ${LIB}
35+
PATHS ${BORINGSSL_LIB}
36+
PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
37+
NO_DEFAULT_PATH)
38+
ELSE()
39+
- FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
40+
- NAMES lib${LIB_NAME}${LIB_SUFFIX}
41+
+ FIND_LIBRARY(BORINGSSL_LIB_${LIB}
42+
+ NAMES lib${LI}${LIB_SUFFIX}
43+
PATHS ${BORINGSSL_LIB}
44+
- PATH_SUFFIXES ${LIB_NAME}
45+
+ PATH_SUFFIXES ${LIB}
46+
NO_DEFAULT_PATH)
47+
ENDIF()
48+
ENDIF()
49+
- IF(BORINGSSL_LIB_${LIB_NAME})
50+
+ IF(BORINGSSL_LIB_${LIB})
51+
MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}")
52+
ELSE()
53+
MESSAGE(FATAL_ERROR "BORINGSSL_LIB_${LIB_NAME} library not found")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
diff --git a/include/lsquic.h b/include/lsquic.h
2+
index 389fbcc..c38d027 100644
3+
--- a/include/lsquic.h
4+
+++ b/include/lsquic.h
5+
@@ -1671,6 +1671,10 @@ int lsquic_stream_close(lsquic_stream_t *s);
6+
int
7+
lsquic_stream_has_unacked_data (lsquic_stream_t *s);
8+
9+
+/* Return SSL object associated with this connection */
10+
+struct ssl_st *
11+
+lsquic_conn_ssl(struct lsquic_conn *conn);
12+
+
13+
/**
14+
* Get certificate chain returned by the server. This can be used for
15+
* server certificate verification.
16+
diff --git a/src/liblsquic/lsquic_conn.c b/src/liblsquic/lsquic_conn.c
17+
index f76550d..31e5285 100644
18+
--- a/src/liblsquic/lsquic_conn.c
19+
+++ b/src/liblsquic/lsquic_conn.c
20+
@@ -128,6 +128,12 @@ lsquic_conn_crypto_alg_keysize (const lsquic_conn_t *lconn)
21+
}
22+
23+
24+
+struct ssl_st *
25+
+lsquic_conn_ssl(struct lsquic_conn *lconn) {
26+
+ return lconn->cn_esf_c->esf_get_ssl(lconn->cn_enc_session);
27+
+}
28+
+
29+
+
30+
struct stack_st_X509 *
31+
lsquic_conn_get_server_cert_chain (struct lsquic_conn *lconn)
32+
{
33+
diff --git a/src/liblsquic/lsquic_enc_sess.h b/src/liblsquic/lsquic_enc_sess.h
34+
index f45c15f..3505fbd 100644
35+
--- a/src/liblsquic/lsquic_enc_sess.h
36+
+++ b/src/liblsquic/lsquic_enc_sess.h
37+
@@ -115,6 +115,9 @@ struct enc_session_funcs_common
38+
(*esf_decrypt_packet)(enc_session_t *, struct lsquic_engine_public *,
39+
const struct lsquic_conn *, struct lsquic_packet_in *);
40+
41+
+ struct ssl_st *
42+
+ (*esf_get_ssl)(enc_session_t *);
43+
+
44+
struct stack_st_X509 *
45+
(*esf_get_server_cert_chain) (enc_session_t *);
46+
47+
diff --git a/src/liblsquic/lsquic_enc_sess_ietf.c b/src/liblsquic/lsquic_enc_sess_ietf.c
48+
index 66329c1..076c4c5 100644
49+
--- a/src/liblsquic/lsquic_enc_sess_ietf.c
50+
+++ b/src/liblsquic/lsquic_enc_sess_ietf.c
51+
@@ -2519,6 +2519,13 @@ iquic_esf_global_cleanup (void)
52+
}
53+
54+
55+
+static struct ssl_st *
56+
+iquic_esf_get_ssl(enc_session_t *enc_session_p) {
57+
+ struct enc_sess_iquic *const enc_sess = enc_session_p;
58+
+ return enc_sess->esi_ssl;
59+
+}
60+
+
61+
+
62+
static struct stack_st_X509 *
63+
iquic_esf_get_server_cert_chain (enc_session_t *enc_session_p)
64+
{
65+
@@ -2744,6 +2751,7 @@ const struct enc_session_funcs_common lsquic_enc_session_common_ietf_v1 =
66+
.esf_global_cleanup = iquic_esf_global_cleanup,
67+
.esf_global_init = iquic_esf_global_init,
68+
.esf_tag_len = IQUIC_TAG_LEN,
69+
+ .esf_get_ssl = iquic_esf_get_ssl,
70+
.esf_get_server_cert_chain
71+
= iquic_esf_get_server_cert_chain,
72+
.esf_get_sni = iquic_esf_get_sni,
73+
@@ -2763,6 +2771,7 @@ const struct enc_session_funcs_common lsquic_enc_session_common_ietf_v1_no_flush
74+
.esf_global_cleanup = iquic_esf_global_cleanup,
75+
.esf_global_init = iquic_esf_global_init,
76+
.esf_tag_len = IQUIC_TAG_LEN,
77+
+ .esf_get_ssl = iquic_esf_get_ssl,
78+
.esf_get_server_cert_chain
79+
= iquic_esf_get_server_cert_chain,
80+
.esf_get_sni = iquic_esf_get_sni,

0 commit comments

Comments
 (0)