FIX: only subscripe to topic if not yet subscribed

This commit is contained in:
Dominik Meyer 2023-07-27 23:46:51 +02:00
parent f69010a6e6
commit 6a8f754117
No known key found for this signature in database
GPG Key ID: B4C312B600606B64

View File

@ -283,11 +283,19 @@ void WhisperCom::Router::processLocalMessage_(zmq::message_t &msg)
} }
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::SUBSCRIBE) else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::SUBSCRIBE)
{ {
DLOG_S(INFO) << "subscription request from " << sender << " topic: " << rmsg.topic();
std::lock_guard<std::mutex> guard{mutexSubscription_}; std::lock_guard<std::mutex> guard{mutexSubscription_};
typeName="Subscribe"; typeName="Subscribe";
subscription_[rmsg.topic()].push_back(sender);
auto it = subscription_.find(rmsg.topic());
if (it == subscription_.end() || (*it).second.empty())
{
listening_.join(rmsg.topic().c_str()); listening_.join(rmsg.topic().c_str());
} }
subscription_[rmsg.topic()].push_back(sender);
}
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE) else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE)
{ {
std::lock_guard<std::mutex> guard{mutexSubscription_}; std::lock_guard<std::mutex> guard{mutexSubscription_};