Skip to content

Commit

Permalink
Add OrderingServiceStub and ConsensusServiceStub
Browse files Browse the repository at this point in the history
  • Loading branch information
lebdron committed Jul 2, 2017
1 parent db2b285 commit c722df9
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 7 deletions.
9 changes: 8 additions & 1 deletion irohad/consensus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ target_link_libraries(sumeragi
timer
logger
rxcpp
)
)

add_library(consensus_service
consensus_service_stub.cpp
)
target_link_libraries(consensus_service
rxcpp
)
48 changes: 48 additions & 0 deletions irohad/consensus/consensus_service.hpp
Original file line number Diff line number Diff line change
@@ -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 <dao/proposal.hpp>
#include <dao/block.hpp>
#include <rxcpp/rx-observable.hpp>

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<rxcpp::observable<dao::Block>> on_commit() = 0;
};
} // namespace consensus
} // namespace iroha

#endif //IROHA_CONSENSUS_SERVICE_HPP
37 changes: 37 additions & 0 deletions irohad/consensus/consensus_service_stub.cpp
Original file line number Diff line number Diff line change
@@ -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 <consensus/consensus_service_stub.hpp>

namespace iroha {
namespace consensus {

using dao::Transaction;
using dao::Proposal;
using dao::Block;

rxcpp::observable<rxcpp::observable<dao::Block>>
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
39 changes: 39 additions & 0 deletions irohad/consensus/consensus_service_stub.hpp
Original file line number Diff line number Diff line change
@@ -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 <ametsuchi/ametsuchi.hpp>
#include <consensus/consensus_service.hpp>
#include <validation/chain/validator.hpp>
#include <validation/stateful/validator.hpp>

namespace iroha {
namespace consensus {
class ConsensusServiceStub : public ConsensusService {
public:
void propagate_block(dao::Block &block) override;
rxcpp::observable<rxcpp::observable<dao::Block>> on_commit() override;

private:
rxcpp::subjects::subject<rxcpp::observable<dao::Block>> commits_;
};
} // namespace consensus
} // namespace iroha

#endif // IROHA_CONSENSUS_SERVICE_STUB_HPP
2 changes: 1 addition & 1 deletion irohad/network/network_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion irohad/ordering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ target_link_libraries(ordering
ordering_service
consensus_service
ordering_connection
)
)

add_library(ordering_service
ordering_service_stub.cpp
)

target_link_libraries(ordering_service
rxcpp
)
48 changes: 48 additions & 0 deletions irohad/ordering/ordering_service.hpp
Original file line number Diff line number Diff line change
@@ -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 <dao/transaction.hpp>
#include <dao/proposal.hpp>
#include <rxcpp/rx-observable.hpp>

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<dao::Proposal> on_proposal() = 0;
};
}//namespace ordering
}// namespace iroha

#endif //IROHA_ORDERING_SERVICE_HPP
37 changes: 37 additions & 0 deletions irohad/ordering/ordering_service_stub.cpp
Original file line number Diff line number Diff line change
@@ -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 <ordering/ordering_service_stub.hpp>

namespace iroha {
namespace ordering {

using dao::Transaction;
using dao::Proposal;

void OrderingServiceStub::propagate_transaction(
dao::Transaction &transaction) {
std::vector<Transaction> transactions{transaction};
Proposal proposal(transactions);
proposals_.get_subscriber().on_next(proposal);
}

rxcpp::observable<dao::Proposal> OrderingServiceStub::on_proposal() {
return proposals_.get_observable();
}
} // namespace ordering
} // namespace iroha
35 changes: 35 additions & 0 deletions irohad/ordering/ordering_service_stub.hpp
Original file line number Diff line number Diff line change
@@ -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 <ordering/ordering_service.hpp>

namespace iroha {
namespace ordering {
class OrderingServiceStub : public OrderingService {
public:
void propagate_transaction(dao::Transaction &transaction) override;
rxcpp::observable<dao::Proposal> on_proposal() override;
private:
rxcpp::subjects::subject<dao::Proposal> proposals_;
};
}//namespace ordering
}// namespace iroha

#endif //IROHA_ORDERING_SERVICE_STUB_HPP
2 changes: 1 addition & 1 deletion libs/dao/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libs/dao/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

#include <common/types.hpp>
#include <vector>
#include "singature.hpp"
#include "signature.hpp"
#include "transaction.hpp"

namespace iroha {
Expand Down
4 changes: 2 additions & 2 deletions libs/dao/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions libs/dao/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include <dao/command.hpp>
#include <memory>
#include <vector>
#include <dao/signature.hpp>

namespace iroha {
namespace dao {
Expand Down

0 comments on commit c722df9

Please sign in to comment.