LCOV - code coverage report
Current view: top level - irohad/consensus/yac - messages.hpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 4 4 100.0 %
Date: 2018-12-05 17:11:35 Functions: 28 29 96.6 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. 2018 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             : #ifndef IROHA_MESSAGES_HPP
      19             : #define IROHA_MESSAGES_HPP
      20             : 
      21             : #include <vector>
      22             : 
      23             : #include "consensus/yac/yac_hash_provider.hpp"  // for YacHash
      24             : #include "interfaces/common_objects/signature.hpp"
      25             : #include "utils/string_builder.hpp"
      26             : 
      27             : namespace iroha {
      28             :   namespace consensus {
      29             :     namespace yac {
      30             : 
      31             :       /**
      32             :        * VoteMessage represents voting for some block;
      33             :        */
      34             :       struct VoteMessage {
      35             :         YacHash hash;
      36             :         std::shared_ptr<shared_model::interface::Signature> signature;
      37             : 
      38             :         bool operator==(const VoteMessage &rhs) const {
      39        1037 :           return hash == rhs.hash and *signature == *rhs.signature;
      40             :         }
      41             : 
      42             :         bool operator!=(const VoteMessage &rhs) const {
      43         133 :           return not(*this == rhs);
      44             :         }
      45             : 
      46             :         std::string toString() const {
      47             :           return shared_model::detail::PrettyStringBuilder()
      48             :               .init("VoteMessage")
      49             :               .append("yac hash", hash.toString())
      50             :               .append("signature",
      51             :                       signature ? signature->toString() : "not set")
      52             :               .finalize();
      53             :         }
      54             :       };
      55             : 
      56             :       /**
      57             :        * CommitMsg means consensus on cluster achieved.
      58             :        * All nodes deals on some solution
      59             :        */
      60             :       struct CommitMessage {
      61             :         explicit CommitMessage(std::vector<VoteMessage> votes)
      62         738 :             : votes(std::move(votes)) {}
      63             : 
      64             :         std::vector<VoteMessage> votes;
      65             : 
      66             :         bool operator==(const CommitMessage &rhs) const {
      67             :           return votes == rhs.votes;
      68             :         }
      69             : 
      70             :         std::string toString() const {
      71             :           return shared_model::detail::PrettyStringBuilder()
      72             :               .init("CommitMessage")
      73             :               .appendAll(
      74             :                   "votes", votes, [](auto vote) { return vote.toString(); })
      75             :               .finalize();
      76             :         }
      77             :       };
      78             : 
      79             :       /**
      80             :        * Reject means that there is impossible
      81             :        * to collect supermajority for any block
      82             :        */
      83             :       struct RejectMessage {
      84             :         explicit RejectMessage(std::vector<VoteMessage> votes)
      85           5 :             : votes(std::move(votes)) {}
      86             : 
      87             :         std::vector<VoteMessage> votes;
      88             : 
      89             :         bool operator==(const RejectMessage &rhs) const {
      90             :           return votes == rhs.votes;
      91             :         }
      92             : 
      93             :         std::string toString() const {
      94             :           return shared_model::detail::PrettyStringBuilder()
      95             :               .init("RejectMessage")
      96             :               .appendAll(
      97             :                   "votes", votes, [](auto vote) { return vote.toString(); })
      98             :               .finalize();
      99             :         }
     100             :       };
     101             :     }  // namespace yac
     102             :   }    // namespace consensus
     103             : }  // namespace iroha
     104             : #endif  // IROHA_MESSAGES_HPP

Generated by: LCOV version 1.13