http2

package
v0.0.0-...-c150d52 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIN_SPARE_H2_STREAMS               = 20
	ASSUMED_MAX_CONCURRENT_STREAMS     = 100
	MAX_RETRIES                        = 3 // Retry making a connection up to MAX_RETRIES times.
	LOW_LATENCY_MAX_CONCURRENT_STREAMS = 5 // Max concurrent streams on a low latency connection.
)

Variables

This section is empty.

Functions

func StreamDataToDatagramChunk

func StreamDataToDatagramChunk(payload []byte, l int) ([]byte, int)

StreamDataToDatagramChunk converts UDP payload data to a CONNECT-UDP datagram chunk. This protocol is for tunneling a UDP stream via an HTTP proxy server. IETF draft: https://datatracker.ietf.org/doc/html/draft-ietf-masque-connect-udp-03 CONNECT-UDP datagram chunk is encoded in the format of T-L-V: T/Type: type; L/Length: data length; V/Value: data. |payload| is the UDP packet payload; |l| is the payload length. It returns the encoded chunk in a byte slice and its total length.

Types

type Client

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

Client is a MASQUE HTTP/2 client that supports HTTP CONNECT and CONNECT-UDP. All CONNECT requests are multiplexed using a HTTP/2 transport. Each CONNECT-UDP request is performed in HTTP/1.1 and sent individually via its own TLS connection. Any CONNECT or CONNECT-UDP requests that need HTTP/3 should not directly use this.

The tlsTimeout setting determines the duration the client waits when attempting to create a new TLS connection to the proxy. An error is returned if the connection is not ready to use within the specified tlsTimeout.

func NewClient

func NewClient(config ClientConfig) *Client

NewClient creates a new Client instance with the provided parameters.

func (*Client) ConnectToProxy

func (c *Client) ConnectToProxy() error

ConnectToProxy connects the Client to the proxy.

func (*Client) CreateTCPStream

func (c *Client) CreateTCPStream(addr string) (*Conn, error)

CreateTCPStream creates a TCP stream to the given address using the client. This function should ONLY be called after successfully calling ConnectToProxy.

If it succeeds, CreateTCPStream returns a Conn struct that provides a pair of I/O interfaces. Users can use the provided I/O interfaces to communicate with the target domain server in a way that is similar to a TCP socket's bytestream abstraction.

Otherwise, CreateTCPStream returns nil and indicates the error.

func (*Client) CreateUDPStream

func (c *Client) CreateUDPStream(addr string) (*Conn, error)

CreateUDPStream creates a UDP stream to the given address using the client.

This function should ONLY be called after calling |ConnectToProxy| successfully. If it succeeds, return a Conn struct that provides a pair of I/O interfaces. Users can then use the provided I/O interfaces to communicate with the target domain server in a way that is similar to an UDP datagram socket abstraction.

Otherwise, it returns nil and indicates the error. It refills the connection for the next call.

type ClientConfig

type ClientConfig struct {
	ProxyAddr       string
	AuthToken       string
	Prot            SocketProtector
	CertData        []byte
	LowLatencyAddrs []string
	Logger          *slog.Logger
	IgnoreCert      bool
}

type Conn

type Conn struct {
	IoInc io.Writer
	IoOut io.ReadCloser
	// contains filtered or unexported fields
}

Conn represents a HTTP CONNECT or CONNECT-UDP connection.

Each connection has a unique stream ID, specified by the |sid| field, and a pair of I/O handles, namely |IoInc| and |IoOut|, designed for sending and receiving data via the proxied TCP/UDP connection.

For CONNECT-UDP using HTTP/1.1, the |transport| field keeps track of the unique HTTP/1.1 TLS connection to the destination proxy server.

The |Alive| field indicates the liveness of the underlying CONNECT-UDP HTTP connection. Users should only send data through this proxied connection if |Alive| is true.

func (*Conn) Close

func (r *Conn) Close() error

Close closes the Conn, performing necessary cleanup.

func (*Conn) Read

func (r *Conn) Read(b []byte) (int, error)

Read reads data from the Conn's IoOut handle if the connection is alive. It returns an error if the connection is closed.

func (*Conn) Sid

func (r *Conn) Sid() uint64

Sid returns the unique stream ID of the Conn.

func (*Conn) Write

func (r *Conn) Write(p []byte) (int, error)

Write writes data to the Conn's IoInc handle if the connection is alive. It returns an error if the connection is closed.

type SocketProtector

type SocketProtector func(fileDescriptor int) error

SocketProtector is a type representing a function that overrides Android's VpnService.protect(). Android's VPN hooks are necessary to capture and redirect all of a phone's traffic through the MASQUE tunnel, but to avoid an infinite loop, the traffic sent to the MASQUE proxy needs to be exempted from that redirection. This function enables "protection" of the given file descriptor (the underlying system fd for the MASQUE tunnel) from Android's VPN.

Jump to

Keyboard shortcuts

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