Skip to content

feat(ipc): add SSE status event streaming to clients in real-time#343

Open
garmr-ulfr wants to merge 3 commits intomainfrom
stream-status-events
Open

feat(ipc): add SSE status event streaming to clients in real-time#343
garmr-ulfr wants to merge 3 commits intomainfrom
stream-status-events

Conversation

@garmr-ulfr
Copy link
Collaborator

This pull request introduces a new server-sent events (SSE) endpoint for streaming VPN status updates and refactors the VPN status handling throughout the IPC server. The changes replace the previous string-based status checks with a strongly-typed VPNStatus enum, update endpoint handlers to use the new status values, and remove legacy status management logic. Additionally, HTTP/2 protocol handling is improved to support streaming responses. The most important changes are grouped below.

VPN Status Event Streaming

  • Added a new SSE endpoint (statusEventsEndpoint) and handler (statusEventsHandler) for real-time VPN status updates, including a client implementation and test coverage. (vpn/ipc/events.go, vpn/ipc/events_client.go, vpn/ipc/events_test.go, vpn/ipc/endpoints.go) [1] [2] [3] [4]

Refactoring Status Management

  • Replaced legacy string-based status checks (e.g., StatusRunning, StatusClosed) with the new VPNStatus enum values (Connected, Disconnected, etc.) across all endpoint handlers and service logic. (vpn/ipc/server.go, vpn/ipc/connections.go, vpn/ipc/clash_mode.go, vpn/ipc/group.go, vpn/ipc/outbound.go, telemetry/connections.go, vpn/ipc/status.go) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]

  • Removed legacy status constants and the setVPNStatus method, simplifying the codebase and centralizing status updates via the new event stream. (vpn/ipc/server.go, vpn/ipc/status.go) [1] [2] [3]

HTTP/2 Streaming Support

  • Introduced explicit HTTP/2 protocol handling and removed response buffering for SSE endpoints to enable efficient streaming and long-lived connections. (vpn/ipc/http.go, vpn/ipc/server.go) [1] [2] [3]

Endpoint Routing Improvements

  • Grouped standard routes under a tracer middleware and separated SSE routes to avoid response buffering, ensuring proper handling of streaming connections. (vpn/ipc/server.go)

These changes modernize the IPC server's status handling, introduce real-time event streaming, and improve protocol support for streaming connections.

…ith VPNStatus type

Introduce a Server-Sent Events endpoint (/status/events) that streams
VPN status changes to clients in real time, replacing the previous
poll-based approach. Refactor status representation from string constants
(StatusRunning, StatusClosed, etc.) to a typed VPNStatus enum (Connected,
Disconnected, Connecting, Disconnecting, Restarting, ErrorStatus) and
move status emission from the IPC server into the tunnel layer. The
tracer middleware is scoped to standard routes so it no longer buffers
long-lived SSE connections, and the HTTP transport is upgraded to
unencrypted HTTP/2 for multiplexed streaming support.
Copilot AI review requested due to automatic review settings February 26, 2026 01:34
Copy link
Contributor

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 pull request modernizes the VPN status handling by introducing a strongly-typed VPNStatus enum to replace string-based status values, adds a new SSE endpoint for real-time status event streaming, and improves HTTP/2 support for long-lived streaming connections. The changes centralize status management through an event-driven architecture where status updates are emitted as StatusUpdateEvent events rather than being managed directly by the IPC server.

Changes:

  • Introduced VPNStatus enum type with values: Connecting, Connected, Disconnecting, Disconnected, Restarting, and ErrorStatus
  • Added SSE endpoint /status/events for streaming VPN status updates to clients in real-time
  • Refactored status management to use event-driven architecture with StatusUpdateEvent emissions from the tunnel layer
  • Updated HTTP server configuration to support HTTP/2 and removed WriteTimeout to enable long-lived SSE connections

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
vpn/ipc/events.go Implements SSE handler for streaming status events with StatusUpdateEvent type definition
vpn/ipc/events_client.go Client implementation for consuming status event stream with retry logic
vpn/ipc/events_test.go Test coverage for status event streaming handler
vpn/ipc/endpoints.go Adds /status/events endpoint constant
vpn/ipc/server.go Introduces VPNStatus enum, removes legacy status management, configures HTTP/2, and separates SSE routes from tracer middleware
vpn/ipc/status.go Updates GetStatus and statusHandler to use VPNStatus type, removes legacy string constants
vpn/ipc/http.go Configures HTTP/2 protocol support for client and server transports
vpn/ipc/connections.go Updates status comparisons from StatusRunning to Connected
vpn/ipc/clash_mode.go Updates status comparisons from StatusRunning to Connected
vpn/ipc/group.go Updates status comparisons from StatusRunning to Connected
vpn/ipc/outbound.go Updates status comparisons from StatusRunning to Connected
vpn/tunnel.go Implements status management with atomic.Value, emits StatusUpdateEvent on status changes, adds Restarting status handling
vpn/service.go Updates Status() return type to VPNStatus, sets Restarting status during restart
vpn/vpn.go Updates isOpen check from StatusRunning to Connected
vpn/vpn_test.go Updates mock service to use VPNStatus type and Connected constant
vpn/tunnel_test.go Updates test assertions from StatusRunning/StatusClosed to Connected/Disconnected
telemetry/connections.go Updates status comparison from StatusRunning to Connected

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants