Skip to content

Conversation

zenyanle
Copy link
Member

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.

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.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Oct 10, 2025
@cfc4n cfc4n requested a review from Copilot October 10, 2025 14:28
Copy link

@Copilot Copilot AI left a 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.

@zenyanle
Copy link
Member Author

Not ready to merge

@cfc4n cfc4n marked this pull request as draft October 11, 2025 01:58
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.
@zenyanle
Copy link
Member Author

should work properly now

@zenyanle
Copy link
Member Author

gojue/ecaptureQ#29
This PR is ready to merge

@zenyanle zenyanle marked this pull request as ready for review October 12, 2025 06:28
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[:]),
Copy link
Member

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

Copy link
Member

@cfc4n cfc4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 12, 2025
@cfc4n cfc4n merged commit 3c0b4f5 into gojue:master Oct 12, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants