client

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultRoutesToTUN will route all system traffic through the TUN.
	DefaultRoutesToTUN = []*route.Addr{

		route.MustParseAddr("0.0.0.0/1"),
		route.MustParseAddr("128.0.0.0/1"),
	}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the actual VPN cl. It manages connections, routing and tunneling of the requests. It is safe to make a Client connection as it does not change the default system routing and just adds on existing infrastructure.

func NewClient

func NewClient() (*Client, error)

NewClient initializes default Client with default proxy address. If you want more options use Client struct.

func NewClientWithOpts

func NewClientWithOpts(cfg Config) (*Client, error)

NewClientWithOpts initializes Client with specified Config. It is recommended to just use NewClient().

func (*Client) BytesRead

func (c *Client) BytesRead() int

BytesRead returns number of bytes read from TUN device.

func (*Client) BytesWritten

func (c *Client) BytesWritten() int

BytesWritten returns number of bytes written to TUN device.

func (*Client) Connect

func (c *Client) Connect(link string) error

Connect creates a global tunnel and routes all incoming connections (or traffic specified in Config.RoutesToTUN) to the VPN server via newly created defaultInboundProxy.

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context) error

Disconnect stops all listeners and cleans up route for XRay server.

It will block till all resources are done processing or context is cancelled (method also enforces timeout of disconnectTimeout)

func (*Client) GatewayIP

func (c *Client) GatewayIP() net.IP

GatewayIP returns gateway IP used to route outbound traffic through. It is used to route packets destined to XRay remote server.

func (*Client) InboundProxy

func (c *Client) InboundProxy() Proxy

InboundProxy returns proxy address initialized by XRay core. Traffic from TUN device is routed to this proxy.

func (*Client) TUNAddress

func (c *Client) TUNAddress() net.IP

TUNAddress returns address the TUN device is set up on. Traffic is routed to this TUN device.

type Config

type Config struct {
	// GatewayIP to direct outbound traffic. Must be able to reach remote XRay server.
	// (default: will be dynamically detected from your default gateway).
	//
	// Client will determine the system gateway IP automatically,
	// and you don't have to set this field explicitly.
	GatewayIP *net.IP
	// Socks proxy address on which XRay creates inbound proxy (default: 127.0.0.1:10808).
	InboundProxy *Proxy
	// TUN device address (default: 192.18.0.1).
	TUNAddress *net.IPNet
	// List of routes to be pointed to TUN device (default: DefaultRoutesToTUN).
	//
	// One exception is explicitly added for XRay remote server IP and can not be altered.
	RoutesToTUN []*route.Addr
	// Whether to allow self-signed certificates or not.
	TLSAllowInsecure bool
	// Pass logger with debug level to observe debug logs (default: slog.TextHandler).
	Logger *slog.Logger
	// XRayLogType is used to redefine xray core log type (default: LogType_None).
	XRayLogType xapplog.LogType
}

Config serves configuration for new Client. Empty fields will be set up with defaults values.

It is advised to not configure the cl yourself, please use NewClient() with default config values, normally you don't have to set these fields yourself.

type Proxy

type Proxy struct {
	IP   net.IP // Inbound proxy IP (e.g. 127.0.0.1)
	Port int    // Inbound proxy port (e.g. 1080)
}

Proxy will set up XRay inbound.

func (*Proxy) String

func (p *Proxy) String() string

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL