-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor: Migrate Agent-Server Communication Protocol to Protobuf #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Switch to Protobuf: Replaced the custom JSON and string-based WebSocket protocol with Protobuf for more efficient and structured data transmission. Simplify Data Handling: Removed intermediate JSON parsing on the server (ecaptureq.go) and simplified the event writer logic. Update Data Flow: Changed processor output channels and server buffers from string to []byte to handle binary Protobuf data. Remove Base64: Eliminated Base64 encoding for event payloads, now sending raw bytes directly within the Protobuf message.
- **Add `ToProtobufEvent()` to Interface:** Introduced a new method to the `IEventStruct` interface to standardize the conversion of events to the `pb.Event` Protobuf format. - **Implement for All Event Types:** Implemented the `ToProtobufEvent()` method for all concrete event structs (OpenSSL, Bash, GoTLS, etc.), mapping their fields to the Protobuf message structure. - **Update Event Processor:** The event processor now uses this new method to create fully structured Protobuf messages before sending them. - **Convert Heartbeat to Protobuf:** Refactored the client heartbeat to also send a structured `pb.Heartbeat` message instead of a custom JSON payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the eCapture agent-server communication protocol from a custom JSON-based implementation to a fully-typed Protobuf protocol, significantly improving performance and maintainability.
- Replaces JSON message format with binary Protobuf messages for WebSocket communication
- Adds ToProtobufEvent() method to all event types for unified serialization
- Introduces a comprehensive protobuf visualizer tool for debugging
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 13 comments.
Show a summary per file
File | Description |
---|---|
utils/protobuf_visualizer/pb_debugger.go | New debugging tool for visualizing protobuf messages |
utils/protobuf_visualizer/README.md | Comprehensive documentation for the visualizer tool |
user/event/*.go | Added ToProtobufEvent() methods to all event types |
protobuf/proto/v1/ecaptureq.proto | Protobuf schema definition |
protobuf/gen/v1/ecaptureq.pb.go | Generated protobuf Go code |
pkg/event_processor/*.go | Updated to use binary protobuf serialization |
pkg/ecaptureq/*.go | Migrated server/client to protobuf protocol |
cli/cmd/*.go | Simplified event writer configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Not ready to merge |
The eventWorker is now responsible for setting the Payload, Length, Type, and UUID on the outgoing Protobuf message. Individual event structs (SSLDataEvent, etc.) now only provide base metadata, decoupling them from the final serialization logic.
should work properly now |
gojue/ecaptureQ#29 |
user/event/event_bash.go
Outdated
DstIp: "127.0.0.1", // Bash events do not have DstIP | ||
DstPort: 0, // Bash events do not have DstPort | ||
Pid: int64(be.Pid), | ||
Pname: string(be.Comm[:]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the commStr function should be used here for filtering. @zenyanle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks.
This PR completely overhauls the communication protocol between the eCapture agent and the eCaptureQ server, migrating from a custom JSON-based implementation to a fully-typed Protobuf protocol.
This was done in two main phases:
Protocol Foundation: The underlying WebSocket transport was switched to handle binary Protobuf messages (LogEntry) instead of raw JSON strings.
Content Serialization: A ToProtobufEvent() method was added and implemented for all event types, ensuring that all captured data is serialized into a consistent and structured pb.Event message before transmission.
This refactoring significantly improves performance, reliability, and maintainability of the agent-server communication pipeline.