Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcceptableProtocols ¶
AcceptableProtocols returns all acceptable protocol strings for a given chain hash. Returns both builder and non-builder variants of the protocol identifier.
func ValidateALPNProtocol ¶
ValidateALPNProtocol validates an ALPN protocol string according to JAMNP-S specification. This is a convenience wrapper around ParseProtocolID that only returns the error status.
Types ¶
type Config ¶
type Config struct {
// ChainHash is the identifier of the blockchain network
ChainHash string
// IsBuilder indicates if this node is a block builder
IsBuilder bool
// MaxBuilderSlots specifies the maximum number of concurrent builder connections
MaxBuilderSlots int
}
Config represents the configuration for a protocol Manager
type JAMNPRegistry ¶
type JAMNPRegistry struct {
// contains filtered or unexported fields
}
JAMNPRegistry manages stream handlers for different protocol stream kinds
func NewJAMNPRegistry ¶
func NewJAMNPRegistry() *JAMNPRegistry
NewJAMNPRegistry creates a new registry for stream handlers
func (*JAMNPRegistry) GetHandler ¶
func (r *JAMNPRegistry) GetHandler(kind StreamKind) (StreamHandler, error)
GetHandler retrieves the handler associated with a given stream kind byte Returns an error if no handler is registered for the kind
func (*JAMNPRegistry) RegisterHandler ¶
func (r *JAMNPRegistry) RegisterHandler(kind StreamKind, handler StreamHandler)
RegisterHandler associates a stream handler with a specific stream kind. When a stream of the registered kind is opened, the corresponding handler will be invoked to process it. This method is called during protocol initialization to set up handlers for supported stream kinds.
func (*JAMNPRegistry) ValidateKind ¶
func (r *JAMNPRegistry) ValidateKind(kindByte byte) error
ValidateKind checks if a given byte represents a valid stream kind Returns an error if the kind is outside the valid range
type Manager ¶
type Manager struct {
Registry *JAMNPRegistry
// contains filtered or unexported fields
}
Manager handles protocol-level connection management and implements transport.ConnectionHandler. It manages protocol connections, stream handling, and protocol validation.
func NewManager ¶
NewManager creates a new protocol Manager with the given configuration. It validates the configuration and initializes a new JAMNPRegistry. Returns an error if the chain hash is empty or invalid.
func (*Manager) GetProtocols ¶
GetProtocols returns the list of supported ALPN protocol strings. The returned protocols include both builder and non-builder variants. Implements the transport.ConnectionHandler interface.
func (*Manager) OnConnection ¶
func (m *Manager) OnConnection(conn TransportConn) *ProtocolConn
OnConnection is called when a new transport connection is established. It sets up a protocol connection and starts a stream handling goroutine.
func (*Manager) ValidateConnection ¶
func (m *Manager) ValidateConnection(tlsState tls.ConnectionState) error
ValidateConnection validates a new TLS connection's protocol negotiation. It checks the negotiated protocol matches the expected format and configuration. Implements the transport.ConnectionHandler interface.
type ProtocolConn ¶
type ProtocolConn struct {
TConn TransportConn
Registry *JAMNPRegistry
// contains filtered or unexported fields
}
ProtocolConn wraps a transport connection with protocol-specific functionality. It manages stream multiplexing, handles stream kinds, and maintains unique persistent streams.
func NewProtocolConn ¶
func NewProtocolConn(tConn TransportConn, registry *JAMNPRegistry) *ProtocolConn
NewProtocolConn creates a new protocol-level connection. It initializes stream management and associates the connection with a handler registry.
func (*ProtocolConn) AcceptStream ¶
func (pc *ProtocolConn) AcceptStream() error
AcceptStream accepts and handles an incoming stream. It reads the stream kind byte, looks up the appropriate handler, and starts a goroutine to handle the stream. Returns an error if accepting the stream or reading the kind fails.
func (*ProtocolConn) Close ¶
func (pc *ProtocolConn) Close() error
Close closes the protocol connection and all associated UP streams. It ensures all resources are properly cleaned up. Returns an error if closing the underlying transport connection fails.
func (*ProtocolConn) OpenStream ¶
func (pc *ProtocolConn) OpenStream(ctx context.Context, kind StreamKind) (quic.Stream, error)
OpenStream opens a new stream of the given kind using the provided context. It writes the stream kind as the first byte and returns the established stream. Returns an error if stream creation or initial write fails.
type ProtocolID ¶
type ProtocolID struct {
// Version is the protocol version (currently only "0")
Version string
// ChainHash is the 8-nibble chain identifier
ChainHash string
// IsBuilder indicates if this is a builder connection
IsBuilder bool
}
ProtocolID represents a complete ALPN protocol identifier. Format: jamnp-s/<version>/<chain-hash>[/builder]
func NewProtocolID ¶
func NewProtocolID(chainHash string, isBuilder bool) *ProtocolID
NewProtocolID creates a new ProtocolID with the specified chain hash and builder status. The version is automatically set to the current supported version.
func ParseProtocolID ¶
func ParseProtocolID(protocol string) (*ProtocolID, error)
ParseProtocolID parses an ALPN protocol string into a ProtocolID. Validates:
- Correct format and number of parts
- Valid prefix
- Supported version
- Chain hash format (8 hex nibbles)
- Optional builder suffix
Returns an error if any validation fails.
func (*ProtocolID) String ¶
func (p *ProtocolID) String() string
String converts the ProtocolID to its string representation. Format examples:
- Non-builder: "jamnp-s/0/deadbeef"
- Builder: "jamnp-s/0/deadbeef/builder"
type StreamHandler ¶
type StreamHandler interface {
HandleStream(ctx context.Context, stream quic.Stream, peerKey ed25519.PublicKey) error
}
StreamHandler processes individual QUIC streams within a connection
type StreamKind ¶
type StreamKind byte
StreamKind represents the type of stream (Unique Persistent or Common Ephemeral)
const ( // UP (Unique Persistent) stream is 0 StreamKindBlockAnnouncement StreamKind = 0 // CE (Common Ephemeral) streams start from 128 StreamKindBlockRequest StreamKind = 128 StreamKindStateRequest StreamKind = 129 StreamKindSafroleTicketSubmit StreamKind = 131 StreamKindSafroleTicketDist StreamKind = 132 StreamKindWorkPackageSubmit StreamKind = 133 StreamKindWorkReportDist StreamKind = 135 StreamKindWorkReportRequest StreamKind = 136 StreamKindShardDist StreamKind = 137 StreamKindAuditShardRequest StreamKind = 138 StreamKindSegmentRequest StreamKind = 139 StreamKindSegmentRequestJust StreamKind = 140 StreamKindAssuranceDist StreamKind = 141 StreamKindPreimageAnnounce StreamKind = 142 StreamKindPreimageRequest StreamKind = 143 StreamKindAuditAnnouncement StreamKind = 144 StreamKindJudgmentPublish StreamKind = 145 )
func (StreamKind) IsUniquePersistent ¶
func (k StreamKind) IsUniquePersistent() bool
IsUniquePersistent determines if a stream kind is Unique Persistent (UP) Returns true for UP streams (values < 128) and false for Common Ephemeral (CE) streams
type TransportConn ¶
type TransportConn interface {
OpenStream(ctx context.Context) (quic.Stream, error)
AcceptStream() (quic.Stream, error)
Context() context.Context
PeerKey() ed25519.PublicKey
QConn() quic.Connection
Close() error
}
TransportConn is an interface that abstracts the transport.Conn functionality This makes it easier to mock for testing