package quicreuse

import "github.com/libp2p/go-libp2p/p2p/transport/quicreuse"

Index

Functions

func FromQuicMultiaddr

func FromQuicMultiaddr(addr ma.Multiaddr) (*net.UDPAddr, quic.Version, error)

func ToQuicMultiaddr

func ToQuicMultiaddr(na net.Addr, version quic.Version) (ma.Multiaddr, error)

func WithAssociation

func WithAssociation(ctx context.Context, association any) context.Context

WithAssociation returns a new context with the given association. Used in DialQUIC to prefer a transport that has the given association.

Types

type ConnManager

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

func NewConnManager

func NewConnManager(statelessResetKey quic.StatelessResetKey, tokenKey quic.TokenGeneratorKey, opts ...Option) (*ConnManager, error)

func (*ConnManager) ClientConfig

func (c *ConnManager) ClientConfig() *quic.Config

func (*ConnManager) Close

func (c *ConnManager) Close() error

func (*ConnManager) DialQUIC

func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error)

func (*ConnManager) LendTransport

func (c *ConnManager) LendTransport(network string, tr QUICTransport, conn net.PacketConn) (<-chan struct{}, error)

LendTransport is an advanced method used to lend an existing QUICTransport to the ConnManager. The ConnManager will close the returned channel when it is done with the transport, so that the owner may safely close the transport.

func (*ConnManager) ListenQUIC

func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (Listener, error)

func (*ConnManager) ListenQUICAndAssociate

func (c *ConnManager) ListenQUICAndAssociate(association any, addr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (Listener, error)

ListenQUICAndAssociate returns a QUIC listener and associates the underlying transport with the given association.

func (*ConnManager) Protocols

func (c *ConnManager) Protocols() []int

func (*ConnManager) SharedNonQUICPacketConn

func (c *ConnManager) SharedNonQUICPacketConn(network string, laddr *net.UDPAddr) (net.PacketConn, error)

func (*ConnManager) TransportForDial

func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refCountedQuicTransport, error)

func (*ConnManager) TransportWithAssociationForDial

func (c *ConnManager) TransportWithAssociationForDial(association any, network string, raddr *net.UDPAddr) (refCountedQuicTransport, error)

TransportWithAssociationForDial returns a QUIC transport for dialing, preferring a transport with the given association.

type Listener

type Listener interface {
	Accept(context.Context) (quic.Connection, error)
	Addr() net.Addr
	Multiaddrs() []ma.Multiaddr
	io.Closer
}

type Option

type Option func(*ConnManager) error

func DisableReuseport

func DisableReuseport() Option

func EnableMetrics

func EnableMetrics(reg prometheus.Registerer) Option

EnableMetrics enables Prometheus metrics collection. If reg is nil, prometheus.DefaultRegisterer will be used as the registerer.

func OverrideListenUDP

func OverrideListenUDP(f listenUDP) Option

func OverrideSourceIPSelector

func OverrideSourceIPSelector(f func() (SourceIPSelector, error)) Option

type QUICListener

type QUICListener interface {
	Accept(ctx context.Context) (quic.Connection, error)
	Close() error
	Addr() net.Addr
}

type QUICTransport

type QUICTransport interface {
	Listen(tlsConf *tls.Config, conf *quic.Config) (QUICListener, error)
	Dial(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (quic.Connection, error)
	WriteTo(b []byte, addr net.Addr) (int, error)
	ReadNonQUICPacket(ctx context.Context, b []byte) (int, net.Addr, error)
	io.Closer
}

type SourceIPSelector

type SourceIPSelector interface {
	PreferredSourceIPForDestination(dst *net.UDPAddr) (net.IP, error)
}

Source Files

config.go connmgr.go listener.go nonquic_packetconn.go options.go quic_multiaddr.go reuse.go tracer.go

Version
v0.41.1 (latest)
Published
Mar 24, 2025
Platform
linux/amd64
Imports
24 packages
Last checked
2 weeks ago

Tools for package owners.