LCOV - code coverage report
Current view: top level - irohad/consensus/yac/impl - peer_orderer_impl.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 9 11 81.8 %
Date: 2018-12-05 17:11:35 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
       3             :  * http://soramitsu.co.jp
       4             :  *
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #include "consensus/yac/impl/peer_orderer_impl.hpp"
      19             : 
      20             : #include <random>
      21             : 
      22             : #include "common/bind.hpp"
      23             : #include "consensus/yac/cluster_order.hpp"
      24             : #include "consensus/yac/yac_hash_provider.hpp"
      25             : #include "interfaces/common_objects/peer.hpp"
      26             : 
      27             : namespace iroha {
      28             :   namespace consensus {
      29             :     namespace yac {
      30             :       PeerOrdererImpl::PeerOrdererImpl(
      31             :           std::shared_ptr<ametsuchi::PeerQueryFactory> peer_query_factory)
      32         255 :           : peer_query_factory_(peer_query_factory) {}
      33             : 
      34             :       boost::optional<ClusterOrdering> PeerOrdererImpl::getInitialOrdering() {
      35         247 :         return peer_query_factory_->createPeerQuery() |
      36             :             [](const auto &query) { return query->getLedgerPeers(); } |
      37             :             [](const auto &peers) { return ClusterOrdering::create(peers); };
      38           0 :       }
      39             : 
      40             :       boost::optional<ClusterOrdering> PeerOrdererImpl::getOrdering(
      41             :           const YacHash &hash) {
      42        1430 :         return peer_query_factory_->createPeerQuery() |
      43             :             [](const auto &query) { return query->getLedgerPeers(); } |
      44             :             [&hash](auto peers) {
      45        1429 :               std::seed_seq seed(hash.vote_hashes.block_hash.begin(),
      46        1429 :                                  hash.vote_hashes.block_hash.end());
      47        1429 :               std::default_random_engine gen(seed);
      48        1429 :               std::shuffle(peers.begin(), peers.end(), gen);
      49        1429 :               return ClusterOrdering::create(peers);
      50        1429 :             };
      51           0 :       }
      52             :     }  // namespace yac
      53             :   }    // namespace consensus
      54             : }  // namespace iroha

Generated by: LCOV version 1.13