Documentation
¶
Overview ¶
Package ipc implements the IPC server for communicating between the client and the VPN service. It provides HTTP endpoints for retrieving statistics, managing groups, selecting outbounds, changing modes, and closing connections.
Index ¶
- Constants
- Variables
- func CloseConnections(ctx context.Context, connIDs []string) error
- func CloseService(ctx context.Context) error
- func GetActiveOutbound(ctx context.Context) (group, tag string, err error)
- func GetClashMode(ctx context.Context) (string, error)
- func GetSelected(ctx context.Context) (group, tag string, err error)
- func GetStatus(ctx context.Context) (string, error)
- func SelectOutbound(ctx context.Context, groupTag, outboundTag string) error
- func SetClashMode(ctx context.Context, mode string) error
- func SetSocketPath(path string)
- func StartService(ctx context.Context, group, tag string) error
- func StopService(ctx context.Context) error
- type Connection
- type Metrics
- type OutboundGroup
- type Outbounds
- type Selector
- type Server
- func (s *Server) Close() error
- func (s *Server) GetStatus() string
- func (s *Server) SetService(svc Service) Service
- func (s *Server) Start(basePath string, fn StartFn) error
- func (s *Server) StartService(ctx context.Context, group, tag string) error
- func (s *Server) StopService(ctx context.Context) error
- type Service
- type StartFn
- type StatusUpdateEvent
- type VPNStatus
Constants ¶
const ( StatusInitializing = "initializing" StatusConnecting = "connecting" StatusRunning = "running" StatusClosing = "closing" StatusClosed = "closed" )
Variables ¶
var ( ErrServiceIsNotReady = errors.New("service is not ready") ErrIPCNotRunning = errors.New("IPC not running") )
Functions ¶
func CloseConnections ¶
CloseConnections closes connections by their IDs. If connIDs is empty, all connections will be closed.
func CloseService ¶
CloseService sends a request to shutdown the service
func GetActiveOutbound ¶
GetActiveOutbound retrieves the outbound that is actively being used, resolving nested groups if necessary.
func GetClashMode ¶
GetClashMode retrieves the current mode from the Clash server.
func GetSelected ¶
GetSelected retrieves the currently selected outbound and its group.
func SelectOutbound ¶
SelectOutbound selects an outbound within a group.
func SetClashMode ¶
SetClashMode sets the mode of the Clash server.
func SetSocketPath ¶
func SetSocketPath(path string)
SetSocketPath sets the path for the Unix domain socket file for client connections.
func StartService ¶
StartService sends a request to start the service
func StopService ¶
StopService sends a request to stop the service (IPC server stays up)
Types ¶
type Connection ¶
type Connection struct {
ID string
Inbound string
IPVersion int
Network string
Source string
Destination string
Domain string
Protocol string
FromOutbound string
CreatedAt int64
ClosedAt int64
Uplink int64
Downlink int64
Rule string
Outbound string
ChainList []string
}
Connection represents a network connection with relevant metadata.
func GetConnections ¶
func GetConnections(ctx context.Context) ([]Connection, error)
GetConnections retrieves the list of current and recently closed connections.
type Metrics ¶
type Metrics struct {
Memory uint64
Goroutines int
Connections int
// UplinkTotal and DownlinkTotal are only available when the service is running and there are
// active connections.
// In bytes.
UplinkTotal int64
// In bytes.
DownlinkTotal int64
}
Metrics represents the runtime metrics of the service.
type OutboundGroup ¶
OutboundGroup represents a group of outbounds.
type Selector ¶
type Selector interface {
adapter.OutboundGroup
SelectOutbound(tag string) bool
}
Selector is helper interface to check if an outbound is a selector or wrapper of selector.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the IPC server that communicates over a Unix domain socket for Unix-like systems, and a named pipe for Windows.
func (*Server) SetService ¶
SetService updates the service attached to the server and returns the old service, if any. Typically called when starting or replacing the VPN tunnel.
func (*Server) Start ¶
Start starts the IPC server. The socket file will be created in the "basePath" directory. On Windows, the "basePath" is ignored and a default named pipe path is used.
func (*Server) StartService ¶
type Service ¶
type Service interface {
Ctx() context.Context
Status() string
ClashServer() *clashapi.Server
Close() error
}
Service defines the interface that the IPC server uses to interact with the underlying VPN service.
type StatusUpdateEvent ¶
StatusUpdateEvent is emitted when the VPN status changes.