dquic

package
v0.0.0-...-d223f38 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dquic contains common functionality for QUIC types shared in both the root dragon package and some test packages around QUIC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *quic.Config

func MakeTransport

func MakeTransport(connContext context.Context, udpConn *net.UDPConn) *quic.Transport

MakeTransport returns a quic.Transport. The transport is used for finer conrol over connection behavior than a simple call to quic.Listen.

func StartListener

func StartListener(
	baseTLSConf *tls.Config,
	caPool *dcert.Pool,
	quicConf *quic.Config,
	qt *quic.Transport,
) (*quic.Listener, error)

Types

type ApplicationErrorCode

type ApplicationErrorCode uint64

ApplicationErrorCode is used for Conn.CloseWithError.

const (
	CARemoved ApplicationErrorCode = 0x0b18_1c9b_757d_05de // Decimal: 799420387874899422

	CARemovedMessage = "CA removed from trusted pool"
)

type Conn

type Conn interface {
	Context() context.Context

	AcceptStream(context.Context) (Stream, error)
	AcceptUniStream(context.Context) (ReceiveStream, error)

	OpenStreamSync(context.Context) (Stream, error)
	OpenUniStreamSync(context.Context) (SendStream, error)

	SendDatagram([]byte) error
	ReceiveDatagram(context.Context) ([]byte, error)

	CloseWithError(
		code ApplicationErrorCode, msg string,
	) error

	// This diverges from the quic.Conn interface.
	// Instead of exposing their entire connection state,
	// we only expose the TLS details that we use occasionally in dragon.
	TLSConnectionState() tls.ConnectionState

	LocalAddr() net.Addr
	RemoteAddr() net.Addr
}

Conn is the interface representing a QUIC connection.

This is mostly a subset of the methods on *quic.Conn, only referencing the methods used in dragon.

type ConnAdapter

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

ConnAdapter wraps a *quic.Conn, implementing the Conn interface.

Create an instance with WrapConn.

func WrapConn

func WrapConn(qc *quic.Conn) ConnAdapter

WrapConn wraps the given connection, returning a value implementing Conn.

func (ConnAdapter) AcceptStream

func (c ConnAdapter) AcceptStream(ctx context.Context) (Stream, error)

func (ConnAdapter) AcceptUniStream

func (c ConnAdapter) AcceptUniStream(ctx context.Context) (ReceiveStream, error)

func (ConnAdapter) CloseWithError

func (c ConnAdapter) CloseWithError(
	code ApplicationErrorCode, msg string,
) error

func (ConnAdapter) Context

func (c ConnAdapter) Context() context.Context

func (ConnAdapter) LocalAddr

func (c ConnAdapter) LocalAddr() net.Addr

func (ConnAdapter) OpenStreamSync

func (c ConnAdapter) OpenStreamSync(ctx context.Context) (Stream, error)

func (ConnAdapter) OpenUniStreamSync

func (c ConnAdapter) OpenUniStreamSync(ctx context.Context) (SendStream, error)

func (ConnAdapter) ReceiveDatagram

func (c ConnAdapter) ReceiveDatagram(ctx context.Context) ([]byte, error)

func (ConnAdapter) RemoteAddr

func (c ConnAdapter) RemoteAddr() net.Addr

func (ConnAdapter) SendDatagram

func (c ConnAdapter) SendDatagram(p []byte) error

func (ConnAdapter) TLSConnectionState

func (c ConnAdapter) TLSConnectionState() tls.ConnectionState

type DialResult

type DialResult struct {
	Conn Conn

	// A channel that is closed when the peer's CA certificate
	// is removed from the trusted CA pool.
	NotifyCARemoved <-chan struct{}
}

DialResult is the return type for Dialer.Dial.

type Dialer

type Dialer struct {
	BaseTLSConf *tls.Config

	QUICTransport *quic.Transport
	QUICConfig    *quic.Config

	CAPool *dcert.Pool
}

Dialer handles establishing QUIC connections with remote peers.

func (Dialer) Dial

func (d Dialer) Dial(ctx context.Context, addr net.Addr) (DialResult, error)

Dial opens a QUIC connection to the given address, using appropriate TLS configuration that respects the current d.CAPool.

The returned dial result includes a NotifyCARemoved channel which is closed if the remote's CA is removed from the trusted pool. It is the caller's responsibility to handle closing the returned connection upon detecting that the NotifyCARemoved channel is closed.

type ReceiveStream

type ReceiveStream interface {
	Read([]byte) (int, error)
	CancelRead(StreamErrorCode)

	SetReadDeadline(time.Time) error
}

ReceiveStream is the read-only version of a Stream.

type ReceiveStreamAdapter

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

ReceiveStreamAdapter wraps a *quic.ReceiveStream to satisfy the ReceiveStream interface. Use WrapReceiveStream to create an instance.

func WrapReceiveStream

func WrapReceiveStream(s *quic.ReceiveStream) ReceiveStreamAdapter

WrapReceiveStream wraps s into a ReceiveStreamAdapter, satifying the ReceiveStream interface.

func (ReceiveStreamAdapter) CancelRead

func (a ReceiveStreamAdapter) CancelRead(code StreamErrorCode)

func (ReceiveStreamAdapter) Read

func (a ReceiveStreamAdapter) Read(p []byte) (int, error)

func (ReceiveStreamAdapter) SetReadDeadline

func (a ReceiveStreamAdapter) SetReadDeadline(t time.Time) error

type SendStream

type SendStream interface {
	Write([]byte) (int, error)
	CancelWrite(StreamErrorCode)

	Close() error

	SetWriteDeadline(t time.Time) error
}

SendStream is the write-only version of a Stream.

type SendStreamAdapter

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

SendStreamAdapter wraps a *quic.SendStream to satisfy the SendStream interface. Use WrapSendStream to create an instance.

func WrapSendStream

func WrapSendStream(s *quic.SendStream) SendStreamAdapter

WrapSendStream wraps s into a SendStreamAdapter, satifying the SendStream interface.

func (SendStreamAdapter) CancelWrite

func (a SendStreamAdapter) CancelWrite(code StreamErrorCode)

func (SendStreamAdapter) Close

func (a SendStreamAdapter) Close() error

func (SendStreamAdapter) SetWriteDeadline

func (a SendStreamAdapter) SetWriteDeadline(t time.Time) error

func (SendStreamAdapter) Write

func (a SendStreamAdapter) Write(p []byte) (int, error)

type Stream

type Stream interface {
	SendStream
	ReceiveStream
}

Stream is a readable and writable QUIC stream.

type StreamAdapter

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

func WrapStream

func WrapStream(s *quic.Stream) StreamAdapter

func (StreamAdapter) CancelRead

func (a StreamAdapter) CancelRead(code StreamErrorCode)

func (StreamAdapter) CancelWrite

func (a StreamAdapter) CancelWrite(code StreamErrorCode)

func (StreamAdapter) Close

func (a StreamAdapter) Close() error

func (StreamAdapter) Read

func (a StreamAdapter) Read(p []byte) (int, error)

func (StreamAdapter) SetReadDeadline

func (a StreamAdapter) SetReadDeadline(t time.Time) error

func (StreamAdapter) SetWriteDeadline

func (a StreamAdapter) SetWriteDeadline(t time.Time) error

func (StreamAdapter) Write

func (a StreamAdapter) Write(p []byte) (int, error)

type StreamErrorCode

type StreamErrorCode uint64

StreamErrorCode is used for ReceiveStream.CancelRead and SendStream.CancelWrite, to inform the peer of why the stream is canceled.

Directories

Path Synopsis
Package dquictest contains stub implementations of quic interfaces.
Package dquictest contains stub implementations of quic interfaces.

Jump to

Keyboard shortcuts

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