conn

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddonNotifier

type AddonNotifier interface {
	NotifyClientDisconnected(*ClientConn)
	NotifyServerDisconnected(*Context)
}

AddonNotifier defines callbacks for addon notifications.

type ClientConn

type ClientConn struct {
	ID                 uuid.UUID
	Conn               net.Conn
	TLS                bool
	NegotiatedProtocol string
	UpstreamCert       bool // Connect to upstream server to look up certificate details. Default: True
	ClientHello        *tls.ClientHelloInfo
	CloseChan          chan struct{} // Channel that is closed when the connection is closed
}

ClientConn represents a client connection.

func NewClientConn

func NewClientConn(c net.Conn) *ClientConn

NewClientConn creates a new ClientConn instance.

func (*ClientConn) MarshalJSON

func (c *ClientConn) MarshalJSON() ([]byte, error)

type Context

type Context struct {
	ClientConn         *ClientConn                 `json:"clientConn"`
	ServerConn         *ServerConn                 `json:"serverConn"`
	Intercept          bool                        `json:"intercept"` // Indicates whether to parse HTTPS
	FlowCount          atomic.Uint32               `json:"-"`         // Number of HTTP requests made on the same connection
	CloseAfterResponse bool                        // after http response, http server will close the connection
	DialFn             func(context.Context) error `json:"-"` // when begin request, if there no ServerConn, use this func to dial
}

Context represents the connection context for a proxy connection.

func NewContext

func NewContext(clientConn *ClientConn) *Context

NewContext creates a new connection context.

func (*Context) ID

func (c *Context) ID() uuid.UUID

ID returns the connection ID.

type ServerConn

type ServerConn struct {
	ID       uuid.UUID
	Address  string
	Conn     net.Conn
	Client   *http.Client
	TLSConn  *tls.Conn
	TLSState *tls.ConnectionState
}

ServerConn represents a server connection.

func NewServerConn

func NewServerConn() *ServerConn

NewServerConn creates a new ServerConn instance.

func (*ServerConn) GetTLSState

func (c *ServerConn) GetTLSState() *tls.ConnectionState

GetTLSState returns the TLS connection state.

func (*ServerConn) MarshalJSON

func (c *ServerConn) MarshalJSON() ([]byte, error)

type WrapClientConn

type WrapClientConn struct {
	net.Conn

	ConnCtx *Context

	CloseChan chan struct{}
	// contains filtered or unexported fields
}

WrapClientConn wraps a net.Conn for remote client connections.

func NewWrapClientConn

func NewWrapClientConn(c net.Conn, addonNotifier AddonNotifier) *WrapClientConn

NewWrapClientConn creates a new wrapped client connection.

func (*WrapClientConn) Close

func (c *WrapClientConn) Close() error

Close closes the connection and notifies addons.

func (*WrapClientConn) Peek

func (c *WrapClientConn) Peek(n int) ([]byte, error)

Peek returns the next n bytes without advancing the reader.

func (*WrapClientConn) Read

func (c *WrapClientConn) Read(data []byte) (int, error)

Read reads data from the connection.

type WrapServerConn

type WrapServerConn struct {
	net.Conn
	ConnCtx *Context
	// contains filtered or unexported fields
}

WrapServerConn wraps a net.Conn for remote server connections.

func NewWrapServerConn

func NewWrapServerConn(c net.Conn, connCtx *Context, addonNotifier AddonNotifier) *WrapServerConn

NewWrapServerConn creates a new wrapped server connection.

func (*WrapServerConn) Close

func (c *WrapServerConn) Close() error

Close closes the connection and notifies addons.

Jump to

Keyboard shortcuts

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