Documentation
¶
Index ¶
- Constants
- Variables
- type CertValidator
- type Config
- type Conn
- func (c *Conn) AcceptStream() (quic.Stream, error)
- func (c *Conn) Close() error
- func (c *Conn) Context() context.Context
- func (c *Conn) OpenStream(ctx context.Context) (quic.Stream, error)
- func (c *Conn) PeerKey() ed25519.PublicKey
- func (c *Conn) QConn() quic.Connection
- func (c *Conn) SetPeerKey(key ed25519.PublicKey)
- type ConnectionHandler
- type DefaultQuicDialer
- type QuicDialer
- type Transport
Constants ¶
const MaxIdleTimeout = 30 * time.Minute
MaxIdleTimeout defines the maximum duration a connection can be idle before timing out
const StreamTimeout = 5 * time.Second
StreamTimeout defines the maximum duration to wait for stream operations
Variables ¶
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 ¶
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 ¶
Close closes the connection and cancels all associated streams. Returns an error if closing the QUIC connection fails.
func (*Conn) Context ¶
Context returns the connection's context. This context is cancelled when the connection is closed.
func (*Conn) OpenStream ¶
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 ¶
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 ¶
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 QuicDialer ¶
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 ¶
NewTransport creates and configures a new transport instance. Returns an error if any required configuration is missing or invalid.
func (*Transport) Connect ¶
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)