Help us shape the future of Go! Take the 2026 Go Developer Survey

trojan

package
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TunIP = "198.18.0.1"

TunIP is the synthetic IPv4 the GUI and utun use. Trojan has no overlay lease.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client dials Trojan TCP (+ TLS / REALITY / XHTTP) per Open.

func New

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

New parses cfg and prepares a dialer. Call Probe before serving SOCKS.

func (*Client) Bytes

func (c *Client) Bytes() (up, down uint64)

Bytes is STATUS spark counters.

func (*Client) Close

func (c *Client) Close() error

Close stops the helper; in-flight streams keep their sockets.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done closes when Close is called.

func (*Client) ListenUDP

func (c *Client) ListenUDP() (net.PacketConn, error)

ListenUDP opens one Trojan UDP ASSOCIATE stream.

func (*Client) Open

func (c *Client) Open(target string) (net.Conn, error)

Open dials the server and starts a Trojan TCP stream to target (host:port).

func (*Client) Probe

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

Probe dials TLS (if any) and one Trojan header so a bad URL fails before SOCKS.

func (*Client) Session

func (c *Client) Session() *mux.Session

Session is nil: Trojan is not a loft mux.

type Config

type Config struct {
	URL      string
	Password string
	SNI      string
	Insecure bool
	Log      func(string)
}

Config is one Trojan outbound (password + server).

type Endpoint

type Endpoint struct {
	Addr        string // host:port
	Password    string
	SNI         string
	TLS         bool
	Reality     bool
	Insecure    bool
	Network     string // tcp, xhttp, …
	Fingerprint string
	PublicKey   string
	ShortID     string
	Path        string
	Host        string
	Mode        string
}

Endpoint is the server address and TLS options extracted from a URL.

func ParseURL

func ParseURL(raw, password string) (Endpoint, error)

ParseURL reads trojan://password@host:port?…, https://host:port, or host:port.

Jump to

Keyboard shortcuts

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