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 : #ifndef IROHA_ORDERING_INIT_HPP
19 : #define IROHA_ORDERING_INIT_HPP
20 :
21 : #include "ametsuchi/block_query_factory.hpp"
22 : #include "ametsuchi/os_persistent_state_factory.hpp"
23 : #include "ametsuchi/peer_query_factory.hpp"
24 : #include "logger/logger.hpp"
25 : #include "ordering/impl/ordering_gate_impl.hpp"
26 : #include "ordering/impl/ordering_gate_transport_grpc.hpp"
27 : #include "ordering/impl/ordering_service_transport_grpc.hpp"
28 : #include "ordering/impl/single_peer_ordering_service.hpp"
29 :
30 : namespace iroha {
31 :
32 : namespace ametsuchi {
33 : class OrderingServicePersistentState;
34 : }
35 :
36 : namespace network {
37 :
38 : /**
39 : * Class aimed to effective initialization of OrderingGate component
40 : */
41 : class OrderingInit {
42 : private:
43 : /**
44 : * Init effective realisation of ordering gate (client of ordering
45 : * service)
46 : * @param transport - object which will be notified
47 : * about incoming proposals and send transactions
48 : * @param block_query_factory - block store factory to get last block
49 : * height
50 : * @return ordering gate
51 : */
52 : auto createGate(
53 : std::shared_ptr<OrderingGateTransport> transport,
54 : std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory);
55 :
56 : /**
57 : * Init ordering service
58 : * @param peer_query_factory - factory to get peer list
59 : * @param max_size - limitation of proposal size
60 : * @param delay_milliseconds - delay before emitting proposal
61 : * @param transport - ordering service transport
62 : * @param persistent_state - factory to access persistent state
63 : * @return ordering service
64 : */
65 : auto createService(
66 : std::shared_ptr<ametsuchi::PeerQueryFactory> peer_query_factory,
67 : size_t max_size,
68 : std::chrono::milliseconds delay_milliseconds,
69 : std::shared_ptr<network::OrderingServiceTransport> transport,
70 : std::shared_ptr<ametsuchi::OsPersistentStateFactory>
71 : persistent_state);
72 :
73 : public:
74 : /**
75 : * Initialization of ordering gate(client) and ordering service (service)
76 : * @param peer_query_factory - factory to get peer list
77 : * @param max_size - limitation of proposal size
78 : * @param delay_milliseconds - delay before emitting proposal
79 : * @param persistent_state - factory to access persistent state
80 : * @param block_query_factory - block store factory to get last block
81 : * height
82 : * @param transaction_batch_factory - factory to create transaction
83 : * batches
84 : * @param async_call - async grpc client that is passed to transport
85 : * components
86 : * @return efficient implementation of OrderingGate
87 : */
88 : std::shared_ptr<iroha::network::OrderingGate> initOrderingGate(
89 : std::shared_ptr<ametsuchi::PeerQueryFactory> peer_query_factory,
90 : size_t max_size,
91 : std::chrono::milliseconds delay_milliseconds,
92 : std::shared_ptr<ametsuchi::OsPersistentStateFactory> persistent_state,
93 : std::shared_ptr<ametsuchi::BlockQueryFactory> block_query_factory,
94 : std::shared_ptr<shared_model::interface::TransactionBatchFactory>
95 : transaction_batch_factory,
96 : std::shared_ptr<network::AsyncGrpcClient<google::protobuf::Empty>>
97 : async_call);
98 :
99 : std::shared_ptr<ordering::SinglePeerOrderingService> ordering_service;
100 : std::shared_ptr<iroha::network::OrderingGate> ordering_gate;
101 : std::shared_ptr<ordering::OrderingGateTransportGrpc>
102 : ordering_gate_transport;
103 : std::shared_ptr<ordering::OrderingServiceTransportGrpc>
104 : ordering_service_transport;
105 :
106 : protected:
107 0 : logger::Logger log_ = logger::log("OrderingInit");
108 : };
109 : } // namespace network
110 : } // namespace iroha
111 :
112 : #endif // IROHA_ORDERING_INIT_HPP
|