quicwrapper

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

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 2

README

quicwrapper

implements several net interfaces using the quic-go library.

Documentation

Overview

Wraps quic structures in standard net interfaces and improves context awareness. Conn instances created by this package may be multiplexed

Index

Constants

View Source
const (

	// This the value represents HTTP/3 protocol (over quic v1).
	AlpnH3 = "h3"
	// This the value represents HTTP/3 protocol (over quic draft 29).
	AlpnH3_29 = "h3-29"
)

Variables

View Source
var (
	ErrListenerClosed = errors.New("listener closed")

	// client asks for this unless explicitly specified in tls.Config
	DefaultClientProtos = []string{AlpnH3}
	// server accepts these unless explicitly specified in tls.Config
	DefaultServerProtos = []string{AlpnH3, AlpnH3_29}
)

Functions

func DialUDPNetx

func DialUDPNetx(addr string) (net.PacketConn, *net.UDPAddr, error)

DialUDPNetx is a UDPDialFn that resolves addresses and obtains the net.PacketConn using the netx package.

func IsPeerGoingAway

func IsPeerGoingAway(err error) bool

func Listen

func Listen(pconn net.PacketConn, tlsConf *tls.Config, config *Config) (net.Listener, error)

Listen creates a QUIC server listening on a given net.PacketConn The net.Conn instances returned by the net.Listener may be multiplexed connections. The caller is responsible for closing the net.PacketConn after the listener has been closed.

func ListenAddr

func ListenAddr(addr string, tlsConf *tls.Config, config *Config) (net.Listener, error)

ListenAddr creates a QUIC server listening on a given address. The net.Conn instances returned by the net.Listener may be multiplexed connections.

Types

type Client

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

func NewClient

func NewClient(addr string, tlsConf *tls.Config, config *Config, dial QuicDialFn) *Client

NewClient returns a client that creates multiplexed QUIC connections in a single Session with the given address using the provided configuration.

The Session is created using the QuicDialFn given, but is not established until the first call to Dial(), DialContext() or Connect()

if dial is nil, the default quic dialer is used

func NewClientWithPinnedCert

func NewClientWithPinnedCert(addr string, tlsConf *tls.Config, config *Config, dial QuicDialFn, cert *x509.Certificate) *Client

NewClientWithPinnedCert returns a new client configured as with NewClient, but accepting only a specific given certificate. If the certificate presented by the connected server does match the given certificate, the connection is rejected. This check is performed regardless of tls.Config settings (ie even if InsecureSkipVerify is true)

If a nil certificate is given, the check is not performed and any valid certificate according the tls.Config given is accepted (equivalent to NewClient behavior)

func (*Client) Close

func (c *Client) Close() error

closes the session established by this client (and all multiplexed connections)

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect requests immediate handshaking regardless of whether any specific Dial has been initiated. It is called lazily on the first Dial if not otherwise called.

This can serve to pre-establish a multiplexed session, but will also initiate idle timeout tracking, keepalives etc. Returns any error encountered during handshake.

This may safely be called concurrently with Dial. The handshake is guaranteed to be completed when the call returns to any caller.

func (*Client) Dial

func (c *Client) Dial() (net.Conn, error)

Dial creates a new multiplexed QUIC connection to the server configured for the client.

func (*Client) DialContext

func (c *Client) DialContext(ctx context.Context) (net.Conn, error)

DialContext creates a new multiplexed QUIC connection to the server configured in the client. The given Context governs cancellation / timeout. If initial handshaking is performed, the operation is additionally governed by HandshakeTimeout value given in the client Config.

type Config

type Config = quic.Config

type Conn

type Conn struct {
	quic.Stream
	// contains filtered or unexported fields
}

wraps quic.Stream and other info to implement net.Conn

func (*Conn) Close

func (c *Conn) Close() error

implements net.Conn.Close

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

implements net.Conn.LocalAddr

func (*Conn) PeerCertificates

func (c *Conn) PeerCertificates() []*x509.Certificate

Returns certificates presented by peer

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

implements net.Conn.Read

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

implements net.Conn.RemoteAddr

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

implements net.Conn.Write

type QuicDialFn

type QuicDialFn func(ctx context.Context, addr string, tlsConf *tls.Config, config *quic.Config) (quic.Connection, error)

a QuicDialFn is a function that may be used to establish a new QUIC Session

var (
	DialWithNetx    QuicDialFn = newDialerWithUDPDialer(DialUDPNetx)
	DialWithoutNetx QuicDialFn = quic.DialAddr
)

type UDPDialFn

type UDPDialFn func(addr string) (net.PacketConn, *net.UDPAddr, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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