Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
lebdron committed Jun 24, 2017
1 parent dbfa8b9 commit 026ad9f
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 217 deletions.
72 changes: 41 additions & 31 deletions irohad/consensus/sumeragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <thread_pool.hpp>
#include <vector>
#include <set>
#include <common/types.hpp>
#include <common/byteutils.hpp>

#include "connection/service.hpp"
#include "connection/client.hpp"
Expand Down Expand Up @@ -50,47 +52,49 @@ namespace consensus {

logger::Logger log("sumeragi");

static ThreadPool pool(ThreadPoolOptions{
static ThreadPool pool(ThreadPoolOptions {
.threads_count = 0,
//config::IrohaConfigManager::getInstance().getConcurrency(0),
.worker_queue_size = 1024
//config::IrohaConfigManager::getInstance().getPoolWorkerQueueSize(1024),
});
}
);

void initialize() {

consensus::connection::receive(
[](const Block &block) {
// TODO: Judge committed
if ( /*check is_committed*/ false) {

} else {
// send processBlock(block) as a task to processing pool
// this returns std::future<void> object
// (std::future).get() method locks processing until result of
// processBlock will be available but processBlock returns
// void, so we don't have to call it and wait
std::function<void()> &&task = std::bind(processBlock, block);
pool.process(std::move(task));
}
});
[](const Block &block) {
// TODO: Judge committed
if ( /*check is_committed*/ false) {

} else {
// send processBlock(block) as a task to processing pool
// this returns std::future<void> object
// (std::future).get() method locks processing until result of
// processBlock will be available but processBlock returns
// void, so we don't have to call it and wait
std::function<void()> &&task = std::bind(processBlock, block);
pool.process(std::move(task));
}
});
}

size_t getMaxFaulty() {
return (size_t)peer_service::monitor::getActivePeerSize() / 3;
return (size_t) peer_service::monitor::getActivePeerSize() / 3;
}

size_t getNumValidatingPeers() {
return getMaxFaulty() * 2 + 1;
}

bool unicast(const iroha::protocol::Block& block, size_t peerOrder) {
auto peer = peer_service::monitor::getActivePeerAt((unsigned int)peerOrder);
bool unicast(const iroha::protocol::Block &block, size_t peerOrder) {
auto peer =
peer_service::monitor::getActivePeerAt((unsigned int) peerOrder);
auto response = connection::sendBlock(block, peer->ip_);
return response.code() == iroha::protocol::ResponseCode::OK;
}

bool leaderMulticast(const iroha::protocol::Block& block) {
bool leaderMulticast(const iroha::protocol::Block &block) {
// connection::multicastWithRange(block, 1, getNumValidatingPeers());
/*
auto peerSize = getNumValidatingPeers();
Expand All @@ -101,7 +105,7 @@ namespace consensus {
return true;
}

bool commit(const iroha::protocol::Block& block) {
bool commit(const iroha::protocol::Block &block) {
// connection::multicastAll(block);
/*
auto peerSize = (size_t)peer_service::monitor::getActivePeerSize();
Expand All @@ -117,24 +121,30 @@ namespace consensus {
return std::vector<uint8_t>();
}

Block createSignedBlock(const Block &block, const std::vector<uint8_t> &merkleRoot) {
Block createSignedBlock(const Block &block,
const std::vector<uint8_t> &merkleRoot) {

// TODO: Use Keypair in peer service.
std::string pkBase64 = peer_service::self_state::getPublicKey();
std::string skBase64 = peer_service::self_state::getPrivateKey();

auto keypair = iroha::crypto::Keypair(base64_decode(pkBase64), base64_decode(skBase64));
auto signature = keypair.sign(merkleRoot);
auto pubkey_ = base64_decode(pkBase64),
privkey_ = base64_decode(skBase64);
auto pubkey =
iroha::to_blob<iroha::ed25519::pubkey_t::size()>(std::string{
pubkey_.begin(), pubkey_.end()});
auto privkey =
iroha::to_blob<iroha::ed25519::privkey_t::size()>(std::string{
privkey_.begin(), privkey_.end()});

if (!signature) {
throw std::runtime_error("failed to create signature");
}
auto signature =
iroha::sign(merkleRoot.data(), merkleRoot.size(), pubkey, privkey);

std::string strSigblob;
for (auto e: *signature) strSigblob.push_back(e);
for (auto e: signature) strSigblob.push_back(e);

Signature newSignature;
*newSignature.mutable_pubkey() = keypair.pub_base64();
*newSignature.mutable_pubkey() = pubkey.to_base64();
*newSignature.mutable_signature() = strSigblob;

Block ret;
Expand All @@ -157,7 +167,8 @@ namespace consensus {
*/

int getNextOrder() {
thread_local int currentProxyTail = static_cast<int>(getNumValidatingPeers()) - 1;
thread_local int
currentProxyTail = static_cast<int>(getNumValidatingPeers()) - 1;
if (currentProxyTail >= peer_service::monitor::getActivePeerSize()) {
return -1;
}
Expand Down Expand Up @@ -224,7 +235,6 @@ namespace consensus {
}
}


/**
*
* For example, given:
Expand Down
9 changes: 5 additions & 4 deletions irohad/peer_service/self_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ limitations under the License.
#include <crypto/crypto.hpp>

#include <iostream>
#include <cstring>

namespace peer_service {
namespace self_state {
Expand All @@ -39,10 +40,10 @@ namespace peer_service {

void initializeMyKey() {
if (public_key_.empty() || private_key_.empty()) {
iroha::crypto::Keypair keypair =
iroha::crypto::Keypair::generate_keypair();
public_key_ = keypair.pub_base64();
private_key_ = *keypair.priv_base64();
auto seed = iroha::create_seed();
auto keypair = iroha::create_keypair(seed);
public_key_ = keypair.first.to_base64();
private_key_ = keypair.second.to_base64();
}
}

Expand Down
8 changes: 6 additions & 2 deletions libs/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <dirent.h>
#include <array>
#include <cstdio>
#include <crypto/base64.hpp>

/**
* This file defines common types used in iroha.
Expand Down Expand Up @@ -78,10 +79,13 @@ namespace iroha {
}

private:
static const std::string code = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static const std::string code;
};

template <size_t size_>
const std::string blob_t<size_>::code = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

template <size_t size>
using hash_t = blob_t<size>;

Expand Down
27 changes: 12 additions & 15 deletions libs/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
add_library(hash STATIC
hash.cpp
hash.hpp
)
hash.cpp
hash.hpp
)

target_link_libraries(hash PUBLIC
keccak
)



keccak
)

add_library(crypto STATIC
crypto.hpp
ed25519_impl.cpp
)
target_link_libraries(crypto PUBLiC
ed25519
hash
)
crypto.hpp
ed25519_impl.cpp
)
target_link_libraries(crypto PUBLIC
ed25519
hash
)
2 changes: 1 addition & 1 deletion libs/dao/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
#ifndef IROHA_ASSET_HPP
#define IROHA_ASSET_HPP

#include <common.hpp>
#include <common/types.hpp>
#include <string>

namespace iroha {
Expand Down
2 changes: 1 addition & 1 deletion libs/dao/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
#ifndef IROHA_BLOCK_HPP
#define IROHA_BLOCK_HPP

#include <common.hpp>
#include <common/types.hpp>
#include <vector>
#include "singature.hpp"
#include "transaction.hpp"
Expand Down
11 changes: 5 additions & 6 deletions libs/dao/dao_hash_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ limitations under the License.
#ifndef IROHA_DAO_HASH_PROVIDER_HPP
#define IROHA_DAO_HASH_PROVIDER_HPP

#include <common.hpp>
#include <crypto/common.hpp>
#include <common/types.hpp>
#include "dao.hpp"

namespace iroha {
Expand All @@ -28,26 +27,26 @@ namespace iroha {
* Hash provider is an abstract factory for computing hashes on DAO objects.
* @tparam T - length of hash
*/
template <int T>
template <size_t N>
class HashProvider {
public:
/**
* Abstract method for computing hash on DAO: Proposal
* @param proposal - source object for computing hash
*/
virtual iroha::hash_t<T> get_hash(const Proposal &proposal) = 0;
virtual blob_t<N> get_hash(const Proposal &proposal) = 0;

/**
* Abstract method for computing hash on DAO: Block
* @param block - source object for computing hash
*/
virtual iroha::hash_t<T> get_hash(const Block &block) = 0;
virtual blob_t<N> get_hash(const Block &block) = 0;

/**
* Abstract method for computing hash on DAO: Transaction
* @param tx - source object for computing hash
*/
virtual iroha::hash_t<T> get_hash(const Transaction &tx) = 0;
virtual blob_t<N> get_hash(const Transaction &tx) = 0;
};
}
}
Expand Down
Loading

0 comments on commit 026ad9f

Please sign in to comment.