Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add front implementation #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ project(WeDPR-Component VERSION ${VERSION})

include(CompilerSettings)
include(BuildInfoGenerator)
set(PROTO_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/generated/pb)

include(IncludeDirectories)
# the target settings
Expand All @@ -67,17 +68,24 @@ set(JNI_SOURCE_PATH wedpr-component-sdk/bindings/java/src/main/c)
set(SDK_SOURCE_LIST ppc-homo ppc-crypto-core wedpr-component-sdk ${JNI_SOURCE_PATH})
# Note: the udf depends on mysql, not enabled in the full node mode
set(UDF_SOURCE_LIST ${SDK_SOURCE_LIST} ppc-udf)
set(ALL_SOURCE_LIST
${SDK_SOURCE_LIST} ppc-crypto
libhelper libinitializer ppc-io ppc-protocol
ppc-gateway ppc-front ppc-tars-protocol
ppc-tools ppc-storage ppc-psi ppc-rpc
ppc-http ppc-mpc ppc-pir
${CEM_SOURCE} ppc-main)
set(CEM_SOURCE "")
if(BUILD_CEM)
set(CEM_SOURCE "ppc-cem")
endif()
#set(ALL_SOURCE_LIST
# ${SDK_SOURCE_LIST} ppc-crypto
# libhelper libinitializer ppc-io ppc-protocol
# ppc-gateway ppc-front ppc-tars-protocol
# ppc-tools ppc-storage ppc-psi ppc-rpc
# ppc-http ppc-mpc ppc-pir
# ${CEM_SOURCE} ppc-main)

set(ALL_SOURCE_LIST
${SDK_SOURCE_LIST} ppc-crypto
libhelper ppc-io wedpr-protocol
ppc-gateway ppc-front
ppc-tools ppc-storage ppc-psi ppc-rpc
ppc-http ppc-mpc ppc-pir ${CEM_SOURCE})

if(BUILD_WEDPR_TOOLKIT)
# fetch the python dependencies
Expand Down
1 change: 1 addition & 0 deletions cpp/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if(BUILD_ALL)

find_package(SEAL REQUIRED)
find_package(Kuku REQUIRED)
find_package(gRPC REQUIRED)

# APSI: Note: APSI depends on seal 4.0 and Kuku 2.1
include(ProjectAPSI)
Expand Down
3 changes: 2 additions & 1 deletion cpp/cmake/IncludeDirectories.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_BINARY_DIR}/generated/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-protocol)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-front)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-gateway)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-component-sdk)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-tars-protocol)
include_directories(${PROTO_OUTPUT_PATH})

set(VCPKG_INCLUDE_PATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
include_directories(${VCPKG_INCLUDE_PATH})
11 changes: 9 additions & 2 deletions cpp/cmake/TargetSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ set(TOOLS_TARGET "ppc-tools")
# ppc-protocol
set(PROTOCOL_TARGET "ppc-protocol")

# ppc-tars-protocol
set(TARS_PROTOCOL_TARGET "ppc-protocol-tars")
# wedpr-protocol/tars
set(TARS_PROTOCOL_TARGET "wedpr-tars-protocol")

# wedpr-protocol/protobuf
set(PB_PROTOCOL_TARGET "wedpr-pb-protocol")

# wedpr-protocol/grpc-client
set(SERVICE_CLIENT_TARGET "service-client")
set(SERVICE_CLIENT_PB_TARGET "service-client-pb")

# ppc-front
SET(FRONT_TARGET "ppc-front")
Expand Down
2 changes: 1 addition & 1 deletion cpp/libinitializer/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "ppc-framework/protocol/Protocol.h"
#include "ppc-pir/src/OtPIRFactory.h"
#include "ppc-pir/src/OtPIRImpl.h"
#include "ppc-protocol/src/PPCMessage.h"
#include "ppc-psi/src/bs-ecdh-psi/BsEcdhPSIFactory.h"
#include "ppc-psi/src/cm2020-psi/CM2020PSIFactory.h"
#include "protocol/src/PPCMessage.h"
#if 0
//TODO: optimize here
#include "ppc-psi/src/ecdh-conn-psi/EcdhConnPSIFactory.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/libinitializer/ProtocolInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "ppc-framework/protocol/GlobalConfig.h"
#include "ppc-framework/protocol/PPCMessageFace.h"
#include "ppc-io/src/DataResourceLoaderImpl.h"
#include "ppc-protocol/src/PPCMessage.h"
#include "ppc-storage/src/FileStorageFactoryImpl.h"
#include "ppc-storage/src/SQLStorageFactoryImpl.h"
#include "ppc-tools/src/config/PPCConfig.h"
#include "protocol/src/PPCMessage.h"
#include <bcos-utilities/Common.h>
#include <memory>

Expand Down
2 changes: 1 addition & 1 deletion cpp/ppc-framework/front/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Channel
* @brief notice task info to gateway by front
* @param _taskInfo the latest task information
*/
virtual bcos::Error::Ptr notifyTaskInfo(protocol::GatewayTaskInfo::Ptr _taskInfo) = 0;
virtual bcos::Error::Ptr notifyTaskInfo(std::string const& taskID) = 0;

/**
* @brief: send message
Expand Down
18 changes: 2 additions & 16 deletions cpp/ppc-framework/front/FrontInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ class FrontInterface
using Ptr = std::shared_ptr<FrontInterface>;
FrontInterface() = default;
virtual ~FrontInterface() {}
/**
* @brief: start/stop service
*/
virtual void start() = 0;
virtual void stop() = 0;

/**
* @brief: receive message from gateway, call by gateway
* @param _message: received ppc message
* @return void
*/
virtual void onReceiveMessage(
front::PPCMessageFace::Ptr _message, ErrorCallbackFunc _callback) = 0;


/**
* @brief: send message to other party by gateway
Expand All @@ -78,11 +64,11 @@ class FrontInterface
* @brief notice task info to gateway
* @param _taskInfo the latest task information
*/
virtual bcos::Error::Ptr notifyTaskInfo(protocol::GatewayTaskInfo::Ptr _taskInfo) = 0;
virtual bcos::Error::Ptr notifyTaskInfo(std::string const& taskID) = 0;

// 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;

Expand Down
80 changes: 59 additions & 21 deletions cpp/ppc-framework/front/IFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,47 @@
*/
#pragma once
#include "FrontConfig.h"
#include "ppc-framework/protocol/INodeInfo.h"
#include "ppc-framework/protocol/Message.h"
#include "ppc-framework/protocol/RouteType.h"
#include <bcos-utilities/Error.h>

namespace ppc::front
{
class IFront
class IFrontClient
{
public:
using Ptr = std::shared_ptr<IFrontClient>;
IFrontClient() = default;
virtual ~IFrontClient() = default;
/**
* @brief: receive message from gateway, call by gateway
* @param _message: received ppc message
* @return void
*/
virtual void onReceiveMessage(
ppc::protocol::Message::Ptr const& _msg, ppc::protocol::ReceiveMsgFunc _callback) = 0;
};
class IFront : public virtual IFrontClient
{
public:
using Ptr = std::shared_ptr<IFront>;

IFront() = default;
virtual ~IFront() = default;
~IFront() override = default;

/**
* @brief start the IFront
*
* @param front the IFront to start
*/
virtual void start() const = 0;
virtual void start() = 0;
/**
* @brief stop the IFront
*
* @param front the IFront to stop
*/
virtual void stop() const = 0;
virtual void stop() = 0;

/**
*
Expand All @@ -53,38 +68,61 @@ class IFront
* @param callback the callback called when receive specified topic
*/
virtual void registerTopicHandler(
std::string const& topic, ppc::protocol::MessageCallback callback) = 0;
std::string const& topic, ppc::protocol::MessageDispatcherCallback callback) = 0;

/**
* @brief async send message
*
* @param routeType the route type
* @param topic the topic
* @param dstInst the dst agency(must set when 'route by agency' and 'route by
* @param routeInfo the route info, include
* - topic the topic
* - dstInst the dst agency(must set when 'route by agency' and 'route by
* component')
* @param dstNodeID the dst nodeID(must set when 'route by nodeID')
* @param componentType the componentType(must set when 'route by component')
* - dstNodeID the dst nodeID(must set when 'route by nodeID')
* - componentType the componentType(must set when 'route by component')
* @param payload the payload to send
* @param seq the message seq
* @param timeout timeout
* @param callback callback
*/
virtual void asyncSendMessage(ppc::protocol::RouteType routeType, std::string const& topic,
std::string const& dstInst, bcos::bytes const& dstNodeID, std::string const& componentType,
bcos::bytes&& payload, int seq, long timeout, ppc::protocol::MessageCallback callback) = 0;
virtual void asyncSendMessage(ppc::protocol::RouteType routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, bcos::bytes&& payload, int seq,
long timeout, ppc::protocol::ReceiveMsgFunc errorCallback,
ppc::protocol::MessageCallback callback) = 0;

// the sync interface for async_send_message
virtual ppc::protocol::Message::Ptr push(ppc::protocol::RouteType routeType, std::string topic,
std::string dstInst, std::string dstNodeID, std::string const& componentType,
bcos::bytes&& payload, int seq, long timeout) = 0;
virtual bcos::Error::Ptr push(ppc::protocol::RouteType routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, bcos::bytes&& payload, int seq,
long timeout) = 0;

virtual ppc::protocol::Message::Ptr pop(std::string const& topic, long timeoutMs) = 0;
virtual ppc::protocol::Message::Ptr peek(std::string const& topic);


/**
* @brief: receive message from gateway, call by gateway
* @param _message: received ppc message
* @return void
* @brief register the nodeInfo to the gateway
* @param nodeInfo the nodeInfo
*/
virtual void onReceiveMessage(
ppc::protocol::Message::Ptr const& _msg, ppc::protocol::ReceiveMsgFunc _callback) = 0;
virtual void registerNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo) = 0;

/**
* @brief unRegister the nodeInfo to the gateway
*/
virtual void unRegisterNodeInfo() = 0;

/**
* @brief register the topic
*
* @param topic the topic to register
*/
virtual void registerTopic(std::string const& topic) = 0;

/**
* @brief unRegister the topic
*
* @param topic the topic to unregister
*/
virtual void unRegisterTopic(std::string const& topic) = 0;
};

class IFrontBuilder
Expand All @@ -101,6 +139,6 @@ class IFrontBuilder
* @return IFront::Ptr he created Front
*/
virtual IFront::Ptr build(ppc::front::FrontConfig::Ptr config) const = 0;
virtual IFront::Ptr buildClient(std::string endPoint) const = 0;
virtual IFrontClient::Ptr buildClient(std::string endPoint) const = 0;
};
} // namespace ppc::front
81 changes: 0 additions & 81 deletions cpp/ppc-framework/gateway/GatewayInterface.h

This file was deleted.

16 changes: 9 additions & 7 deletions cpp/ppc-framework/gateway/IGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ class IGateway
* @param timeout timeout
* @param callback callback
*/
virtual void asyncSendMessage(ppc::protocol::RouteType routeType, std::string const& topic,
std::string const& dstInst, bcos::bytes const& dstNodeID, std::string const& componentType,
bcos::bytes&& payload, long timeout, ppc::protocol::ReceiveMsgFunc callback) = 0;
virtual void asyncSendMessage(ppc::protocol::RouteType routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, bcos::bytes&& payload,
long timeout, ppc::protocol::ReceiveMsgFunc callback) = 0;

virtual void registerNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo);
virtual void unRegisterNodeInfo(bcos::bytesConstRef nodeID);
virtual void registerTopic(bcos::bytesConstRef nodeID, std::string const& topic);
virtual void unRegisterTopic(bcos::bytesConstRef nodeID, std::string const& topic);
virtual void asyncSendbroadcastMessage(ppc::protocol::RouteType routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, bcos::bytes&& payload) = 0;
virtual void registerNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo) = 0;
virtual void unRegisterNodeInfo(bcos::bytesConstRef nodeID) = 0;
virtual void registerTopic(bcos::bytesConstRef nodeID, std::string const& topic) = 0;
virtual void unRegisterTopic(bcos::bytesConstRef nodeID, std::string const& topic) = 0;
};

} // namespace ppc::gateway
Loading
Loading