quic

package
v0.9.16 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Name = "quic"
)

Variables

View Source
var (
	ErrMisconfiguredQuic  = errors.New("misconfigured Quic")
	ErrClosed             = errors.New("quic connection closed")
	ErrInvalidMsgType     = errors.New("invalid message type")
	ErrFromRedirectServer = errors.New("non-300 response from redirect server")
	ErrSendTimeout        = errors.New("wrp message send timed out")
	ErrHttp3NotSupported  = errors.New("http3 protocol not supported")
)

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// AcceptStream returns the next stream opened by the peer, blocking until one is available.
	// If the connection was closed due to a timeout, the error satisfies
	// the net.Error interface, and Timeout() will be true.
	AcceptStream(context.Context) (Stream, error)
	// AcceptUniStream returns the next unidirectional stream opened by the peer, blocking until one is available.
	// If the connection was closed due to a timeout, the error satisfies
	// the net.Error interface, and Timeout() will be true.
	//AcceptUniStream(context.Context) (Stream, error)
	// OpenStream opens a new bidirectional QUIC stream.
	// There is no signaling to the peer about new streams:
	// The peer can only accept the stream after data has been sent on the stream,
	// or the stream has been reset or closed.
	// When reaching the peer's stream limit, it is not possible to open a new stream until the
	// peer raises the stream limit. In that case, a StreamLimitReachedError is returned.
	OpenStream() (Stream, error)
	// OpenStreamSync opens a new bidirectional QUIC stream.
	// It blocks until a new stream can be opened.
	// There is no signaling to the peer about new streams:
	// The peer can only accept the stream after data has been sent on the stream,
	// or the stream has been reset or closed.
	//OpenStreamSync(context.Context) (Stream, error)
	// OpenUniStream opens a new outgoing unidirectional QUIC stream.
	// There is no signaling to the peer about new streams:
	// The peer can only accept the stream after data has been sent on the stream,
	// or the stream has been reset or closed.
	// When reaching the peer's stream limit, it is not possible to open a new stream until the
	// peer raises the stream limit. In that case, a StreamLimitReachedError is returned.
	//OpenUniStream() (Stream, error)
	// OpenUniStreamSync opens a new outgoing unidirectional QUIC stream.
	// It blocks until a new stream can be opened.
	// There is no signaling to the peer about new streams:
	// The peer can only accept the stream after data has been sent on the stream,
	// or the stream has been reset or closed.
	//OpenUniStreamSync(context.Context) (Stream, error)
	// LocalAddr returns the local address.
	//LocalAddr() net.Addr
	// RemoteAddr returns the address of the peer.
	//RemoteAddr() net.Addr
	// CloseWithError closes the connection with an error.
	// The error string will be sent to the peer.
	CloseWithError(quic.ApplicationErrorCode, string) error
}

type ConnectionWrapper added in v0.8.0

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

func (ConnectionWrapper) AcceptStream added in v0.8.0

func (w ConnectionWrapper) AcceptStream(ctx context.Context) (Stream, error)

func (ConnectionWrapper) CloseWithError added in v0.8.0

func (w ConnectionWrapper) CloseWithError(code quic.ApplicationErrorCode, msg string) error

func (ConnectionWrapper) OpenStream added in v0.8.0

func (w ConnectionWrapper) OpenStream() (Stream, error)

type Dialer

type Dialer interface {
	DialQuic(ctx context.Context, url *url.URL) (Connection, error)
}

type Egress

type Egress interface {
	// HandleWrp is called whenever a message targets something other than this device.
	HandleWrp(m wrp.Message) error
}

Egress interface is the egress route used to handle wrp messages that targets something other than this device

type Http3ClientConfig

type Http3ClientConfig struct {
	QuicConfig quic.Config
	TlsConfig  tls.Config
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is a functional option type for Quic.

func AddConnectListener

func AddConnectListener(listener event.ConnectListener, cancel ...*event.CancelFunc) Option

AddConnectListener adds a connect listener to the WS connection.

func AddDisconnectListener

func AddDisconnectListener(listener event.DisconnectListener, cancel ...*event.CancelFunc) Option

AddDisconnectListener adds a disconnect listener to the WS connection.

func AddMessageListener

func AddMessageListener(listener event.MsgListener, cancel ...*event.CancelFunc) Option

AddMessageListener adds a message listener to the WS connection. The listener will be called for every message received from the WS.

func AdditionalHeaders

func AdditionalHeaders(headers http.Header) Option

AdditionalHeaders sets the additional headers for the WS connection.

func ConveyDecorator

func ConveyDecorator(f func(http.Header) error) Option

writes identity metadata to convey header on connect with the cloud

func ConveyMsgDecorator added in v0.8.2

func ConveyMsgDecorator(f func(*wrp.Message) error) Option

writes identity metadata directly to every outbound message.

func CredentialsDecorator

func CredentialsDecorator(f func(http.Header) error) Option

CredentialsDecorator provides the credentials decorator for the WS connection.

func DeviceID

func DeviceID(id wrp.DeviceID) Option

DeviceID sets the device ID for the WS connection.

func Enabled

func Enabled(enabled bool) Option

func FetchURL

func FetchURL(f func(context.Context) (string, error)) Option

FetchURL sets the FetchURL for the WS connection.

func FetchURLTimeout

func FetchURLTimeout(d time.Duration) Option

FetchURLTimeout sets the FetchURLTimeout for the WS connection. If this is not set, the default is 30 seconds.

func HTTP3Client

func HTTP3Client(c *Http3ClientConfig) Option

HTTPClient is the configuration for the HTTP3 client used for connection attempts.

func KeepAliveInterval

func KeepAliveInterval(d time.Duration) Option

KeepAliveInterval sets the keep alive interval for the WS connection. If this is not set, the default is 30 seconds.

func NowFunc

func NowFunc(f func() time.Time) Option

NowFunc sets the now function for the WS connection.

func Once

func Once(once ...bool) Option

Once sets whether or not to only attempt to connect once.

func RetryPolicy

func RetryPolicy(pf retry.PolicyFactory) Option

RetryPolicy sets the retry policy factory used for delaying between retry attempts for reconnection.

func SendTimeout

func SendTimeout(d time.Duration) Option

SendTimeout sets the send timeout for the WS connection.

func URL

func URL(url string) Option

URL sets the URL for the quic connection.

type QuicClient

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

func New

func New(opts ...Option) (*QuicClient, error)

New creates a new http3 connection with the given options.

func (*QuicClient) AddConnectListener added in v0.7.35

func (qc *QuicClient) AddConnectListener(listener event.ConnectListener) event.CancelFunc

AddConnectListener adds a connect listener to the quic connection. The listener will be called every time the connection succeeds or fails

func (*QuicClient) AddMessageListener

func (qc *QuicClient) AddMessageListener(listener event.MsgListener) event.CancelFunc

AddMessageListener adds a message listener to the quic connection. The listener will be called for every message received from the cloud.

func (*QuicClient) HandleWrp

func (qc *QuicClient) HandleWrp(m wrp.Message) error

func (*QuicClient) IsEnabled

func (qc *QuicClient) IsEnabled() bool

func (*QuicClient) Name

func (qc *QuicClient) Name() string

func (*QuicClient) Send

func (qc *QuicClient) Send(ctx context.Context, msg wrp.Message) error

Send sends the provided WRP message through the existing quic connection.

func (*QuicClient) Start

func (qc *QuicClient) Start()

Start starts the http3 connection and a long running goroutine to maintain the connection.

func (*QuicClient) Stop

func (qc *QuicClient) Stop()

Stop stops the quic connection.

type QuicDialer

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

func (*QuicDialer) DialQuic

func (qd *QuicDialer) DialQuic(ctx context.Context, url *url.URL) (Connection, error)

NOTE - with an older version of quic: when using an http.Client, the quic connection seems to always get re-created and the client no longer had access to the current quic connection. The below "dialer" uses the http3.ClientConn api directly and that api uses the passed in connection. However, retry now that quic has been updated.

type Redirector

type Redirector interface {
	GetUrl(ctx context.Context, inUrl *url.URL) (*url.URL, error)
}

type Stream added in v0.8.0

type Stream interface {
	StreamID() quic.StreamID
	Read(p []byte) (int, error)
	Write(p []byte) (int, error)
	CancelRead(errorCode quic.StreamErrorCode)
	Context() context.Context
	Close() error
	SetReadDeadline(t time.Time) error
	SetDeadline(t time.Time) error
}

type UrlRedirector

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

func (*UrlRedirector) GetUrl

func (r *UrlRedirector) GetUrl(ctx context.Context, inUrl *url.URL) (*url.URL, error)

Retrieve the url from the redirect server, if there is one. Stop the redirect. Possibly temporary solution until we figure out how to retrieve the new connection in the client after a seamless redirect.

Directories

Path Synopsis
cmd
example command

Jump to

Keyboard shortcuts

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