diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.cpp b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.cpp index 9685e82c..3c36b39a 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.cpp +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.cpp @@ -190,19 +190,47 @@ GatewayNodeInfos PeerRouterTable::selectRouterByAgency(Message::Ptr const& msg) return it->second; } +// Note: selectRouterByComponent support not specified the dstInst GatewayNodeInfos PeerRouterTable::selectRouterByComponent(Message::Ptr const& msg) const { GatewayNodeInfos result; - bcos::ReadGuard l(x_mutex); - auto it = m_agency2GatewayInfos.find(msg->header()->optionalField()->dstInst()); - // no router found - if (it == m_agency2GatewayInfos.end()) + auto dstInst = msg->header()->optionalField()->dstInst(); + std::vector selectedRouterInfos; { - return result; + bcos::ReadGuard l(x_mutex); + if (dstInst.size() > 0) + { + // specified the dstInst + auto it = m_agency2GatewayInfos.find(dstInst); + // no router found + if (it == m_agency2GatewayInfos.end()) + { + return result; + } + selectedRouterInfos.emplace_back(it->second); + } + else + { + // the dstInst not specified, query from all agencies + for (auto const& it : m_agency2GatewayInfos) + { + selectedRouterInfos.emplace_back(it.second); + } + } } - auto const& gatewayInfos = it->second; + for (auto const& it : selectedRouterInfos) + { + selectRouterByComponent(result, it); + } + return result; +} + + +void PeerRouterTable::selectRouterByComponent( + GatewayNodeInfos& choosedGateway, GatewayNodeInfos const& singleAgencyGatewayInfos) const +{ // foreach all gateways to find the component - for (auto const& it : gatewayInfos) + for (auto const& it : singleAgencyGatewayInfos) { auto const& nodeListInfo = it->nodeList(); for (auto const& nodeInfo : nodeListInfo) @@ -210,12 +238,11 @@ GatewayNodeInfos PeerRouterTable::selectRouterByComponent(Message::Ptr const& ms if (nodeInfo.second->components().count( msg->header()->optionalField()->componentType())) { - result.insert(it); + choosedGateway.insert(it); break; } } } - return result; } void PeerRouterTable::asyncBroadcastMessage(ppc::protocol::Message::Ptr const& msg) const diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.h b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.h index fdb7bc6c..42fe8c80 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.h +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/PeerRouterTable.h @@ -54,6 +54,8 @@ class PeerRouterTable private: virtual GatewayNodeInfos selectRouterByNodeID(ppc::protocol::Message::Ptr const& msg) const; virtual GatewayNodeInfos selectRouterByComponent(ppc::protocol::Message::Ptr const& msg) const; + void selectRouterByComponent( + GatewayNodeInfos& choosedGateway, GatewayNodeInfos const& singleAgencyGatewayInfos) const; virtual GatewayNodeInfos selectRouterByAgency(ppc::protocol::Message::Ptr const& msg) const; void removeP2PNodeIDFromNodeIDInfos(GatewayNodeInfo::Ptr const& gatewayInfo); void insertGatewayInfo(GatewayNodeInfo::Ptr const& gatewayInfo); diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java index ce254431..17679b24 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java @@ -303,7 +303,7 @@ public void asyncSendResponse( int seq, MessageErrorCallback errorCallback) { if (dstNode == null) { - throw new WeDPRSDKException("asyncSendMessageByTopic failed for the dstNode is empty"); + throw new WeDPRSDKException("asyncSendResponse failed for the dstNode is empty"); } this.transport .getFront()