1818 * @date 2023-03-24
1919 */
2020#include " MPCInitializer.h"
21+ #include " ppc-framework/front/FrontConfig.h"
22+ #include " ppc-framework/protocol/ServiceType.h"
2123#include " ppc-mpc/src/MPCService.h"
2224#include " ppc-tools/src/config/PPCConfig.h"
25+ #include " wedpr-protocol/protocol/src/ServiceConfig.h"
26+ #include " wedpr-transport/sdk/src/TransportBuilder.h"
2327
2428using namespace ppc ::rpc;
2529using namespace bcos ;
30+ using namespace ppc ::sdk;
2631using namespace ppc ::mpc;
2732using namespace ppc ::tools;
33+ using namespace ppc ::front;
34+ using namespace ppc ::protocol;
35+
36+ MPCInitializer::MPCInitializer () : m_transportBuilder(std::make_shared<TransportBuilder>()) {}
2837
29- // / TODO: mpc support the gateway
3038void MPCInitializer::init (std::string const & _configPath)
3139{
3240 // init the log
@@ -40,28 +48,54 @@ void MPCInitializer::init(std::string const& _configPath)
4048 // init the rpc
4149 INIT_LOG (INFO) << LOG_DESC (" init the rpc" );
4250 // load the rpc config
43- auto ppcConfig = std::make_shared<PPCConfig>();
44- ppcConfig ->loadRpcConfig (pt);
45- ppcConfig ->loadMPCConfig (pt);
51+ m_config = std::make_shared<PPCConfig>();
52+ m_config ->loadRpcConfig (pt);
53+ m_config ->loadMPCConfig (pt);
4654 // bool useMysql = pt.get<bool>("mpc.use_mysql", false);
47- auto storageConfig = ppcConfig ->storageConfig ();
48- auto mpcConfig = ppcConfig ->mpcConfig ();
49- auto rpcFactory = std::make_shared<RpcFactory>(ppcConfig ->agencyID ());
50- m_rpc = rpcFactory->buildRpc (ppcConfig , nullptr );
55+ auto storageConfig = m_config ->storageConfig ();
56+ auto mpcConfig = m_config ->mpcConfig ();
57+ auto rpcFactory = std::make_shared<RpcFactory>(m_config ->agencyID ());
58+ m_rpc = rpcFactory->buildRpc (m_config , nullptr );
5159 auto mpcService = std::make_shared<MPCService>();
5260 mpcService->setMPCConfig (mpcConfig);
5361 mpcService->setStorageConfig (storageConfig);
5462 m_rpc->registerHandler (" run" , std::bind (&MPCService::runMpcRpc, mpcService,
5563 std::placeholders::_1, std::placeholders::_2));
5664 m_rpc->registerHandler (" kill" , std::bind (&MPCService::killMpcRpc, mpcService,
5765 std::placeholders::_1, std::placeholders::_2));
66+ INIT_LOG (INFO) << LOG_DESC (" init the mpc rpc success" );
67+ // init the transport
68+ initTransport (pt);
69+ }
5870
71+ void MPCInitializer::initTransport (boost::property_tree::ptree const & property)
72+ {
73+ INIT_LOG (INFO) << LOG_DESC (" initTransport: load front config" );
74+ m_config->loadFrontConfig (true , m_transportBuilder->frontConfigBuilder (), property);
75+ INIT_LOG (INFO) << LOG_DESC (" initTransport: load front config success" );
5976
60- INIT_LOG (INFO) << LOG_DESC (" init the mpc rpc success" );
77+ // add the service meta
78+ ServiceConfigBuilder serviceConfigBuilder;
79+ auto entryPoint =
80+ serviceConfigBuilder.buildEntryPoint (MPC_SERVICE_TYPE, m_config->accessEntrypoint ());
81+ auto serviceConfig = serviceConfigBuilder.buildServiceConfig ();
82+ serviceConfig.addEntryPoint (entryPoint);
83+ auto serviceMeta = serviceConfig.encode ();
84+ m_config->frontConfig ()->setMeta (serviceMeta);
85+ INIT_LOG (INFO) << LOG_DESC (" initTransport: register serviceMeta" )
86+ << LOG_KV (" serviceMeta" , serviceMeta);
87+ INIT_LOG (INFO) << LOG_DESC (" initTransport: buildProTransport" );
88+ m_transport = m_transportBuilder->buildProTransport (m_config->frontConfig ());
89+ INIT_LOG (INFO) << LOG_DESC (" initTransport: buildProTransport success" );
6190}
6291
6392void MPCInitializer::start ()
6493{
94+ // start the transport
95+ if (m_transport)
96+ {
97+ m_transport->start ();
98+ }
6599 // start the ppc mpc
66100 if (m_rpc)
67101 {
@@ -75,4 +109,8 @@ void MPCInitializer::stop()
75109 {
76110 m_rpc->stop ();
77111 }
112+ if (m_transport)
113+ {
114+ m_transport->stop ();
115+ }
78116}
0 commit comments