-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca71127
commit 6dcefa0
Showing
32 changed files
with
2,102 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* 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 FrontConfig.h | ||
* @author: yujiechen | ||
* @date 2024-08-22 | ||
*/ | ||
|
||
#pragma once | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace ppc::front | ||
{ | ||
/** | ||
* @brief the gateway endpoint | ||
* | ||
*/ | ||
class GatewayEndPoint | ||
{ | ||
public: | ||
GatewayEndPoint() = default; | ||
GatewayEndPoint(std::string const& host, uint16_t port) : m_host(std::move(host)), m_port(port) | ||
{} | ||
virtual ~GatewayEndPoint() = default; | ||
|
||
virtual std::string const& host() const { return m_host; } | ||
uint16_t port() const { return m_port; } | ||
|
||
void setHost(std::string host) { m_host = std::move(host); } | ||
void setPort(uint16_t port) { m_port = port; } | ||
|
||
private: | ||
// the host | ||
std::string m_host; | ||
// the port | ||
uint16_t m_port; | ||
}; | ||
|
||
// Note: swig explosed interface | ||
class FrontConfig | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<FrontConfig>; | ||
FrontConfig(int threadPoolSize, std::string agencyID) | ||
: m_threadPoolSize(threadPoolSize), m_agencyID(std::move(agencyID)) | ||
{} | ||
virtual ~FrontConfig() = default; | ||
|
||
virtual int threadPoolSize() const { return m_threadPoolSize; } | ||
virtual std::string const agencyID() const { return m_agencyID; } | ||
virtual std::vector<GatewayEndPoint> const& gatewayInfo() const { return m_gatewayInfo; } | ||
virtual void setGatewayInfo(std::vector<GatewayEndPoint> gatewayInfo) | ||
{ | ||
m_gatewayInfo = std::move(gatewayInfo); | ||
} | ||
|
||
virtual void appendGatewayInfo(GatewayEndPoint&& endpoint) | ||
{ | ||
// TODO:check the endpoint | ||
m_gatewayInfo.push_back(endpoint); | ||
} | ||
|
||
private: | ||
int m_threadPoolSize; | ||
std::string m_agencyID; | ||
std::vector<GatewayEndPoint> m_gatewayInfo; | ||
}; | ||
|
||
class FrontConfigBuilder | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<FrontConfigBuilder>; | ||
FrontConfigBuilder() = default; | ||
virtual ~FrontConfigBuilder() = default; | ||
|
||
FrontConfig::Ptr build(int threadPoolSize, std::string agencyID) | ||
{ | ||
return std::make_shared<FrontConfig>(threadPoolSize, agencyID); | ||
} | ||
}; | ||
} // namespace ppc::front |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* 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 IFront.h | ||
* @author: yujiechen | ||
* @date 2024-08-22 | ||
*/ | ||
#pragma once | ||
#include "FrontConfig.h" | ||
#include "ppc-framework/protocol/Message.h" | ||
#include "ppc-framework/protocol/RouteType.h" | ||
#include <bcos-utilities/Error.h> | ||
|
||
namespace ppc::front | ||
{ | ||
class IFront | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<IFront>; | ||
|
||
IFront() = default; | ||
virtual ~IFront() = default; | ||
|
||
/** | ||
* @brief start the IFront | ||
* | ||
* @param front the IFront to start | ||
*/ | ||
virtual void start() const = 0; | ||
/** | ||
* @brief stop the IFront | ||
* | ||
* @param front the IFront to stop | ||
*/ | ||
virtual void stop() const = 0; | ||
|
||
/** | ||
* | ||
* @param front the front object | ||
* @param topic the topic | ||
* @param callback the callback called when receive specified topic | ||
*/ | ||
virtual void registerTopicHandler( | ||
std::string const& topic, ppc::protocol::MessageCallback 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 | ||
* component') | ||
* @param dstNodeID the dst nodeID(must set when 'route by nodeID') | ||
* @param 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; | ||
|
||
// 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; | ||
|
||
/** | ||
* @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 IFrontBuilder | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<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 IFront::Ptr buildClient(std::string endPoint) const = 0; | ||
}; | ||
} // namespace ppc::front |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* 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 IGateway.h | ||
* @author: yujiechen | ||
* @date 2024-08-26 | ||
*/ | ||
#pragma once | ||
#include "../protocol/INodeInfo.h" | ||
#include "../protocol/Message.h" | ||
#include "../protocol/RouteType.h" | ||
#include <bcos-utilities/Error.h> | ||
|
||
|
||
namespace ppc::gateway | ||
{ | ||
using ErrorCallbackFunc = std::function<void(bcos::Error::Ptr)>; | ||
/** | ||
* @brief: A list of interfaces provided by the gateway which are called by the front service. | ||
*/ | ||
class IGateway | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<IGateway>; | ||
IGateway() = default; | ||
virtual ~IGateway() {} | ||
|
||
/** | ||
* @brief: start/stop service | ||
*/ | ||
virtual void start() = 0; | ||
virtual void stop() = 0; | ||
|
||
/** | ||
* @brief send message to gateway | ||
* | ||
* @param routeType the route type | ||
* @param topic the topic | ||
* @param 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') | ||
* @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, 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); | ||
}; | ||
|
||
} // namespace ppc::gateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* 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 INodeInfo.h | ||
* @author: yujiechen | ||
* @date 2024-08-26 | ||
*/ | ||
#pragma once | ||
#include "ppc-framework/front/IFront.h" | ||
#include <memory> | ||
|
||
namespace ppc::protocol | ||
{ | ||
// the node information | ||
class INodeInfo | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<INodeInfo>; | ||
INodeInfo() = default; | ||
virtual ~INodeInfo() = default; | ||
|
||
virtual std::string const& endPoint() const = 0; | ||
virtual bcos::bytesConstRef nodeID() const = 0; | ||
|
||
// components | ||
virtual void setComponents(std::vector<std::string> const& components) = 0; | ||
virtual std::set<std::string> const& components() const = 0; | ||
|
||
virtual void encode(bcos::bytes& data) const = 0; | ||
virtual void decode(bcos::bytesConstRef data) = 0; | ||
|
||
virtual void setFront(ppc::front::IFront::Ptr&& front) = 0; | ||
virtual ppc::front::IFront::Ptr const& getFront() const = 0; | ||
|
||
virtual bool equal(INodeInfo::Ptr const& info) | ||
{ | ||
return (nodeID() == info->nodeID()) && (components() == info->components()); | ||
} | ||
}; | ||
class INodeInfoFactory | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr<INodeInfoFactory>; | ||
INodeInfoFactory(bcos::bytes nodeID) : m_nodeID(std::move(nodeID)) {} | ||
virtual ~INodeInfoFactory() = default; | ||
|
||
virtual INodeInfo::Ptr build() = 0; | ||
virtual INodeInfo::Ptr build(std::string const& endPoint) = 0; | ||
|
||
protected: | ||
bcos::bytes m_nodeID; | ||
}; | ||
} // namespace ppc::protocol |
Oops, something went wrong.