Skip to content

Commit

Permalink
erase front dependency to bcos-boostssl
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Oct 23, 2024
1 parent 7c69e64 commit 49f2b02
Show file tree
Hide file tree
Showing 33 changed files with 583 additions and 1,275 deletions.
39 changes: 19 additions & 20 deletions .github/workflows/cpp_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
!c:/vcpkg/buildtrees
!c:/vcpkg/packages
!c:/vcpkg/downloads
key: build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
key: build-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
restore-keys: |
build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-${{ matrix.os }}-${{ github.base_ref }}-
build-${{ matrix.os }}-
build-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-all-${{ matrix.os }}-${{ github.base_ref }}-
build-all-${{ matrix.os }}-
- name: Build for linux
if: runner.os == 'Linux'
run: |
Expand Down Expand Up @@ -105,11 +105,11 @@ jobs:
${{ env.VCPKG_ROOT }}/buildtrees
${{ env.VCPKG_ROOT }}/packages
${{ env.VCPKG_ROOT }}/downloads
key: build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
key: build-sdk-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
restore-keys: |
build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-${{ matrix.os }}-${{ github.base_ref }}-
build-${{ matrix.os }}-
build-sdk-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-sdk-${{ matrix.os }}-${{ github.base_ref }}-
build-sdk-${{ matrix.os }}-
- name: Add MSbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/[email protected]
Expand All @@ -118,7 +118,7 @@ jobs:
run: |
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_SDK=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake ..
MSBuild /version
MSBuild wedpr-component.sln /p:Configuration=Release /p:Platform=x64
MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
- name: Build for linux
if: runner.os == 'Linux'
run: |
Expand Down Expand Up @@ -184,18 +184,18 @@ jobs:
${{ env.VCPKG_ROOT }}/buildtrees
${{ env.VCPKG_ROOT }}/packages
${{ env.VCPKG_ROOT }}/downloads
key: build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
key: build-toolkit-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
restore-keys: |
build-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-${{ matrix.os }}-${{ github.base_ref }}-
build-${{ matrix.os }}-
build-toolkit-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
build-toolkit-${{ matrix.os }}-${{ github.base_ref }}-
build-toolkit-${{ matrix.os }}-
- name: Add MSbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/[email protected]
- name: Build for windows
if: runner.os == 'Windows'
run: |
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild wedpr-component.sln /p:Configuration=Release /p:Platform=x64
mkdir -p cpp/build && cd cpp/build && cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DBUILD_WEDPR_TOOLKIT=ON -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. && MSBuild /version && MSBuild WeDPR-Component.sln /p:Configuration=Release /p:Platform=x64
- name: Build for linux
if: runner.os == 'Linux'
run: |
Expand Down Expand Up @@ -249,11 +249,11 @@ jobs:
/usr/local/share/vcpkg/packages
/home/runner/.ccache
/Users/runner/.ccache/
key: centos-notest-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
key: centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
restore-keys: |
centos-notest-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
centos-notest-${{ matrix.os }}-${{ github.base_ref }}-
centos-notest-${{ matrix.os }}-
centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-
centos-notest-all-${{ matrix.os }}-
- name: Prepare centos tools
run: |
rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
Expand All @@ -277,11 +277,10 @@ jobs:
- name: Build
run: |
alias cmake='cmake3'
. /opt/rh/devtoolset-10/enable
. /opt/rh/devtoolset-11/enable
. /opt/rh/rh-perl530/enable
export LIBCLANG_PATH=/opt/rh/llvm-toolset-7/root/lib64/
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
. /opt/rh/llvm-toolset-7/enable
mkdir -p cpp/build
cd cpp/build
cmake3 -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endif()
if(BUILD_ALL OR BUILD_WEDPR_TOOLKIT)
find_package(TBB REQUIRED)
find_package(gRPC REQUIRED)
find_package(jsoncpp REQUIRED)
endif()
##### the sdk dependencies #####
if(BUILD_ALL OR BUILD_SDK OR BUILD_UDF)
Expand All @@ -29,7 +30,6 @@ endif()

##### the full-dependencies #####
if(BUILD_ALL)
find_package(jsoncpp REQUIRED)
find_package(${BCOS_BOOSTSSL_TARGET} REQUIRED)
# tcmalloc
include(ProjectTCMalloc)
Expand Down
68 changes: 23 additions & 45 deletions cpp/ppc-framework/protocol/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "RouteType.h"
#include "ppc-framework/Helper.h"
#include "ppc-framework/libwrapper/Buffer.h"
#include <bcos-boostssl/interfaces/MessageFace.h>
#include <bcos-utilities/Common.h>
#include <bcos-utilities/DataConvertUtility.h>
#include <bcos-utilities/Error.h>
Expand Down Expand Up @@ -183,35 +182,28 @@ class MessageHeader
uint16_t mutable m_length;
};

class Message : virtual public bcos::boostssl::MessageFace
class Message
{
public:
using Ptr = std::shared_ptr<Message>;
Message() = default;
~Message() override {}
virtual ~Message() {}

virtual MessageHeader::Ptr header() const { return m_header; }
virtual void setHeader(MessageHeader::Ptr header) { m_header = std::move(header); }

/// the overloaed implementation ===
uint16_t version() const override { return m_header->version(); }
void setVersion(uint16_t version) override { m_header->setVersion(version); }
uint16_t packetType() const override { return m_header->packetType(); }
void setPacketType(uint16_t packetType) override { m_header->setPacketType(packetType); }
std::string const& seq() const override { return m_header->traceID(); }
void setSeq(std::string traceID) override { m_header->setTraceID(traceID); }
uint16_t ext() const override { return m_header->ext(); }
void setExt(uint16_t ext) override { m_header->setExt(ext); }

bool isRespPacket() const override { return m_header->isRespPacket(); }
void setRespPacket() override { m_header->setRespPacket(); }

virtual uint32_t length() const override
{
return m_header->length() + (m_payload ? m_payload->size() : 0);
}

std::shared_ptr<bcos::bytes> payload() const override { return m_payload; }
uint16_t version() const { return m_header->version(); }
void setVersion(uint16_t version) { m_header->setVersion(version); }
uint16_t packetType() const { return m_header->packetType(); }
void setPacketType(uint16_t packetType) { m_header->setPacketType(packetType); }
std::string const& seq() const { return m_header->traceID(); }
void setSeq(std::string traceID) { m_header->setTraceID(traceID); }
uint16_t ext() const { return m_header->ext(); }
void setExt(uint16_t ext) { m_header->setExt(ext); }

bool isRespPacket() const { return m_header->isRespPacket(); }
void setRespPacket() { m_header->setRespPacket(); }
void setPayload(std::shared_ptr<bcos::bytes> _payload) { m_payload = std::move(_payload); }
// for swig wrapper
OutputBuffer payloadBuffer() const
{
Expand All @@ -222,11 +214,6 @@ class Message : virtual public bcos::boostssl::MessageFace
return OutputBuffer{(unsigned char*)m_payload->data(), m_payload->size()};
}

void setPayload(std::shared_ptr<bcos::bytes> _payload) override
{
m_payload = std::move(_payload);
}

void setFrontMessage(MessagePayload::Ptr frontMessage)
{
m_frontMessage = std::move(frontMessage);
Expand All @@ -236,10 +223,15 @@ class Message : virtual public bcos::boostssl::MessageFace

// Note: swig wrapper require define all methods
virtual bool encode(bcos::bytes& _buffer) = 0;
// encode and return the {header, payload}
virtual bool encode(bcos::boostssl::EncodedMsg& _encodedMsg) = 0;
virtual int64_t decode(bcos::bytesConstRef _buffer) = 0;

virtual uint32_t length() const
{
return m_header->length() + (m_payload ? m_payload->size() : 0);
}

virtual std::shared_ptr<bcos::bytes> payload() const { return m_payload; }

protected:
MessageHeader::Ptr m_header;
// Note: allocate here in case of wsService nullptr access caused coredump
Expand All @@ -259,12 +251,12 @@ class MessageHeaderBuilder
virtual MessageOptionalHeader::Ptr build(MessageOptionalHeader::Ptr const& optionalHeader) = 0;
};

class MessageBuilder : public bcos::boostssl::MessageFaceFactory
class MessageBuilder
{
public:
using Ptr = std::shared_ptr<MessageBuilder>;
MessageBuilder() = default;
~MessageBuilder() override = default;
virtual ~MessageBuilder() = default;

virtual Message::Ptr build() = 0;
virtual Message::Ptr build(bcos::bytesConstRef buffer) = 0;
Expand Down Expand Up @@ -320,20 +312,6 @@ inline std::string printMessage(Message::Ptr const& _msg)
}
return stringstream.str();
}

inline std::string printWsMessage(bcos::boostssl::MessageFace::Ptr const& _msg)
{
if (!_msg)
{
return "nullptr";
}
std::ostringstream stringstream;
stringstream << LOG_KV("rsp", _msg->isRespPacket()) << LOG_KV("traceID", _msg->seq())
<< LOG_KV("packetType", _msg->packetType()) << LOG_KV("length", _msg->length())
<< LOG_KV("ext", _msg->ext());
return stringstream.str();
}

// function to send response
using SendResponseFunction = std::function<void(std::shared_ptr<bcos::bytes>&& payload)>;
using ReceiveMsgFunc = std::function<void(bcos::Error::Ptr)>;
Expand Down
98 changes: 98 additions & 0 deletions cpp/ppc-framework/protocol/P2PMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* 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 Message.h
* @author: yujiechen
* @date 2024-08-22
*/
#pragma once
#include "Message.h"
#include <bcos-boostssl/interfaces/MessageFace.h>
namespace ppc::protocol
{
// the wrapper for override bcos::boostssl::MessageFace while use implementation for Message
class P2PMessage : virtual public bcos::boostssl::MessageFace
{
public:
using Ptr = std::shared_ptr<P2PMessage>;
P2PMessage(Message::Ptr msg) : m_msg(std::move(msg)) {}
~P2PMessage() override {}

/// the overloaed implementation ===
uint16_t version() const override { return m_msg->version(); }
void setVersion(uint16_t version) override { m_msg->setVersion(version); }
uint16_t packetType() const override { return m_msg->packetType(); }
void setPacketType(uint16_t packetType) override { m_msg->setPacketType(packetType); }
std::string const& seq() const override { return m_msg->seq(); }
void setSeq(std::string seq) override { m_msg->setSeq(seq); }
uint16_t ext() const override { return m_msg->ext(); }
void setExt(uint16_t ext) override { m_msg->setExt(ext); }
std::shared_ptr<bcos::bytes> payload() const override { return m_msg->payload(); }
void setPayload(std::shared_ptr<bcos::bytes> payload) override
{
m_msg->setPayload(std::move(payload));
}

bool encode(bcos::bytes& _buffer) override { return m_msg->encode(_buffer); }

int64_t decode(bcos::bytesConstRef _buffer) override { return m_msg->decode(_buffer); }

bool isRespPacket() const override { return m_msg->isRespPacket(); }
void setRespPacket() override { m_msg->setRespPacket(); }
uint32_t length() const override { return m_msg->length(); }

// encode and return the {header, payload}
virtual bool encode(bcos::boostssl::EncodedMsg& _encodedMsg) = 0;

Message::Ptr const& msg() { return m_msg; }
MessageHeader::Ptr header() const { return m_msg->header(); }

protected:
Message::Ptr m_msg;
};


class P2PMessageBuilder : virtual public bcos::boostssl::MessageFaceFactory
{
public:
using Ptr = std::shared_ptr<P2PMessageBuilder>;
P2PMessageBuilder() = default;
~P2PMessageBuilder() override = default;

virtual P2PMessage::Ptr build() = 0;
virtual P2PMessage::Ptr build(ppc::protocol::RouteType routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, bcos::bytes&& payload) = 0;
};
inline std::string printWsMessage(bcos::boostssl::MessageFace::Ptr const& _msg)
{
if (!_msg)
{
return "nullptr";
}
std::ostringstream stringstream;
stringstream << LOG_KV("rsp", _msg->isRespPacket()) << LOG_KV("traceID", _msg->seq())
<< LOG_KV("packetType", _msg->packetType()) << LOG_KV("length", _msg->length())
<< LOG_KV("ext", _msg->ext());
return stringstream.str();
}
inline std::string printP2PMessage(P2PMessage::Ptr const& _msg)
{
if (_msg->msg() == nullptr)
{
return "";
}
return printMessage(_msg->msg());
}
} // namespace ppc::protocol
2 changes: 1 addition & 1 deletion cpp/ppc-framework/protocol/PPCMessageFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once
#include "Protocol.h"
#include "ppc-framework/protocol/Message.h"
#include "ppc-framework/protocol/P2PMessage.h"
#include <bcos-utilities/Common.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
Expand Down
9 changes: 2 additions & 7 deletions cpp/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
"name": "grpc",
"version": "1.51.1#1"
},
{
"name": "zlib",
"version": "1.2.12",
"port-version": 1
},
{
"name": "jsoncpp",
"version": "1.9.5"
Expand Down Expand Up @@ -122,8 +117,7 @@
},
"tarscpp",
"tbb",
"libxml2",
"jsoncpp"
"libxml2"
]
},
"sdk": {
Expand All @@ -148,6 +142,7 @@
"version>=": "1.51.1"
},
"tarscpp",
"jsoncpp",
"tbb"
]
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/wedpr-crypto/ppc-crypto/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ find_package(OpenSSL REQUIRED)
message(STATUS "OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")

target_link_libraries(${CRYPTO_TARGET} PUBLIC ${BCOS_UTILITIES_TARGET} ${CRYPTO_CORE_TARGET} OpenSSL::Crypto unofficial-sodium::sodium unofficial-sodium::sodium_config_public TBB::tbb ${CPU_FEATURES_LIB})
target_link_libraries(${CRYPTO_TARGET} PUBLIC ${BCOS_UTILITIES_TARGET} ${CRYPTO_CORE_TARGET} OpenSSL::Crypto unofficial-sodium::sodium TBB::tbb ${CPU_FEATURES_LIB})

if (ENABLE_IPP_CRYPTO)
find_package(ipp-crypto REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion cpp/wedpr-protocol/protocol/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB_RECURSE SRCS *.cpp)
add_library(${PROTOCOL_TARGET} ${SRCS})

target_link_libraries(${PROTOCOL_TARGET} PUBLIC ${BCOS_BOOSTSSL_TARGET} ${CPU_FEATURES_LIB} jsoncpp_static)
target_link_libraries(${PROTOCOL_TARGET} PUBLIC ${CPU_FEATURES_LIB} jsoncpp_static)
Loading

0 comments on commit 49f2b02

Please sign in to comment.