Skip to content

feat(ipc): remove ipc dependeny on data directory#337

Open
garmr-ulfr wants to merge 6 commits intomainfrom
remove-ipc-datadir
Open

feat(ipc): remove ipc dependeny on data directory#337
garmr-ulfr wants to merge 6 commits intomainfrom
remove-ipc-datadir

Conversation

@garmr-ulfr
Copy link
Collaborator

This PR decouples the IPC layer from the data directory by moving server configuration building and file watching responsibilities out of the tunnel/IPC server and into the caller.


Primary Change: Remove IPC dependency on data directory

  • The tunnel no longer reads server config files directly or watches the filesystem for changes. Instead, it receives pre-built options as a serialized JSON string and exposes explicit AddOutbounds, RemoveOutbounds, and UpdateOutbounds methods for dynamic server management. (vpn/tunnel.go)
  • Removed vpn/ipc/set.go entirely, which contained the SetSettingsPath endpoint and the go:linkname hack for reloading settings — a Linux-specific workaround that is no longer needed.
  • The Service interface now accepts an options string for Start and Restart instead of group/tag pairs, and adds UpdateOutbounds, AddOutbounds, and RemoveOutbounds methods. (vpn/ipc/server.go)
  • TunnelService implements the new interface, delegating outbound mutations to the underlying tunnel. Options are built and serialized by the caller before being passed over IPC. (vpn/service.go)

New IPC endpoints for outbound management

  • Added three new POST endpoints: /outbound/update, /outbound/add, and /outbound/remove with corresponding handlers and client functions. (vpn/ipc/endpoints.go, vpn/ipc/outbound.go)
  • Registered the new routes and removed the now-deleted setSettingsPathEndpoint route. (vpn/ipc/server.go)

Event-driven server propagation

  • Introduced ServersUpdatedEvent, ServersAddedEvent, and ServersRemovedEvent event types emitted when the server manager modifies its server list. (servers/manager.go)
  • Added init() subscriptions that forward these events to the running tunnel via the new IPC endpoints, replacing the previous file-watcher approach. (vpn/vpn.go)

VPN status type refinement

  • Replaced string-based status constants (StatusRunning, StatusClosed, etc.) with a typed VPNStatus type and new values (Connected, Disconnected, Connecting, Disconnecting). (vpn/ipc/status.go, and all handlers)
  • Start/stop handlers now set intermediate statuses (Connecting, Disconnecting) and handle concurrent state transitions more explicitly. (vpn/ipc/server.go)

Public API updates

  • Added AutoConnect, Connect, Restart, and SelectServer as the new public API; deprecated QuickConnect, ConnectToServer, and Reconnect. (vpn/vpn.go)
  • SelectServer now supports the autoAllTag group for switching to auto mode via clash mode. (vpn/vpn.go)
  • getOptions() builds and serializes tunnel options from settings, centralizing option construction at the caller level. (vpn/vpn.go)

Test updates

  • Updated all tests to use the new VPNStatus constants, the changed Service interface signatures, and the separated addOutbounds/removeOutbounds calls. (vpn/tunnel_test.go, vpn/vpn_test.go)

Copilot AI review requested due to automatic review settings February 24, 2026 01:35
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 PR removes the IPC layer's dependency on the data directory by eliminating file watching and moving server configuration responsibility to the caller. The tunnel now receives pre-built configuration as JSON and exposes explicit outbound management methods.

Changes:

  • Replaced file-watching with event-driven server propagation via the events package
  • Changed Service interface to accept serialized options strings and added UpdateOutbounds/AddOutbounds/RemoveOutbounds methods
  • Introduced typed VPNStatus (Connected, Disconnected, Connecting, Disconnecting) replacing string constants

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
vpn/vpn.go Added init() event subscriptions to forward server changes to tunnel; added AutoConnect/Connect/Restart public APIs; deprecated old APIs
vpn/tunnel.go Removed file watcher and reloadOptions; split updateGroup into separate addOutbounds/removeOutbounds/updateOutbounds methods; changed start() to accept options string
vpn/service.go Updated Start/Restart to accept options string; added UpdateOutbounds/AddOutbounds/RemoveOutbounds delegating to tunnel
vpn/ipc/server.go Changed Service interface signatures; added outbound management routes; improved status transition handling
vpn/ipc/status.go Replaced string status constants with VPNStatus type; fixed GetStatus return type
vpn/ipc/outbound.go Added UpdateOutbounds/AddOutbounds/RemoveOutbounds handlers and client functions
vpn/ipc/endpoints.go Added three new endpoint constants for outbound management
vpn/ipc/set.go Removed entire file (SetSettingsPath endpoint and go:linkname hack)
servers/manager.go Added ServersUpdatedEvent/ServersAddedEvent/ServersRemovedEvent emitted on changes
vpn/tunnel_test.go Updated tests for new VPNStatus type and split outbound operations
vpn/vpn_test.go Updated mockService to implement new Service interface
telemetry/connections.go Updated status check to use ipc.Connected
vpn/ipc/group.go Updated status check to use Connected constant
vpn/ipc/connections.go Updated status checks to use Connected constant
vpn/ipc/clash_mode.go Updated status check to use Connected constant

💡 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