Skip to content

Commit

Permalink
adapt to intializer
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Sep 4, 2024
1 parent 905ac0f commit 15cf2e9
Show file tree
Hide file tree
Showing 47 changed files with 691 additions and 660 deletions.
3 changes: 2 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ set(ALL_SOURCE_LIST
wedpr-storage/ppc-io wedpr-storage/ppc-storage
wedpr-transport/ppc-gateway wedpr-transport/ppc-front
wedpr-transport/ppc-http wedpr-transport/ppc-rpc wedpr-transport/sdk
wedpr-computing/ppc-psi wedpr-computing/ppc-mpc wedpr-computing/ppc-pir ${CEM_SOURCE})
wedpr-computing/ppc-psi wedpr-computing/ppc-mpc wedpr-computing/ppc-pir ${CEM_SOURCE}
wedpr-initializer wedpr-main)

if(BUILD_WEDPR_TOOLKIT)
# fetch the python dependencies
Expand Down
4 changes: 2 additions & 2 deletions cpp/cmake/TargetSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ set(RPC_TARGET "ppc-rpc")
# libhelper
set(HELPER_TARGET "ppc-helper")

# libinitializer
set(INIT_LIB init)
# wedpr-initializer
set(INIT_LIB "wedpr-inititializer")

# ppc-cem
set(CEM_TARGET "ppc-cem")
Expand Down
55 changes: 38 additions & 17 deletions cpp/ppc-framework/front/FrontConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

#pragma once
#include "ppc-framework/protocol/EndPoint.h"
#include "ppc-framework/protocol/GrpcConfig.h"
#include "ppc-framework/protocol/INodeInfo.h"
#include <memory>
#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -49,40 +52,58 @@ class FrontConfig

virtual void appendGatewayInfo(ppc::protocol::EndPoint&& endpoint)
{
// TODO:check the endpoint
m_gatewayInfo.push_back(endpoint);
}

ppc::protocol::EndPoint const& selfEndPoint() const { return m_selfEndPoint; }
void setSelfEndPoint(ppc::protocol::EndPoint const& endPoint) { m_selfEndPoint = endPoint; }

// TODO here
std::string gatewayEndPoints() { return ""; }
// refer to: https://github.com/grpc/grpc-node/issues/2066
// grpc prefer to using ipv4:${host1}:${port1},${host2}:${port2} as target to support multiple
// servers
std::string gatewayGrpcTarget()
{
std::stringstream oss;
oss << "ipv4:";
for (auto const& endPoint : m_gatewayInfo)
{
oss << endPoint.entryPoint() << ",";
}
return oss.str();
}

std::string const& loadBalancePolicy() const { return m_loadBanlancePolicy; }
void setLoadBalancePolicy(std::string const& loadBanlancePolicy)
void setGrpcConfig(ppc::protocol::GrpcConfig::Ptr grpcConfig)
{
m_loadBanlancePolicy = loadBanlancePolicy;
m_grpcConfig = std::move(grpcConfig);
}
ppc::protocol::GrpcConfig::Ptr const& grpcConfig() const { return m_grpcConfig; }

// generate the nodeInfo
virtual ppc::protocol::INodeInfo::Ptr generateNodeInfo() const = 0;

virtual std::vector<std::string> const& getComponents() const { return m_components; }
void setComponents(std::vector<std::string> const& components) { m_components = components; }

private:
std::string m_loadBanlancePolicy = "round_robin";
protected:
ppc::protocol::GrpcConfig::Ptr m_grpcConfig;
ppc::protocol::EndPoint m_selfEndPoint;
int m_threadPoolSize;
std::string m_nodeID;
std::vector<ppc::protocol::EndPoint> m_gatewayInfo;
std::vector<std::string> m_components;
};

class FrontConfigBuilder
inline std::string printFrontDesc(FrontConfig::Ptr const& config)
{
public:
using Ptr = std::shared_ptr<FrontConfigBuilder>;
FrontConfigBuilder() = default;
virtual ~FrontConfigBuilder() = default;

FrontConfig::Ptr build(int threadPoolSize, std::string nodeID)
if (!config)
{
return std::make_shared<FrontConfig>(threadPoolSize, nodeID);
return "nullptr";
}
};
std::ostringstream stringstream;
stringstream << LOG_KV("endPoint", config->selfEndPoint().entryPoint())
<< LOG_KV("nodeID", config->nodeID())
<< LOG_KV("poolSize", config->threadPoolSize())
<< LOG_KV("target", config->gatewayGrpcTarget());
return stringstream.str();
}
} // namespace ppc::front
5 changes: 2 additions & 3 deletions cpp/ppc-framework/front/FrontInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class FrontInterface
virtual void asyncSendResponse(const std::string& _agencyID, std::string const& _uuid,
front::PPCMessageFace::Ptr _message, ErrorCallbackFunc _callback) = 0;

virtual void registerMessageHandler(uint8_t _taskType, uint8_t _algorithmType,
std::function<void(front::PPCMessageFace::Ptr)> _handler) = 0;
/**
* @brief notice task info to gateway
* @param _taskInfo the latest task information
Expand All @@ -69,9 +71,6 @@ class FrontInterface
// erase the task-info when task finished
virtual bcos::Error::Ptr eraseTaskInfo(std::string const& _taskID) = 0;

// get the agencyList from the gateway
virtual void asyncGetAgencyList(GetAgencyListCallback _callback) = 0;

virtual std::string const& selfEndPoint() const { return m_selfEndPoint; }

protected:
Expand Down
9 changes: 1 addition & 8 deletions cpp/ppc-framework/front/IFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IFrontClient
virtual void onReceiveMessage(
ppc::protocol::Message::Ptr const& _msg, ppc::protocol::ReceiveMsgFunc _callback) = 0;
};
class IFront : public virtual IFrontClient
class IFront : virtual public IFrontClient
{
public:
using Ptr = std::shared_ptr<IFront>;
Expand Down Expand Up @@ -132,13 +132,6 @@ class IFrontBuilder
IFrontBuilder() = default;
virtual ~IFrontBuilder() = default;

/**
* @brief create the Front using specified config
*
* @param config the config used to build the Front
* @return IFront::Ptr he created Front
*/
virtual IFront::Ptr build(ppc::front::FrontConfig::Ptr config) const = 0;
virtual IFrontClient::Ptr buildClient(std::string endPoint) const = 0;
};
} // namespace ppc::front
42 changes: 42 additions & 0 deletions cpp/ppc-framework/protocol/GrpcConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (C) 2023 WeDPR.
* SPDX-License-Identifier: Apache-2.0
* 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.
*
* @file GrpcConfig.h
* @author: yujiechen
* @date 2024-09-02
*/
#pragma once
#include <memory>
#include <string>

namespace ppc::protocol
{
class GrpcConfig
{
public:
using Ptr = std::shared_ptr<GrpcConfig>;
GrpcConfig() = default;
virtual ~GrpcConfig() = default;

std::string const& loadBalancePolicy() const { return m_loadBanlancePolicy; }
void setLoadBalancePolicy(std::string const& loadBanlancePolicy)
{
m_loadBanlancePolicy = loadBanlancePolicy;
}

private:
std::string m_loadBanlancePolicy = "round_robin";
};
} // namespace ppc::protocol
3 changes: 0 additions & 3 deletions cpp/ppc-framework/rpc/RpcStatusInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

namespace ppc::rpc
{

class RpcStatusInterface
{
public:
Expand All @@ -45,8 +44,6 @@ class RpcStatusInterface
virtual bcos::Error::Ptr insertTask(protocol::Task::Ptr _task) = 0;
virtual bcos::Error::Ptr updateTaskStatus(protocol::TaskResult::Ptr _taskResult) = 0;
virtual protocol::TaskResult::Ptr getTaskStatus(const std::string& _taskID) = 0;
virtual bcos::Error::Ptr insertGateway(
const std::string& _agencyID, const std::string& _endpoint) = 0;
virtual bcos::Error::Ptr deleteGateway(const std::string& _agencyID) = 0;
virtual std::vector<protocol::GatewayInfo> listGateway() = 0;
};
Expand Down
1 change: 0 additions & 1 deletion cpp/ppc-framework/rpc/RpcTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ enum class RpcError : int32_t
std::string const RUN_TASK_METHOD = "runTask";
std::string const ASYNC_RUN_TASK_METHOD = "asyncRunTask";
std::string const GET_TASK_STATUS = "getTaskStatus";
std::string const REGISTER_GATEWAY_URL = "registerGatewayUrl";

std::string const ASYNC_RUN_BS_MODE_TASK = "asyncRunBsModeTask";
std::string const FETCH_CIPHER = "fetchCipher";
Expand Down
1 change: 0 additions & 1 deletion cpp/test-utils/FakeFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class FakeFront : public FrontInterface
}
}

void asyncGetAgencyList(GetAgencyListCallback) override {}

private:
// the uuid to _callback
Expand Down
11 changes: 1 addition & 10 deletions cpp/wedpr-computing/ppc-psi/src/PSIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@ class PSIConfig
int taskExpireTime() const { return m_taskExpireTime; }
void setTaskExpireTime(int _taskExpireTime) { m_taskExpireTime = _taskExpireTime; }

void updateAgenyList(std::vector<std::string> const& _agencyList)
{
bcos::UpgradableGuard l(x_agencyList);
if (m_agencyList != _agencyList)
{
bcos::UpgradeGuard ul(l);
m_agencyList = _agencyList;
}
}

std::vector<std::string> agencyList() const
{
bcos::ReadGuard l(x_agencyList);
Expand Down Expand Up @@ -165,6 +155,7 @@ class PSIConfig
int m_taskExpireTime = 10000;

// the agency list, for task-sync
// TODO: fetch from the gateway
std::vector<std::string> m_agencyList;
mutable bcos::SharedMutex x_agencyList;
};
Expand Down
10 changes: 10 additions & 0 deletions cpp/wedpr-helper/ppc-tools/src/config/PPCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Common.h"
#include "NetworkConfig.h"
#include "ParamChecker.h"
#include "ppc-framework/front/FrontConfig.h"
#include "ppc-framework/storage/CacheStorage.h"
#include <bcos-utilities/Common.h>
#include <memory.h>
Expand Down Expand Up @@ -244,6 +245,10 @@ class PPCConfig

int holdingMessageMinutes() const { return m_holdingMessageMinutes; }

ppc::front::FrontConfig::Ptr const& frontConfig() const { return m_frontConfig; }

ppc::protocol::GrpcConfig::Ptr const& grpcConfig() const { return m_grpcConfig; }

private:
virtual void loadRA2018Config(boost::property_tree::ptree const& _pt);
virtual void loadEcdhPSIConfig(boost::property_tree::ptree const& _pt);
Expand Down Expand Up @@ -283,6 +288,11 @@ class PPCConfig
// the gateway holding message time, in minutes, default 30min
int m_holdingMessageMinutes = 30;

// the front config
// TODO: parse the frontConfig
ppc::front::FrontConfig::Ptr m_frontConfig;
ppc::protocol::GrpcConfig::Ptr m_grpcConfig;

// the ra2018-psi config
RA2018Config m_ra2018PSIConfig;
// the storage config
Expand Down
5 changes: 4 additions & 1 deletion cpp/wedpr-initializer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
file(GLOB SRC_LIST "*.cpp")

add_library(${INIT_LIB} ${SRC_LIST})
target_link_libraries(${INIT_LIB} PUBLIC ${PROTOCOL_TARGET} ${CRYPTO_TARGET} ${FRONT_TARGET} ${LABELED_PSI_TARGET} ${RA2018_PSI_TARGET} ${CM2020_PSI_TARGET} ${ECDH_2PC_PSI_TARGET} ${ECDH_MULTI_PSI_TARGET} ${ECDH_CONN_PSI_TARGET} ${BS_ECDH_PSI_TARGET} ${PIR_TARGET} ${IO_TARGET} ${STORAGE_TARGET})
target_link_libraries(${INIT_LIB} PUBLIC
${PROTOCOL_TARGET} ${CRYPTO_TARGET} ${WEDPR_TRANSPORT_SDK_TARGET} ${LABELED_PSI_TARGET}
${RA2018_PSI_TARGET} ${CM2020_PSI_TARGET} ${ECDH_2PC_PSI_TARGET}
${ECDH_MULTI_PSI_TARGET} ${ECDH_CONN_PSI_TARGET} ${BS_ECDH_PSI_TARGET} ${PIR_TARGET} ${IO_TARGET} ${STORAGE_TARGET})
74 changes: 0 additions & 74 deletions cpp/wedpr-initializer/FrontInitializer.cpp

This file was deleted.

Loading

0 comments on commit 15cf2e9

Please sign in to comment.