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
1 changed files with 9 additions and 1 deletions

View File

@ -283,10 +283,18 @@ void WhisperCom::Router::processLocalMessage_(zmq::message_t &msg)
}
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_};
typeName="Subscribe";
auto it = subscription_.find(rmsg.topic());
if (it == subscription_.end() || (*it).second.empty())
{
listening_.join(rmsg.topic().c_str());
}
subscription_[rmsg.topic()].push_back(sender);
listening_.join(rmsg.topic().c_str());
}
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE)
{