feat: add WebSocket server and PacketData structure for log handling#810
Merged
Conversation
support eCaptureQ Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
|
Failed to generate code suggestions for PR |
…log transmission Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…log transmission Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…t server Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…ket client Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces WebSocket server capabilities and data structures for log handling in the eCaptureQ package. The implementation includes a complete WebSocket server system with message broadcasting, client connection management, and structured data models for packet information exchange.
- Adds PacketData structure with JSON serialization for frontend compatibility
- Implements WebSocket server with client management through Hub pattern
- Refactors existing WebSocket utility to support custom connection handlers
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| user/event/ievent.go | Removes commented interface methods |
| user/config/iconfig.go | Adds EcaptureQ configuration field and GetAddrType method |
| pkg/util/ws/server.go | Refactors to support custom WebSocket handlers instead of base64 decoding |
| pkg/util/ws/server_test.go | Updates test to use new handler signature |
| pkg/ecaptureq/proto.go | Defines message types and data structures with JSON encoding |
| pkg/ecaptureq/server.go | Implements WebSocket server with logging and event handling |
| pkg/ecaptureq/hub.go | Implements client connection management and message broadcasting |
| pkg/ecaptureq/client.go | Handles individual WebSocket client connections |
| cli/cmd/root.go | Integrates eCaptureQ server into CLI with conditional initialization |
| cli/cmd/ecaptureq.go | Provides writer adapters for eCaptureQ integration |
Comments suppressed due to low confidence (1)
pkg/ecaptureq/server.go:61
- [nitpick] The variable name
iis not used and is ambiguous. Consider removing it or giving it a more descriptive name if it serves a purpose.
var i = 0
…port Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…essing Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…f payload Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…eartbeat logic Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…ents in server Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…age validation Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
support eCaptureQ
This pull request introduces several new features and refactors to the
ecaptureqpackage, focusing on implementing a WebSocket server, creating a data model for packet handling, and improving the WebSocket utility. The changes add functionality for encoding and decoding packet data, handling WebSocket read/write operations, and managing concurrency through buffered channels.New features in
ecaptureqpackage:Packet data model and JSON serialization:
PacketDatastruct to represent packet information, including fields such asTimestamp,SrcIP,DstIP, andPayloadBase64. The struct uses JSON tags for serialization compatibility with frontend expectations.EncodeandDecodemethods for convertingPacketDatainstances to and from JSON byte streams.WebSocket server implementation:
Serverstruct with fields for address, logging buffer, WebSocket instance, and logger.Start,Write, andReadfor starting the server, writing data to WebSocket connections, and logging received data.Refactor and enhancements to WebSocket utility (
pkg/util/ws):Buffered write channel:
writeChanwith a configurable buffer size (WriteChanLength) to handle concurrent writes to WebSocket connections efficiently. [1] [2]Separation of read and write handlers:
Serverstruct to use distinctreadHandlerandwriteChanfields, improving clarity and functionality for WebSocket message handling.Concurrent WebSocket operations:
handleWebSocketmethod to use two goroutines: one for processing incoming messages viareadHandlerand another for sending messages fromwriteChan. This ensures non-blocking operations for both reading and writing.