Skip to content

Commit

Permalink
add sdk to wedpr-transport
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Sep 4, 2024
1 parent 615e87c commit a6d2a97
Show file tree
Hide file tree
Showing 22 changed files with 237 additions and 579 deletions.
3 changes: 3 additions & 0 deletions cpp/cmake/TargetSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ endif()

set(BOOST_UNIT_TEST Boost::unit_test_framework)

# ==== the transport sdk===
set(WEDPR_TRANSPORT_SDK_TARGET wedpr-transport-sdk)

# ==== the swig wrapper =====
set(WEDPR_PYTHON_TOOLKIT "wedpr_python_toolkit")
set(WEDPR_PYTHON_TOOLKIT_DIR ${PROJECT_BINARY_DIR}/python/${WEDPR_PYTHON_TOOLKIT})
2 changes: 0 additions & 2 deletions cpp/libinitializer/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ void Initializer::init(ppc::protocol::NodeArch _arch)
}
init->fetchAgencyListPeriodically();
});
// load the tars config
m_config->loadTarsConfig(m_configPath);
}
INIT_LOG(INFO) << LOG_DESC("init the frontService success")
<< LOG_KV("agency", m_config->agencyID()) << LOG_KV("arch", _arch);
Expand Down
63 changes: 28 additions & 35 deletions cpp/ppc-framework/front/FrontConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,58 @@
*/

#pragma once
#include "ppc-framework/protocol/EndPoint.h"
#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))
FrontConfig(int threadPoolSize, std::string nodeID)
: m_threadPoolSize(threadPoolSize), m_nodeID(std::move(nodeID))
{}
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)
virtual std::string const& nodeID() const { return m_nodeID; }
virtual std::vector<ppc::protocol::EndPoint> const& gatewayInfo() const
{
return m_gatewayInfo;
}
virtual void setGatewayInfo(std::vector<ppc::protocol::EndPoint> gatewayInfo)
{
m_gatewayInfo = std::move(gatewayInfo);
}

virtual void appendGatewayInfo(GatewayEndPoint&& endpoint)
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 ""; }

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

private:
std::string m_loadBanlancePolicy = "round_robin";
ppc::protocol::EndPoint m_selfEndPoint;
int m_threadPoolSize;
std::string m_agencyID;
std::vector<GatewayEndPoint> m_gatewayInfo;
std::string m_nodeID;
std::vector<ppc::protocol::EndPoint> m_gatewayInfo;
};

class FrontConfigBuilder
Expand All @@ -87,9 +80,9 @@ class FrontConfigBuilder
FrontConfigBuilder() = default;
virtual ~FrontConfigBuilder() = default;

FrontConfig::Ptr build(int threadPoolSize, std::string agencyID)
FrontConfig::Ptr build(int threadPoolSize, std::string nodeID)
{
return std::make_shared<FrontConfig>(threadPoolSize, agencyID);
return std::make_shared<FrontConfig>(threadPoolSize, nodeID);
}
};
} // namespace ppc::front
41 changes: 41 additions & 0 deletions cpp/ppc-framework/front/IFrontBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 "IFront.h"

namespace ppc::front
{
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 IFrontClient::Ptr buildClient(std::string endPoint) const = 0;
};
} // namespace ppc::front
59 changes: 59 additions & 0 deletions cpp/ppc-framework/protocol/EndPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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 EndPoint.h
* @author: yujiechen
* @date 2024-08-22
*/

#pragma once
#include <memory>
#include <string>
#include <vector>

namespace ppc::protocol
{
/**
* @brief the endpoint
*
*/
class EndPoint
{
public:
EndPoint() = default;
EndPoint(std::string const& host, uint16_t port) : m_host(std::move(host)), m_port(port) {}
virtual ~EndPoint() = 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; }

std::string entryPoint() const { return m_host + ":" + std::to_string(m_port); }

std::string listenEndPoint() const { return m_listenIp + ":" + std::to_string(m_port); }

std::string const& listenIp() const { return m_listenIp; }

private:
// the listenIp
std::string m_listenIp = "0.0.0.0";
// the host
std::string m_host;
// the port
uint16_t m_port;
};
} // namespace ppc::protocol
7 changes: 2 additions & 5 deletions cpp/ppc-framework/protocol/INodeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ class INodeInfoFactory
{
public:
using Ptr = std::shared_ptr<INodeInfoFactory>;
INodeInfoFactory(bcos::bytes nodeID) : m_nodeID(std::move(nodeID)) {}
INodeInfoFactory() = default;
virtual ~INodeInfoFactory() = default;

virtual INodeInfo::Ptr build() = 0;
virtual INodeInfo::Ptr build(std::string const& endPoint) = 0;

protected:
bcos::bytes m_nodeID;
virtual INodeInfo::Ptr build(bcos::bytesConstRef nodeID, std::string const& endPoint) = 0;
};

inline std::string printNodeInfo(INodeInfo::Ptr const& nodeInfo)
Expand Down
4 changes: 2 additions & 2 deletions cpp/ppc-framework/protocol/RouteType.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#pragma once
#include <string>
#include <sstream>
#include <string>

namespace ppc::protocol
{
Expand Down Expand Up @@ -51,4 +51,4 @@ inline std::ostream& operator<<(std::ostream& _out, RouteType const& _type)
}
return _out;
}
} // namespace ppc::front
} // namespace ppc::protocol
133 changes: 0 additions & 133 deletions cpp/ppc-main/gateway/GatewayServiceApp.cpp

This file was deleted.

Loading

0 comments on commit a6d2a97

Please sign in to comment.