tinywss

package module
v0.0.0-...-c10008a Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 22 Imported by: 3

README

tinywss

A module for establishing a rudimentary secure "websocket". Performs websocket handshake, but does not actually enforce the websocket protocol for data exchanged afterwards. Exposes a dialer and listener returning objects conforming to net.Conn and net.Listener.

It is not meant to be compatible with anything but itself.

Documentation

Overview

tinywss

A module for establishing a rudimentary secure "websocket". Performs websocket handshake, but does not actually enforce the websocket protocol for data exchanged afterwards. Exposes a dialer and listener returning objects conforming to net.Conn and net.Listener.

It is not meant to be compatible with anything but itself.

Index

Constants

View Source
const (
	// ProtocolRaw specifies a raw (not multiplexed) connection
	ProtocolRaw = "tinywss-raw"
	// ProtocolMux specifies a multiplexed connection
	ProtocolMux = "tinywss-smux"
)

Variables

View Source
var (
	// ErrListenerClosed is the error returned if listener is used after closed
	ErrListenerClosed = errors.New("listener closed")
	// ErrDialerClosed is the error returned if client is used after closed
	ErrClientClosed = errors.New("client closed")
)

Functions

func ListenAddr

func ListenAddr(opts *ListenOpts) (net.Listener, error)

ListenAddr starts a tinywss server listening at the configured address.

func NewRoundTripper

func NewRoundTripper(dial DialFN) *roundTripHijacker

creates a new default RoundTripHijacker

Types

type Client

type Client interface {

	// DialContext attempts to dial the configured server, returning an error if
	// the context given expires before the server can be contacted.
	DialContext(ctx context.Context) (net.Conn, error)

	// Close shuts down any resources associated with the client
	Close() error
}

func NewClient

func NewClient(opts *ClientOpts) Client

NewClient constructs a new tinywss.Client with the specified options

type ClientOpts

type ClientOpts struct {
	URL             string
	MaxPendingDials int64
	RoundTrip       RoundTripHijacker
	Headers         http.Header

	// Multiplex Options
	Multiplexed       bool
	KeepAliveInterval time.Duration
	KeepAliveTimeout  time.Duration
	MaxFrameSize      int
	MaxReceiveBuffer  int
}

ClientOpts contains configuration options for NewClient

type DialFN

type DialFN func(network, addr string) (net.Conn, error)

func TLSDialFN

func TLSDialFN(tlsConf *tls.Config) DialFN

type HandshakeError

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

HandshakeError is returned when handshake expectations fail

func (HandshakeError) Error

func (e HandshakeError) Error() string

type ListenOpts

type ListenOpts struct {
	Addr             string
	CertFile         string
	KeyFile          string
	TLSConf          *tls.Config
	HandshakeTimeout time.Duration
	Protocols        []string // allowed protocols

	// If provided, this listener is used instead of starting
	// a TLS listener using the tls configuration specified.
	// Addr, CertFile, KeyFile and TLSConf are ignored if this
	// is given.
	Listener net.Listener

	// Multiplex options
	KeepAliveInterval time.Duration
	KeepAliveTimeout  time.Duration
	MaxFrameSize      int
	MaxReceiveBuffer  int
}

Configuration options for ListenAddr

type RoundTripHijacker

type RoundTripHijacker interface {
	RoundTripHijack(*http.Request) (*http.Response, net.Conn, error)
}

RoundTripHijacker is the interface used by the Client to make the HTTP upgrade request and hijack the the underlying connection.

type WsConn

type WsConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*WsConn) Close

func (c *WsConn) Close() error

implements net.Conn.Close()

func (*WsConn) UpgradeHeaders

func (c *WsConn) UpgradeHeaders() http.Header

returns the headers on the initial HTTP connection that was upgraded to create this WsConn.

func (*WsConn) Wrapped

func (c *WsConn) Wrapped() net.Conn

Wrapped implements the interface netx.WrappedConn

Jump to

Keyboard shortcuts

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