transport

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseWebSocketURL added in v0.3.5

func ParseWebSocketURL(rawURL string) (scheme, host, port, path string, err error)

ParseWebSocketURL parses a WebSocket URL and returns components

Types

type CompressionConfig added in v0.3.5

type CompressionConfig struct {
	Enable  bool
	Level   int
	MinSize int
}

CompressionConfig holds compression settings

type Config added in v0.3.5

type Config struct {
	// Secret is the authentication secret/key
	Secret string

	// DNS is the DNS server address for resolution
	DNS string

	// Compression holds optional compression settings
	Compression *CompressionConfig
}

Config holds common configuration for all transports

type Manager

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

Manager handles the lifecycle of underlying network connections and seamless switching between them using Yamux session resumption. Uses MTP (Mimic Transport Protocol) over UDP for anti-DPI transport.

func NewManager

func NewManager(serverAddr string, uuid string, dns string) *Manager

NewManager creates a new transport manager

func (*Manager) GetMTPConn

func (m *Manager) GetMTPConn() *mtp.MTPConn

GetMTPConn returns the current MTP connection (for stats)

func (*Manager) RotateTransport

func (m *Manager) RotateTransport(newDomain string) error

RotateTransport switches the underlying transport to a new domain while keeping the Yamux session alive via MTP session migration. Uses protected dialer for Android VpnService compatibility.

func (*Manager) StartSession

func (m *Manager) StartSession(initialDomain string) (*yamux.Session, error)

StartSession establishes the initial connection and Yamux session over MTP

type Transport added in v0.3.5

type Transport interface {
	// Dial connects to the remote address and returns a net.Conn
	Dial(ctx context.Context, address string) (net.Conn, error)

	// Listen starts listening for incoming connections on the given address
	Listen(address string) (net.Listener, error)

	// Name returns the transport protocol name (e.g., "mtp", "ws", "quic")
	Name() string

	// Close closes the transport and releases resources
	Close() error
}

Transport is the interface that all transport protocols must implement. It provides a unified API for different transport mechanisms (MTP, WebSocket, QUIC, etc.)

type VirtualConn

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

VirtualConn is a persistent connection wrapper that can switch its underlying physical connection. This allows upper layers (like Yamux) to think they have a stable connection. It supports buffered seamless swap to prevent data loss during transport rotation.

func NewVirtualConn

func NewVirtualConn(conn net.Conn) *VirtualConn

func (*VirtualConn) Close

func (v *VirtualConn) Close() error

func (*VirtualConn) LocalAddr

func (v *VirtualConn) LocalAddr() net.Addr

func (*VirtualConn) Read

func (v *VirtualConn) Read(b []byte) (n int, err error)

func (*VirtualConn) RemoteAddr

func (v *VirtualConn) RemoteAddr() net.Addr

func (*VirtualConn) SetDeadline

func (v *VirtualConn) SetDeadline(t time.Time) error

func (*VirtualConn) SetReadDeadline

func (v *VirtualConn) SetReadDeadline(t time.Time) error

func (*VirtualConn) SetWriteDeadline

func (v *VirtualConn) SetWriteDeadline(t time.Time) error

func (*VirtualConn) SwapConnection

func (v *VirtualConn) SwapConnection(newConn net.Conn)

SwapConnection replaces the underlying connection with a new one. The old connection is NOT closed here, caller handles it.

func (*VirtualConn) SwapConnectionSeamless

func (v *VirtualConn) SwapConnectionSeamless(newConn net.Conn) error

SwapConnectionSeamless replaces the underlying connection with buffered transition. Writes during the swap are captured and replayed on the new connection.

func (*VirtualConn) Write

func (v *VirtualConn) Write(b []byte) (n int, err error)

type WebSocketConfig added in v0.3.5

type WebSocketConfig struct {
	// Path is the URL path for WebSocket endpoint (e.g., "/ws")
	Path string

	// Host is the Host header value for masquerading
	Host string

	// TLS enables WSS (WebSocket over TLS)
	TLS bool

	// TLSConfig allows custom TLS configuration
	TLSConfig *tls.Config

	// Headers are additional HTTP headers to send during handshake
	Headers http.Header

	// HandshakeTimeout is the timeout for WebSocket handshake
	HandshakeTimeout time.Duration

	// ReadBufferSize is the size of the read buffer
	ReadBufferSize int

	// WriteBufferSize is the size of the write buffer
	WriteBufferSize int
}

WebSocketConfig holds WebSocket-specific configuration

func DefaultWebSocketConfig added in v0.3.5

func DefaultWebSocketConfig() *WebSocketConfig

DefaultWebSocketConfig returns default WebSocket configuration

type WebSocketTransport added in v0.3.5

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

WebSocketTransport implements Transport interface for WebSocket connections

func NewWebSocketTransport added in v0.3.5

func NewWebSocketTransport(config *WebSocketConfig) *WebSocketTransport

NewWebSocketTransport creates a new WebSocket transport

func (*WebSocketTransport) Close added in v0.3.5

func (t *WebSocketTransport) Close() error

Close closes the WebSocket transport

func (*WebSocketTransport) Dial added in v0.3.5

func (t *WebSocketTransport) Dial(ctx context.Context, address string) (net.Conn, error)

Dial connects to the remote WebSocket server

func (*WebSocketTransport) Listen added in v0.3.5

func (t *WebSocketTransport) Listen(address string) (net.Listener, error)

Listen starts a WebSocket server

func (*WebSocketTransport) Name added in v0.3.5

func (t *WebSocketTransport) Name() string

Name returns the transport name

Jump to

Keyboard shortcuts

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