-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: add WebSocket server and PacketData structure for log handling #810
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
i
is 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>
support eCaptureQ
This pull request introduces several new features and refactors to the
ecaptureq
package, 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
ecaptureq
package:Packet data model and JSON serialization:
PacketData
struct to represent packet information, including fields such asTimestamp
,SrcIP
,DstIP
, andPayloadBase64
. The struct uses JSON tags for serialization compatibility with frontend expectations.Encode
andDecode
methods for convertingPacketData
instances to and from JSON byte streams.WebSocket server implementation:
Server
struct with fields for address, logging buffer, WebSocket instance, and logger.Start
,Write
, andRead
for starting the server, writing data to WebSocket connections, and logging received data.Refactor and enhancements to WebSocket utility (
pkg/util/ws
):Buffered write channel:
writeChan
with a configurable buffer size (WriteChanLength
) to handle concurrent writes to WebSocket connections efficiently. [1] [2]Separation of read and write handlers:
Server
struct to use distinctreadHandler
andwriteChan
fields, improving clarity and functionality for WebSocket message handling.Concurrent WebSocket operations:
handleWebSocket
method to use two goroutines: one for processing incoming messages viareadHandler
and another for sending messages fromwriteChan
. This ensures non-blocking operations for both reading and writing.