cluster/PublishEvent:: Make event non-const

We want to introduce a hook that can modify the cluster event instances, so
need to pass around a non-const version of it.
This commit is contained in:
Arne Welzel 2025-04-07 13:50:24 +02:00
parent c4a48baeda
commit 90f94ff4f2
5 changed files with 11 additions and 8 deletions

View file

@ -624,7 +624,7 @@ std::vector<broker::peer_info> Manager::Peers() const {
std::string Manager::NodeID() const { return to_string(bstate->endpoint.node_id()); } std::string Manager::NodeID() const { return to_string(bstate->endpoint.node_id()); }
bool Manager::DoPublishEvent(const std::string& topic, const cluster::detail::Event& event) { bool Manager::DoPublishEvent(const std::string& topic, cluster::detail::Event& event) {
auto maybe_ev = zeek::cluster::detail::to_broker_event(event); auto maybe_ev = zeek::cluster::detail::to_broker_event(event);
if ( ! maybe_ev ) if ( ! maybe_ev )
return false; return false;

View file

@ -396,7 +396,7 @@ private:
void DoTerminate() override; void DoTerminate() override;
// Broker overrides this to do its own serialization. // Broker overrides this to do its own serialization.
bool DoPublishEvent(const std::string& topic, const cluster::detail::Event& event) override; bool DoPublishEvent(const std::string& topic, cluster::detail::Event& event) override;
// This should never be reached, broker itself doesn't call this and overrides // This should never be reached, broker itself doesn't call this and overrides
// the generic DoPublishEvent() method that would call this. // the generic DoPublishEvent() method that would call this.

View file

@ -91,7 +91,7 @@ std::optional<detail::Event> Backend::MakeClusterEvent(FuncValPtr handler, ArgsS
} }
// Default implementation doing the serialization. // Default implementation doing the serialization.
bool Backend::DoPublishEvent(const std::string& topic, const cluster::detail::Event& event) { bool Backend::DoPublishEvent(const std::string& topic, cluster::detail::Event& event) {
cluster::detail::byte_buffer buf; cluster::detail::byte_buffer buf;
if ( ! event_serializer->SerializeEvent(buf, event) ) if ( ! event_serializer->SerializeEvent(buf, event) )

View file

@ -178,14 +178,17 @@ public:
/** /**
* Publish a cluster::detail::Event instance to a given topic. * Publish a cluster::detail::Event instance to a given topic.
* *
* The event is allowed to be modified by plugins, e.g. to add additional
* metadata, modify the arguments, or rewrite it in other ways, too. The
* caller will observe these changes on the event as it is passed by
* reference.
*
* @param topic The topic string to publish the event to. * @param topic The topic string to publish the event to.
* @param event The event to publish. * @param event The event to publish.
* *
* @return true if the event was successfully published. * @return true if the event was successfully published.
*/ */
bool PublishEvent(const std::string& topic, const cluster::detail::Event& event) { bool PublishEvent(const std::string& topic, cluster::detail::Event& event) { return DoPublishEvent(topic, event); }
return DoPublishEvent(topic, event);
}
/** /**
* Status codes for callbacks. * Status codes for callbacks.
@ -319,7 +322,7 @@ private:
* This hook method only exists for the existing Broker implementation that * This hook method only exists for the existing Broker implementation that
* short-circuits serialization. Other backends should not override this. * short-circuits serialization. Other backends should not override this.
*/ */
virtual bool DoPublishEvent(const std::string& topic, const cluster::detail::Event& event); virtual bool DoPublishEvent(const std::string& topic, cluster::detail::Event& event);
/** /**
* Send a serialized cluster::detail::Event to the given topic. * Send a serialized cluster::detail::Event to the given topic.

View file

@ -454,7 +454,7 @@ void WebSocketEventDispatcher::HandleEvent(WebSocketClientEntry& entry, std::str
// //
// Switching to a JSON v2 format that ensures all Zeek types are represented // Switching to a JSON v2 format that ensures all Zeek types are represented
// explicitly would help. // explicitly would help.
const auto& zeek_ev = cluster::detail::to_zeek_event(broker_ev); auto zeek_ev = cluster::detail::to_zeek_event(broker_ev);
if ( ! zeek_ev ) { if ( ! zeek_ev ) {
entry.wsc->SendError(broker::enum_str(broker::ec::deserialization_failed), "failed to create Zeek event"); entry.wsc->SendError(broker::enum_str(broker::ec::deserialization_failed), "failed to create Zeek event");
return; return;