generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 36
IPLD refactor #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
IPLD refactor #108
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
add_library(filecoin_hasher | ||
hasher.cpp | ||
) | ||
target_link_libraries(filecoin_hasher | ||
blake2 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "hasher.hpp" | ||
|
||
#include <libp2p/crypto/sha/sha256.hpp> | ||
#include "crypto/blake2/blake2b160.hpp" | ||
|
||
namespace fc::crypto { | ||
std::map<Hasher::HashType, Hasher::HashMethod> Hasher::methods_{ | ||
{HashType::sha256, Hasher::sha2_256}, | ||
{HashType::blake2b_256, Hasher::blake2b_256}}; | ||
|
||
Hasher::Multihash Hasher::calculate(HashType hash_type, | ||
gsl::span<const uint8_t> buffer) { | ||
HashMethod hash_method = methods_.at(hash_type); | ||
return std::invoke(hash_method, buffer); | ||
} | ||
|
||
Hasher::Multihash Hasher::sha2_256(gsl::span<const uint8_t> buffer) { | ||
auto digest = libp2p::crypto::sha256(buffer); | ||
auto multi_hash = Multihash::create(HashType::sha256, digest); | ||
BOOST_ASSERT_MSG(multi_hash.has_value(), | ||
"fc::crypto::Hasher - failed to create sha2-256 hash"); | ||
return multi_hash.value(); | ||
} | ||
|
||
Hasher::Multihash Hasher::blake2b_256(gsl::span<const uint8_t> buffer) { | ||
auto digest = crypto::blake2b::blake2b_256(buffer); | ||
auto multi_hash = Multihash::create(HashType::blake2b_256, digest); | ||
BOOST_ASSERT_MSG(multi_hash.has_value(), | ||
"fc::crypto::Hasher - failed to create blake2b_256 hash"); | ||
return multi_hash.value(); | ||
sergkaprovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} // namespace fc::crypto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef FILECOIN_CORE_CRYPTO_HASHER_HPP | ||
#define FILECOIN_CORE_CRYPTO_HASHER_HPP | ||
|
||
#include <map> | ||
|
||
#include <libp2p/multi/multihash.hpp> | ||
|
||
namespace fc::crypto { | ||
/** | ||
* @class Supported methods: | ||
* sha2-256 | ||
* blakeb2-256 | ||
*/ | ||
class Hasher { | ||
protected: | ||
using HashType = libp2p::multi::HashType; | ||
using Multihash = libp2p::multi::Multihash; | ||
using HashMethod = Multihash (*)(gsl::span<const uint8_t>); | ||
|
||
private: | ||
static std::map<HashType, HashMethod> methods_; | ||
|
||
public: | ||
static Multihash calculate(HashType hash_type, | ||
gsl::span<const uint8_t> buffer); | ||
|
||
/** | ||
* @brief Calculate SHA2-256 hash | ||
* @param buffer - source data | ||
* @return SHA2-256 hash | ||
*/ | ||
static Multihash sha2_256(gsl::span<const uint8_t> buffer); | ||
|
||
/** | ||
* @brief Calculate Blake2b-256 hash | ||
* @param buffer - source data | ||
* @return Blake2b-256 hash | ||
*/ | ||
static Multihash blake2b_256(gsl::span<const uint8_t> buffer); | ||
}; | ||
} // namespace fc::crypto | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
find_package(Protobuf REQUIRED) | ||
set(PB_SCHEME "merkledag.proto") | ||
set(PB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out=${PB_BUILD_DIR} ${PB_SCHEME} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/impl/protobuf | ||
RESULT_VARIABLE CMD_OUTPUT | ||
) | ||
|
||
add_library(ipfs_merkledag_service_protobuf | ||
${PB_BUILD_DIR}/merkledag.pb.h | ||
${PB_BUILD_DIR}/merkledag.pb.cc | ||
) | ||
target_include_directories(ipfs_merkledag_service_protobuf PUBLIC ${PB_BUILD_DIR}) | ||
target_link_libraries(ipfs_merkledag_service_protobuf | ||
protobuf::libprotobuf | ||
) | ||
disable_clang_tidy(ipfs_merkledag_service_protobuf) | ||
# | ||
# Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
add_library(ipfs_merkledag_service | ||
impl/link_impl.cpp | ||
impl/node_impl.cpp | ||
impl/merkledag_service_impl.cpp | ||
impl/pb_node_encoder.cpp | ||
impl/pb_node_decoder.cpp | ||
impl/leaf_impl.cpp | ||
) | ||
target_link_libraries(ipfs_merkledag_service | ||
cid | ||
Boost::boost | ||
ipld_node | ||
ipfs_blockservice | ||
ipfs_datastore_in_memory | ||
ipfs_merkledag_service_protobuf | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.