-
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
97726a1
commit 9b504f7
Showing
19 changed files
with
211 additions
and
42 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
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
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
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(ppc-transport-sdk VERSION ${VERSION}) | ||
|
||
file(GLOB_RECURSE SRCS *.cpp) | ||
|
||
add_library(${WEDPR_TRANSPORT_SDK_TARGET} ${SRCS}) | ||
target_link_libraries(${WEDPR_TRANSPORT_SDK_TARGET} PUBLIC | ||
${FRONT_TARGET} ${PB_PROTOCOL_TARGET} ${SERVICE_CLIENT_TARGET} ${SERVICE_SERVER_TARGET} ${CPU_FEATURES_LIB}) | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
add_subdirectory(src) | ||
|
||
if (DEMO) | ||
add_subdirectory(demo) | ||
enable_testing() | ||
endif () |
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,7 @@ | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
# cmake settings | ||
set(BINARY_NAME transport_sdk_demo) | ||
add_executable(${BINARY_NAME} transport_client.cpp) | ||
target_link_libraries(${BINARY_NAME} ${WEDPR_TRANSPORT_SDK_TARGET}) | ||
|
||
unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY) |
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,132 @@ | ||
/* | ||
* Copyright (C) 2022 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 transport_bench.cpp | ||
* @desc: bench for transport | ||
* @author: yujiechen | ||
* @date 2024-09-13 | ||
*/ | ||
#include "ppc-framework/protocol/RouteType.h" | ||
#include "wedpr-transport/sdk/src/TransportBuilder.h" | ||
#include <thread> | ||
|
||
using namespace ppc::front; | ||
using namespace ppc::sdk; | ||
using namespace ppc::protocol; | ||
|
||
void Usage(std::string const& _appName) | ||
{ | ||
std::cout << _appName << " [hostIp] [listenPort] [gatewayTargets] [nodeID] [dstNode]" | ||
<< std::endl; | ||
std::cout << "example:" << std::endl; | ||
std::cout << _appName | ||
<< " 127.0.0.1 9020 ipv4:127.0.0.1:40600,127.0.0.1:40601 agency0Node agency1Node" | ||
<< std::endl; | ||
std::cout << _appName | ||
<< " 127.0.0.1 9021 ipv4:127.0.0.1:40620,127.0.0.1:40621 agency1Node agency0Node" | ||
<< std::endl; | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
if (argc < 6) | ||
{ | ||
Usage(argv[0]); | ||
return -1; | ||
} | ||
// the hostIp | ||
std::string hostIp = argv[1]; | ||
// the clientPort | ||
int port = atoi(argv[2]); | ||
std::string listenIp = "0.0.0.0"; | ||
// the gatewayTargets | ||
std::string gatewayTargets = argv[3]; | ||
// the nodeID | ||
std::string nodeID = argv[4]; | ||
// the dstNode | ||
std::string dstNode = argv[5]; | ||
|
||
auto transportBuilder = std::make_shared<TransportBuilder>(); | ||
auto frontConfig = transportBuilder->buildConfig(2, nodeID); | ||
frontConfig->setGatewayGrpcTarget(gatewayTargets); | ||
EndPoint endPoint(hostIp, port); | ||
frontConfig->setSelfEndPoint(endPoint); | ||
auto transport = transportBuilder->buildProTransport(frontConfig); | ||
|
||
// start the transport | ||
std::cout << "#### start the front, detail: " << printFrontDesc(frontConfig); | ||
transport->start(); | ||
auto routeInfo = transport->routeInfoBuilder()->build(); | ||
std::string topic = "sync_testDemo"; | ||
routeInfo->setDstNode(bcos::bytes(dstNode.begin(), dstNode.end())); | ||
routeInfo->setTopic(topic); | ||
transport->getFront()->registerTopicHandler(topic, [](Message::Ptr msg) { | ||
std::cout << "=== async receive message: " << printMessage(msg) << "====" << std::endl; | ||
}); | ||
std::string syncTopic = "sync__" + topic; | ||
auto syncRouteInfo = transport->routeInfoBuilder()->build(); | ||
syncRouteInfo->setDstNode(bcos::bytes(dstNode.begin(), dstNode.end())); | ||
syncRouteInfo->setTopic(syncTopic); | ||
// sendMessage test | ||
long i = 0; | ||
while (true) | ||
{ | ||
try | ||
{ | ||
std::string payload = "payload+++" + std::to_string(i); | ||
bcos::bytes payloadBytes = bcos::bytes(payload.begin(), payload.end()); | ||
// async test | ||
transport->getFront()->asyncSendMessage((uint16_t)RouteType::ROUTE_THROUGH_NODEID, | ||
routeInfo, std::move(bcos::bytes(payload.begin(), payload.end())), 0, 10000, | ||
[](bcos::Error::Ptr error) { | ||
if (error && error->errorCode() != 0) | ||
{ | ||
std::cout << "!**** send message failed for: " << error->errorMessage() | ||
<< "***!" << std::endl; | ||
} | ||
}, | ||
nullptr); | ||
|
||
// push | ||
auto error = transport->getFront()->push((uint16_t)RouteType::ROUTE_THROUGH_NODEID, | ||
syncRouteInfo, std::move(payloadBytes), 0, 10000); | ||
if (!error && error->errorCode() != 0) | ||
{ | ||
std::cout << "!**** send message failed for: " << error->errorMessage() << "***!" | ||
<< std::endl; | ||
} | ||
// pop | ||
auto msg = transport->getFront()->pop(syncTopic, 10000); | ||
if (msg == nullptr) | ||
{ | ||
std::cout << "try to receive message timeout" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "=== sync receive message: " << printMessage(msg) | ||
<< "====" << std::endl; | ||
} | ||
i++; | ||
} | ||
catch (std::exception const& e) | ||
{ | ||
std::cout << "!**** exception: " << boost::diagnostic_information(e) << "****!" | ||
<< std::endl; | ||
} | ||
// wait for 2s | ||
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); | ||
}; | ||
return 0; | ||
} |
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,8 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(ppc-transport-sdk VERSION ${VERSION}) | ||
|
||
file(GLOB_RECURSE SRCS *.cpp) | ||
|
||
add_library(${WEDPR_TRANSPORT_SDK_TARGET} ${SRCS}) | ||
target_link_libraries(${WEDPR_TRANSPORT_SDK_TARGET} PUBLIC | ||
${FRONT_TARGET} ${PB_PROTOCOL_TARGET} ${SERVICE_CLIENT_TARGET} ${SERVICE_SERVER_TARGET} ${CPU_FEATURES_LIB}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.