From f8ef5addaa8168b47132bb22a82a86be25c53663 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 6 Feb 2025 16:33:19 +0100 Subject: [PATCH] cluster/Backend: Rename HandleRemoteEvent() to ProcessEvent() ...also add Backend::ProcessEvent() for backends to trigger event processing without needing to use ProcessEventMessage(). --- src/cluster/Backend.cc | 10 +++++++--- src/cluster/Backend.h | 22 ++++++++++++++++++---- src/cluster/websocket/WebSocket.cc | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cluster/Backend.cc b/src/cluster/Backend.cc index 53b70047cc..5a2c44bfff 100644 --- a/src/cluster/Backend.cc +++ b/src/cluster/Backend.cc @@ -19,7 +19,7 @@ using namespace zeek::cluster; -bool detail::LocalEventHandlingStrategy::DoHandleRemoteEvent(std::string_view topic, detail::Event e) { +bool detail::LocalEventHandlingStrategy::DoProcessEvent(std::string_view topic, detail::Event e) { zeek::event_mgr.Enqueue(e.Handler(), std::move(e.Args()), util::detail::SOURCE_BROKER, 0, nullptr, e.Timestamp()); return true; } @@ -123,7 +123,11 @@ void Backend::EnqueueEvent(EventHandlerPtr h, zeek::Args args) { event_handling_strategy->EnqueueLocalEvent(h, std::move(args)); } -bool Backend::ProcessEventMessage(std::string_view topic, std::string_view format, const byte_buffer_span payload) { +bool Backend::ProcessEvent(std::string_view topic, detail::Event e) { + return event_handling_strategy->ProcessEvent(topic, std::move(e)); +} + +bool Backend::ProcessEventMessage(std::string_view topic, std::string_view format, byte_buffer_span payload) { if ( format != event_serializer->Name() ) { zeek::reporter->Error("ProcessEventMessage: Wrong format: %s vs %s", std::string{format}.c_str(), event_serializer->Name().c_str()); @@ -139,7 +143,7 @@ bool Backend::ProcessEventMessage(std::string_view topic, std::string_view forma return false; } - return event_handling_strategy->HandleRemoteEvent(topic, std::move(*r)); + return ProcessEvent(topic, std::move(*r)); } bool Backend::ProcessLogMessage(std::string_view format, byte_buffer_span payload) { diff --git a/src/cluster/Backend.h b/src/cluster/Backend.h index 03f6de3e49..9116f8bc76 100644 --- a/src/cluster/Backend.h +++ b/src/cluster/Backend.h @@ -102,7 +102,7 @@ public: * * @return true if the remote event was handled successfully, else false. */ - bool HandleRemoteEvent(std::string_view topic, Event e) { return DoHandleRemoteEvent(topic, std::move(e)); } + bool ProcessEvent(std::string_view topic, Event e) { return DoProcessEvent(topic, std::move(e)); } /** * Method for enquing backend specific events. @@ -120,14 +120,14 @@ public: private: /** - * Hook method for implementing HandleRemoteEvent(). + * Hook method for implementing ProcessEvent(). * * @param topic The topic on which the event was received. * @param ev The parsed event that was received. * * @return true if the remote event was handled successfully, else false. */ - virtual bool DoHandleRemoteEvent(std::string_view topic, Event e) = 0; + virtual bool DoProcessEvent(std::string_view topic, Event e) = 0; /** * Hook method for implementing EnqueueLocalEvent(). @@ -143,7 +143,7 @@ private: */ class LocalEventHandlingStrategy : public EventHandlingStrategy { private: - bool DoHandleRemoteEvent(std::string_view topic, Event e) override; + bool DoProcessEvent(std::string_view topic, Event e) override; void DoEnqueueLocalEvent(EventHandlerPtr h, zeek::Args args) override; }; @@ -308,6 +308,20 @@ protected: */ void EnqueueEvent(EventHandlerPtr h, zeek::Args args); + /** + * Process a cluster event. + * + * This method is called by ProcessEventMessage() and delegates + * to the event handling strategy. It should only be used by + * backends implementing their own serialization format. Other + * backends should not have a use for this and call ProcessEventMessage() + * directly instead. + * + * @param topic The topic on which the event was received. + * @param e The event as cluster::detail::Event. + */ + bool ProcessEvent(std::string_view topic, detail::Event e); + /** * Process an incoming event message. */ diff --git a/src/cluster/websocket/WebSocket.cc b/src/cluster/websocket/WebSocket.cc index 0f3be64742..3ffd150383 100644 --- a/src/cluster/websocket/WebSocket.cc +++ b/src/cluster/websocket/WebSocket.cc @@ -53,7 +53,7 @@ private: * will need some abstractions if client's can opt to use different encodings * of events in the future. */ - bool DoHandleRemoteEvent(std::string_view topic, zeek::cluster::detail::Event e) override { + bool DoProcessEvent(std::string_view topic, zeek::cluster::detail::Event e) override { // If the client has left, no point in sending it any pending event. if ( wsc->IsTerminated() ) return true;