From c722df9dd2ecdb8e34a52ed7f59d7521434309f8 Mon Sep 17 00:00:00 2001 From: Andrei Lebedev Date: Sun, 2 Jul 2017 15:09:00 +0300 Subject: [PATCH] Add OrderingServiceStub and ConsensusServiceStub --- irohad/consensus/CMakeLists.txt | 9 +++- irohad/consensus/consensus_service.hpp | 48 +++++++++++++++++++++ irohad/consensus/consensus_service_stub.cpp | 37 ++++++++++++++++ irohad/consensus/consensus_service_stub.hpp | 39 +++++++++++++++++ irohad/network/network_api.h | 2 +- irohad/ordering/CMakeLists.txt | 10 ++++- irohad/ordering/ordering_service.hpp | 48 +++++++++++++++++++++ irohad/ordering/ordering_service_stub.cpp | 37 ++++++++++++++++ irohad/ordering/ordering_service_stub.hpp | 35 +++++++++++++++ libs/dao/account.hpp | 2 +- libs/dao/block.hpp | 2 +- libs/dao/dao.hpp | 4 +- libs/dao/{singature.hpp => signature.hpp} | 0 libs/dao/transaction.hpp | 1 + 14 files changed, 267 insertions(+), 7 deletions(-) create mode 100644 irohad/consensus/consensus_service.hpp create mode 100644 irohad/consensus/consensus_service_stub.cpp create mode 100644 irohad/consensus/consensus_service_stub.hpp create mode 100644 irohad/ordering/ordering_service.hpp create mode 100644 irohad/ordering/ordering_service_stub.cpp create mode 100644 irohad/ordering/ordering_service_stub.hpp rename libs/dao/{singature.hpp => signature.hpp} (100%) diff --git a/irohad/consensus/CMakeLists.txt b/irohad/consensus/CMakeLists.txt index 8f3df72a3e..d9388faad7 100644 --- a/irohad/consensus/CMakeLists.txt +++ b/irohad/consensus/CMakeLists.txt @@ -25,4 +25,11 @@ target_link_libraries(sumeragi timer logger rxcpp - ) \ No newline at end of file + ) + +add_library(consensus_service + consensus_service_stub.cpp + ) +target_link_libraries(consensus_service + rxcpp + ) \ No newline at end of file diff --git a/irohad/consensus/consensus_service.hpp b/irohad/consensus/consensus_service.hpp new file mode 100644 index 0000000000..149fe75830 --- /dev/null +++ b/irohad/consensus/consensus_service.hpp @@ -0,0 +1,48 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_CONSENSUS_SERVICE_HPP +#define IROHA_CONSENSUS_SERVICE_HPP + +#include +#include +#include + +namespace iroha { + namespace consensus { + /** + * Consensus interface for peer communication service + */ + class ConsensusService { + public: + + /** + * Propagate a block formed from proposal + * @param block + */ + virtual void propagate_block(dao::Block &block) = 0; + + /** + * Return observable of all commits from the consensus + * @return + */ + virtual rxcpp::observable> on_commit() = 0; + }; + } // namespace consensus +} // namespace iroha + +#endif //IROHA_CONSENSUS_SERVICE_HPP diff --git a/irohad/consensus/consensus_service_stub.cpp b/irohad/consensus/consensus_service_stub.cpp new file mode 100644 index 0000000000..2ed2e45051 --- /dev/null +++ b/irohad/consensus/consensus_service_stub.cpp @@ -0,0 +1,37 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace iroha { + namespace consensus { + + using dao::Transaction; + using dao::Proposal; + using dao::Block; + + rxcpp::observable> + ConsensusServiceStub::on_commit() { + return commits_.get_observable(); + } + + void ConsensusServiceStub::propagate_block(dao::Block &block) { + commits_.get_subscriber().on_next(rxcpp::observable<>::from(block)); + } + + } // namespace consensus +} // namespace iroha \ No newline at end of file diff --git a/irohad/consensus/consensus_service_stub.hpp b/irohad/consensus/consensus_service_stub.hpp new file mode 100644 index 0000000000..77997a41a9 --- /dev/null +++ b/irohad/consensus/consensus_service_stub.hpp @@ -0,0 +1,39 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_CONSENSUS_SERVICE_STUB_HPP +#define IROHA_CONSENSUS_SERVICE_STUB_HPP + +#include +#include +#include +#include + +namespace iroha { + namespace consensus { + class ConsensusServiceStub : public ConsensusService { + public: + void propagate_block(dao::Block &block) override; + rxcpp::observable> on_commit() override; + + private: + rxcpp::subjects::subject> commits_; + }; + } // namespace consensus +} // namespace iroha + +#endif // IROHA_CONSENSUS_SERVICE_STUB_HPP diff --git a/irohad/network/network_api.h b/irohad/network/network_api.h index a93112f39b..67646dc106 100644 --- a/irohad/network/network_api.h +++ b/irohad/network/network_api.h @@ -50,7 +50,7 @@ namespace iroha { class TransactionPropagator { public: /** - * Method spreads transaction to other members of a network + * Method spreads transaction to other members of a network * @param tx - transaction for propagation */ virtual void propagate_transaction(dao::Transaction &tx) = 0; diff --git a/irohad/ordering/CMakeLists.txt b/irohad/ordering/CMakeLists.txt index 087551d798..39b890e320 100644 --- a/irohad/ordering/CMakeLists.txt +++ b/irohad/ordering/CMakeLists.txt @@ -22,4 +22,12 @@ target_link_libraries(ordering ordering_service consensus_service ordering_connection -) \ No newline at end of file +) + +add_library(ordering_service + ordering_service_stub.cpp + ) + +target_link_libraries(ordering_service + rxcpp + ) \ No newline at end of file diff --git a/irohad/ordering/ordering_service.hpp b/irohad/ordering/ordering_service.hpp new file mode 100644 index 0000000000..4474a3670e --- /dev/null +++ b/irohad/ordering/ordering_service.hpp @@ -0,0 +1,48 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_ORDERING_SERVICE_HPP +#define IROHA_ORDERING_SERVICE_HPP + +#include +#include +#include + +namespace iroha { + namespace ordering { + /** + * Ordering service interface for peer communication service + */ + class OrderingService { + public: + + /** + * Propagate a signed transaction for further processing + * @param transaction + */ + virtual void propagate_transaction(dao::Transaction &transaction) = 0; + + /** + * Return observable of all proposals in the consensus + * @return + */ + virtual rxcpp::observable on_proposal() = 0; + }; + }//namespace ordering +}// namespace iroha + +#endif //IROHA_ORDERING_SERVICE_HPP diff --git a/irohad/ordering/ordering_service_stub.cpp b/irohad/ordering/ordering_service_stub.cpp new file mode 100644 index 0000000000..ec370eaab3 --- /dev/null +++ b/irohad/ordering/ordering_service_stub.cpp @@ -0,0 +1,37 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace iroha { + namespace ordering { + + using dao::Transaction; + using dao::Proposal; + + void OrderingServiceStub::propagate_transaction( + dao::Transaction &transaction) { + std::vector transactions{transaction}; + Proposal proposal(transactions); + proposals_.get_subscriber().on_next(proposal); + } + + rxcpp::observable OrderingServiceStub::on_proposal() { + return proposals_.get_observable(); + } + } // namespace ordering +} // namespace iroha \ No newline at end of file diff --git a/irohad/ordering/ordering_service_stub.hpp b/irohad/ordering/ordering_service_stub.hpp new file mode 100644 index 0000000000..5464bbedd0 --- /dev/null +++ b/irohad/ordering/ordering_service_stub.hpp @@ -0,0 +1,35 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_ORDERING_SERVICE_STUB_HPP +#define IROHA_ORDERING_SERVICE_STUB_HPP + +#include + +namespace iroha { + namespace ordering { + class OrderingServiceStub : public OrderingService { + public: + void propagate_transaction(dao::Transaction &transaction) override; + rxcpp::observable on_proposal() override; + private: + rxcpp::subjects::subject proposals_; + }; + }//namespace ordering +}// namespace iroha + +#endif //IROHA_ORDERING_SERVICE_STUB_HPP diff --git a/libs/dao/account.hpp b/libs/dao/account.hpp index 7b82c05e9e..703d941c47 100644 --- a/libs/dao/account.hpp +++ b/libs/dao/account.hpp @@ -16,7 +16,7 @@ limitations under the License. #ifndef IROHA_ACCOUNT_HPP #define IROHA_ACCOUNT_HPP -#include "singature.hpp" +#include "signature.hpp" namespace iroha { namespace dao { diff --git a/libs/dao/block.hpp b/libs/dao/block.hpp index 7db45cd52f..e20f39b19b 100644 --- a/libs/dao/block.hpp +++ b/libs/dao/block.hpp @@ -19,7 +19,7 @@ limitations under the License. #include #include -#include "singature.hpp" +#include "signature.hpp" #include "transaction.hpp" namespace iroha { diff --git a/libs/dao/dao.hpp b/libs/dao/dao.hpp index 61ecce917f..0634bb178e 100644 --- a/libs/dao/dao.hpp +++ b/libs/dao/dao.hpp @@ -25,13 +25,13 @@ #include "account.hpp" #include "wallet.hpp" #include "peer.hpp" -#include "singature.hpp" +#include "signature.hpp" #include "domain.hpp" #include "client.hpp" #include "query_response.hpp" #include "peer.hpp" -#include "singature.hpp" +#include "signature.hpp" #include "dao_crypto_provider.hpp" #include "dao_hash_provider.hpp" diff --git a/libs/dao/singature.hpp b/libs/dao/signature.hpp similarity index 100% rename from libs/dao/singature.hpp rename to libs/dao/signature.hpp diff --git a/libs/dao/transaction.hpp b/libs/dao/transaction.hpp index eff19fb87a..f4bcf7a8e1 100644 --- a/libs/dao/transaction.hpp +++ b/libs/dao/transaction.hpp @@ -21,6 +21,7 @@ limitations under the License. #include #include #include +#include namespace iroha { namespace dao {