quic

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package quic implements a ech.Dialer for QUIC connections.

It uses ech.Dialer for name resolution and finding the Encrypted Client Hello (ECH) Config List, and quic.DialAddr for establishing the QUIC connection.

Example
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

conn, err := Dial(ctx, "udp", "private.example.com", &tls.Config{}, &quic.Config{})
if err != nil {
	log.Fatalf("Dial: %v", err)
}
stream, err := conn.OpenStream()
if err != nil {
	log.Fatalf("conn.OpenStream: %v", err)
}
defer stream.Close()
fmt.Fprintln(stream, "Hello!")

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(ctx context.Context, network, addr string, tc *tls.Config, qc *quic.Config) (*quic.Conn, error)

Dial connects to the given network and address. Name resolution is done with ech.DefaultResolver. It uses HTTPS DNS records to retrieve the server's Encrypted Client Hello (ECH) Config List and uses it automatically if found.

If the name resolution returns multiple IP addresses, Dial iterates over them until a connection is successfully established.

Dial is equivalent to:

NewDialer(...).Dial(...)

For finer control, instantiate a ech.Dialer first with NewDialer. Then, call Dial, e.g.:

dialer := NewDialer(&quic.Config{})
dialer.RequireECH = true
conn, err := dialer.Dial(...)
Example
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

conn, err := Dial(ctx, "udp", "private.example.com", &tls.Config{}, &quic.Config{})
if err != nil {
	log.Fatalf("Dial: %v", err)
}
stream, err := conn.OpenStream()
if err != nil {
	log.Fatalf("conn.OpenStream: %v", err)
}
defer stream.Close()
fmt.Fprintln(stream, "Hello!")

func NewDialer added in v0.2.0

func NewDialer(qc *quic.Config) *ech.Dialer[*quic.Conn]

NewDialer returns a quic.Connection Dialer.

Example
dialer := NewDialer(&quic.Config{})
dialer.RequireECH = true
dialer.PublicName = "public.example.com"

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

conn, err := dialer.Dial(ctx, "udp", "private.example.com", &tls.Config{})
if err != nil {
	log.Fatalf("Dial: %v", err)
}
stream, err := conn.OpenStream()
if err != nil {
	log.Fatalf("conn.OpenStream: %v", err)
}
defer stream.Close()
fmt.Fprintln(stream, "Hello!")

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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