Skip to content

Commit

Permalink
add libp2p 0.1.26
Browse files Browse the repository at this point in the history
  • Loading branch information
simbahebinbo committed Aug 29, 2024
1 parent 2f3cf77 commit 937810a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions cmake/projects/libp2p/hunter.cmake
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions examples/libp2p/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)

28 changes: 28 additions & 0 deletions examples/libp2p/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <libp2p/multi/multiaddress.hpp>
#include <libp2p/peer/peer_id.hpp>

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;
}

0 comments on commit 937810a

Please sign in to comment.