Skip to content

Commit 507af8b

Browse files
committed
IPLD format refactor
1 parent 726eeef commit 507af8b

31 files changed

+704
-531
lines changed

core/primitives/persistent_block/persistent_block.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace fc::primitives::blockchain::block {
1515
return cid_;
1616
}
1717

18-
const common::Buffer &PersistentBlock::getRawBytes() const {
18+
const common::Buffer &PersistentBlock::getRawBytes() const {
1919
return data_;
2020
}
2121

core/primitives/persistent_block/persistent_block.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#ifndef CPP_FILECOIN_CORE_BLOCKCHAIN_BLOCK_PERSISTENT_BLOCK_HPP
77
#define CPP_FILECOIN_CORE_BLOCKCHAIN_BLOCK_PERSISTENT_BLOCK_HPP
88

9-
#include "storage/ipfs/ipfs_block.hpp"
9+
#include "storage/ipld/ipld_block.hpp"
1010

1111
namespace fc::primitives::blockchain::block {
12-
class PersistentBlock : public storage::ipfs::IpfsBlock {
12+
class PersistentBlock : public storage::ipld::IPLDBlock {
1313
public:
1414
virtual ~PersistentBlock() override = default;
1515

core/storage/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory(filestore)
1010
add_subdirectory(hamt)
1111
add_subdirectory(in_memory)
1212
add_subdirectory(ipfs)
13+
add_subdirectory(ipld)
1314
add_subdirectory(keystore)
1415
add_subdirectory(leveldb)
1516
add_subdirectory(repository)

core/storage/ipfs/ipfs_block.hpp

-39
This file was deleted.
+5-24
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
1-
find_package(Protobuf REQUIRED)
2-
set(PB_SCHEME "merkledag.proto")
3-
set(PB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
4-
5-
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out=${PB_BUILD_DIR} ${PB_SCHEME}
6-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/impl/protobuf
7-
RESULT_VARIABLE CMD_OUTPUT
8-
)
9-
10-
add_library(ipfs_merkledag_service_protobuf
11-
${PB_BUILD_DIR}/merkledag.pb.h
12-
${PB_BUILD_DIR}/merkledag.pb.cc
13-
)
14-
target_include_directories(ipfs_merkledag_service_protobuf PUBLIC ${PB_BUILD_DIR})
15-
target_link_libraries(ipfs_merkledag_service_protobuf
16-
protobuf::libprotobuf
17-
)
18-
disable_clang_tidy(ipfs_merkledag_service_protobuf)
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
195

206
add_library(ipfs_merkledag_service
21-
impl/link_impl.cpp
22-
impl/node_impl.cpp
237
impl/merkledag_service_impl.cpp
24-
impl/pb_node_encoder.cpp
25-
impl/pb_node_decoder.cpp
268
impl/leaf_impl.cpp
279
)
2810
target_link_libraries(ipfs_merkledag_service
29-
cid
3011
Boost::boost
12+
ipld_node
3113
ipfs_blockservice
3214
ipfs_datastore_in_memory
33-
ipfs_merkledag_service_protobuf
3415
)

core/storage/ipfs/merkledag/impl/link_impl.cpp

-27
This file was deleted.

core/storage/ipfs/merkledag/impl/merkledag_service_impl.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#include <boost/assert.hpp>
99
#include <libp2p/multi/content_identifier_codec.hpp>
10-
#include "storage/ipfs/merkledag/impl/node_impl.hpp"
10+
#include "storage/ipld/impl/ipld_node_impl.hpp"
1111

1212
using libp2p::multi::ContentIdentifierCodec;
1313

1414
namespace fc::storage::ipfs::merkledag {
15+
using ipld::IPLDNodeImpl;
16+
1517
MerkleDagServiceImpl::MerkleDagServiceImpl(
1618
std::shared_ptr<IpfsDatastore> service)
1719
: block_service_{std::move(service)} {
@@ -20,14 +22,14 @@ namespace fc::storage::ipfs::merkledag {
2022
}
2123

2224
outcome::result<void> MerkleDagServiceImpl::addNode(
23-
std::shared_ptr<const Node> node) {
25+
std::shared_ptr<const IPLDNode> node) {
2426
return block_service_->set(node->getCID(), node->getRawBytes());
2527
}
2628

27-
outcome::result<std::shared_ptr<Node>> MerkleDagServiceImpl::getNode(
29+
outcome::result<std::shared_ptr<IPLDNode>> MerkleDagServiceImpl::getNode(
2830
const CID &cid) const {
2931
OUTCOME_TRY(content, block_service_->get(cid));
30-
return NodeImpl::createFromRawBytes(content);
32+
return IPLDNodeImpl::createFromRawBytes(content);
3133
}
3234

3335
outcome::result<void> MerkleDagServiceImpl::removeNode(const CID &cid) {
@@ -37,15 +39,15 @@ namespace fc::storage::ipfs::merkledag {
3739
outcome::result<size_t> MerkleDagServiceImpl::select(
3840
gsl::span<const uint8_t> root_cid,
3941
gsl::span<const uint8_t> selector,
40-
std::function<bool(std::shared_ptr<const Node>)> handler) const {
42+
std::function<bool(std::shared_ptr<const IPLDNode>)> handler) const {
4143
std::ignore = selector;
4244
OUTCOME_TRY(content_id, ContentIdentifierCodec::decode(root_cid));
4345
CID cid{std::move(content_id)};
4446
OUTCOME_TRY(root_node, getNode(cid));
45-
std::vector<std::shared_ptr<const Node>> node_set{};
47+
std::vector<std::shared_ptr<const IPLDNode>> node_set{};
4648
node_set.emplace_back(std::move(root_node));
4749
const auto &links = node_set.front()->getLinks();
48-
for (const auto& link : links) {
50+
for (const auto &link : links) {
4951
auto request = getNode(link.get().getCID());
5052
if (request.has_error()) return ServiceError::UNRESOLVED_LINK;
5153
node_set.emplace_back(std::move(request.value()));
@@ -79,7 +81,7 @@ namespace fc::storage::ipfs::merkledag {
7981

8082
outcome::result<void> MerkleDagServiceImpl::buildGraph(
8183
const std::shared_ptr<LeafImpl> &root,
82-
const std::vector<std::reference_wrapper<const Link>> &links,
84+
const std::vector<std::reference_wrapper<const IPLDLink>> &links,
8385
bool depth_limit,
8486
const size_t max_depth,
8587
size_t current_depth) const {
@@ -89,7 +91,7 @@ namespace fc::storage::ipfs::merkledag {
8991
for (const auto &link : links) {
9092
auto request = getNode(link.get().getCID());
9193
if (request.has_error()) return ServiceError::UNRESOLVED_LINK;
92-
std::shared_ptr<Node> node = request.value();
94+
std::shared_ptr<IPLDNode> node = request.value();
9395
auto child_leaf = std::make_shared<LeafImpl>(node->content());
9496
auto build_result = buildGraph(child_leaf,
9597
node->getLinks(),

core/storage/ipfs/merkledag/impl/merkledag_service_impl.hpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#include "storage/ipfs/datastore.hpp"
1212
#include "storage/ipfs/merkledag/impl/leaf_impl.hpp"
1313
#include "storage/ipfs/merkledag/merkledag_service.hpp"
14+
#include "storage/ipld/ipld_link.hpp"
1415

1516
namespace fc::storage::ipfs::merkledag {
17+
using ipld::IPLDLink;
18+
1619
class MerkleDagServiceImpl : public MerkleDagService {
1720
public:
1821
/**
@@ -21,17 +24,18 @@ namespace fc::storage::ipfs::merkledag {
2124
*/
2225
explicit MerkleDagServiceImpl(std::shared_ptr<IpfsDatastore> service);
2326

24-
outcome::result<void> addNode(std::shared_ptr<const Node> node) override;
27+
outcome::result<void> addNode(
28+
std::shared_ptr<const IPLDNode> node) override;
2529

26-
outcome::result<std::shared_ptr<Node>> getNode(
30+
outcome::result<std::shared_ptr<IPLDNode>> getNode(
2731
const CID &cid) const override;
2832

2933
outcome::result<void> removeNode(const CID &cid) override;
3034

3135
outcome::result<size_t> select(
3236
gsl::span<const uint8_t> root_cid,
3337
gsl::span<const uint8_t> selector,
34-
std::function<bool(std::shared_ptr<const Node> node)> handler)
38+
std::function<bool(std::shared_ptr<const IPLDNode> node)> handler)
3539
const override;
3640

3741
outcome::result<std::shared_ptr<Leaf>> fetchGraph(
@@ -55,7 +59,7 @@ namespace fc::storage::ipfs::merkledag {
5559
*/
5660
outcome::result<void> buildGraph(
5761
const std::shared_ptr<LeafImpl> &root,
58-
const std::vector<std::reference_wrapper<const Link>> &links,
62+
const std::vector<std::reference_wrapper<const IPLDLink>> &links,
5963
bool depth_limit,
6064
size_t max_depth,
6165
size_t current_depth = 0) const;

core/storage/ipfs/merkledag/impl/node_impl.cpp

-133
This file was deleted.

0 commit comments

Comments
 (0)