Skip to content

Commit

Permalink
send message by component support not specify the dstInst
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Oct 11, 2024
1 parent 895db56 commit 247b945
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,32 +190,59 @@ 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<GatewayNodeInfos> 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)
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 247b945

Please sign in to comment.