transport

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIdleTimeout = 30 * time.Minute

MaxIdleTimeout defines the maximum duration a connection can be idle before timing out

View Source
const StreamTimeout = 5 * time.Second

StreamTimeout defines the maximum duration to wait for stream operations

Variables

View Source
var (
	ErrInvalidCertificate = errors.New("invalid certificate")
	ErrConnectionExists   = errors.New("connection already exists")
	ErrStreamClosed       = errors.New("stream closed")
	ErrListenerFailed     = errors.New("failed to create QUIC listener")
	ErrDialFailed         = errors.New("failed to dial peer")
	ErrConnFailed         = errors.New("failed to establish connection")
)

Functions

This section is empty.

Types

type CertValidator

type CertValidator interface {
	// ValidateCertificate checks if a certificate meets required criteria
	ValidateCertificate(cert *x509.Certificate) error
	// ExtractPublicKey retrieves the Ed25519 public key from a certificate
	ExtractPublicKey(cert *x509.Certificate) (ed25519.PublicKey, error)
}

CertValidator performs TLS certificate validation and public key extraction

type Config

type Config struct {
	PublicKey     ed25519.PublicKey  // Node's public key
	PrivateKey    ed25519.PrivateKey // Node's private key
	TLSCert       *tls.Certificate   // TLS certificate
	ListenAddr    *net.UDPAddr       // Address to listen on
	CertValidator CertValidator      // Certificate validator
	Handler       ConnectionHandler  // Connection handler
	Context       context.Context    // Context for transport lifecycle
}

Config holds all parameters needed to initialize a Transport. This includes cryptographic keys, network configuration, and handlers.

type Conn

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

Conn represents a QUIC connection with a remote peer. It manages the underlying QUIC connection, stream creation, and connection lifecycle via context cancellation.

func (*Conn) AcceptStream

func (c *Conn) AcceptStream() (quic.Stream, error)

AcceptStream accepts an incoming QUIC stream from the peer. Uses the connection's context for cancellation. Returns the accepted stream or an error if accepting fails.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection and cancels all associated streams. Returns an error if closing the QUIC connection fails.

func (*Conn) Context

func (c *Conn) Context() context.Context

Context returns the connection's context. This context is cancelled when the connection is closed.

func (*Conn) OpenStream

func (c *Conn) OpenStream(ctx context.Context) (quic.Stream, error)

OpenStream opens a new bidirectional QUIC stream. The provided context can be used to cancel the stream opening operation. Returns the new stream or an error if creation fails.

func (*Conn) PeerKey

func (c *Conn) PeerKey() ed25519.PublicKey

PeerKey returns the public key of the connected peer. This key uniquely identifies the remote peer.

func (*Conn) QConn

func (c *Conn) QConn() quic.Connection

func (*Conn) SetPeerKey

func (c *Conn) SetPeerKey(key ed25519.PublicKey)

SetPeerKey sets the peer's public key

type ConnectionHandler

type ConnectionHandler interface {
	// OnConnection is called after a new connection is established and authenticated.
	// The handler typically sets up protocol-specific streams and state.
	OnConnection(conn *Conn)
	// GetProtocols returns supported ALPN protocol strings
	GetProtocols() []string
	// ValidateConnection verifies TLS parameters including ALPN protocol selection.
	// This is called during the TLS handshake after certificate validation.
	ValidateConnection(tlsState tls.ConnectionState) error
}

ConnectionHandler defines how new connections are processed at the protocol level. This interface separates transport-level connection handling from protocol-specific behaviors.

type DefaultQuicDialer

type DefaultQuicDialer struct{}

Default implementation

func (*DefaultQuicDialer) DialAddr

func (d *DefaultQuicDialer) DialAddr(ctx context.Context, addr string, tlsConf *tls.Config, quicConfig *quic.Config) (quic.Connection, error)

type QuicDialer

type QuicDialer interface {
	DialAddr(ctx context.Context, addr string, tlsConf *tls.Config, quicConfig *quic.Config) (quic.Connection, error)
}

type Transport

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

Transport manages the networking layer of a JAMNP-S node. It handles: - Starting/stopping the QUIC listener - Initiating outbound connections - TLS handshakes and certificate validation - Forwarding authenticated connections to protocol handlers

func NewTransport

func NewTransport(config Config) (*Transport, error)

NewTransport creates and configures a new transport instance. Returns an error if any required configuration is missing or invalid.

func (*Transport) Connect

func (t *Transport) Connect(addr *net.UDPAddr) error

Connect initiates an outbound connection to a peer. The connection follows the same TLS configuration and validation as incoming connections.

func (*Transport) SetDialer

func (t *Transport) SetDialer(dialer QuicDialer)

func (*Transport) Start

func (t *Transport) Start() error

Start begins listening for incoming QUIC connections. It configures TLS with: - Required client certificates - TLS 1.3 minimum version - JAMNP-S certificate validation - ALPN protocol validation

func (*Transport) Stop

func (t *Transport) Stop() error

Stop gracefully shuts down the transport and all active connections. Waits for the accept loop to finish before returning.

Jump to

Keyboard shortcuts

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