diff --git a/cmake/configs/default.cmake b/cmake/configs/default.cmake index 87e6e38386..da1f60a787 100644 --- a/cmake/configs/default.cmake +++ b/cmake/configs/default.cmake @@ -379,6 +379,7 @@ hunter_default_version(libjson-rpc-cpp VERSION 0.7.0-p3) hunter_default_version(libmill VERSION 1.18) hunter_default_version(libogg VERSION 1.3.3-p0) hunter_default_version(libpcre VERSION 8.41) +hunter_default_version(libp2p VERSION 0.1.26) hunter_default_version(librtmp VERSION 2.4.0-p0) hunter_default_version(libscrypt VERSION 1.21-p1) hunter_default_version(libsodium VERSION 1.0.16-p0) diff --git a/cmake/projects/libp2p/hunter.cmake b/cmake/projects/libp2p/hunter.cmake new file mode 100644 index 0000000000..8596adeadc --- /dev/null +++ b/cmake/projects/libp2p/hunter.cmake @@ -0,0 +1,27 @@ +# All rights reserved. + +# !!! DO NOT PLACE HEADER GUARDS HERE !!! + +# Load used modules +include(hunter_add_version) +include(hunter_cacheable) +include(hunter_download) +include(hunter_pick_scheme) + +# List of versions here... + +hunter_add_version( + PACKAGE_NAME + libp2p + VERSION + "0.1.26" + URL + "https://github.com/libp2p/cpp-libp2p/archive/v0.1.26.zip" + SHA1 + 9a44a1448f2de9999a0c6ef4f8aad0d68220dd50 +) + +# Pick a download scheme +hunter_pick_scheme(DEFAULT url_sha1_cmake) +hunter_cacheable(libp2p) +hunter_download(PACKAGE_NAME libp2p) diff --git a/examples/libp2p/CMakeLists.txt b/examples/libp2p/CMakeLists.txt new file mode 100644 index 0000000000..cc06b95e2f --- /dev/null +++ b/examples/libp2p/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2015, Ruslan Baratov +# All rights reserved. + +cmake_minimum_required(VERSION 3.12) + +# Emulate HunterGate: +# * https://github.com/hunter-packages/gate +include("../common.cmake") + +project(download-libp2p) + +hunter_add_package(libp2p) +find_package(libp2p CONFIG REQUIRED) + +add_executable(libp2p_example main.cpp) +target_link_libraries(libp2p_example PRIVATE + libp2p::p2p_peer_id + libp2p::p2p_multiaddress +) + diff --git a/examples/libp2p/main.cpp b/examples/libp2p/main.cpp new file mode 100644 index 0000000000..39bcb10dc3 --- /dev/null +++ b/examples/libp2p/main.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using namespace libp2p; + +int main() +{ + auto addr = Multiaddress::create("/ip4/192.168.0.1/tcp/8080"); + std::cout << "address: " << addr.value().getStringAddress() << std::endl; + + // 创建一个 Peer ID + auto peer_id_result = PeerId::fromBase58("QmPCh4nxk8kkj7A7KsSeYvW1Z5AB89p8s3u4FRoRhGgDZk"); + + // 输出 Peer ID + if (peer_id_result) + { + // 检查是否成功 + const auto& peer_id = peer_id_result.value(); // 获取 PeerId 对象 + std::cout << "Peer ID: " << peer_id.toHex() << std::endl; // 使用 toHex() + } + else + { + std::cout << "Invalid Peer ID" << std::endl; + } + + return 0; +}