protocol

package
v0.1.0-p8a.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionV1    = 1
	MaxFrameSize = 1024 * 1024
	MaxIDLength  = 128
)
View Source
const (
	TransferProtocolVersion  = 1
	MaxTransferChunkBytes    = 256 * 1024
	MaxTransferMetadataBytes = 16 * 1024
	MaxTransferFileBytes     = 1024 * 1024 * 1024
)

Variables

View Source
var (
	ErrFrameTooLarge = errors.New("node protocol frame exceeds size limit")
	ErrInvalidFrame  = errors.New("invalid node protocol frame")
)
View Source
var (
	ErrInvalidTransferFrame = errors.New("invalid node transfer frame")
)

Functions

func Encode

func Encode(envelope Envelope) ([]byte, error)

func EncodeTransferFrame

func EncodeTransferFrame(frame TransferFrame) ([]byte, error)

func Schema

func Schema(name string) ([]byte, error)

Types

type Envelope

type Envelope struct {
	Type           FrameType       `json:"type"`
	ID             string          `json:"id,omitempty"`
	Method         string          `json:"method,omitempty"`
	Params         json.RawMessage `json:"params,omitempty"`
	IdempotencyKey string          `json:"idempotency_key,omitempty"`
	OK             *bool           `json:"ok,omitempty"`
	Result         json.RawMessage `json:"result,omitempty"`
	Error          *Error          `json:"error,omitempty"`
	Event          string          `json:"event,omitempty"`
	Payload        json.RawMessage `json:"payload,omitempty"`
}

func Decode

func Decode(data []byte) (Envelope, error)

func (Envelope) Validate

func (envelope Envelope) Validate() error

type Error

type Error struct {
	Code    string          `json:"code"`
	Message string          `json:"message"`
	Details json.RawMessage `json:"details,omitempty"`
}

func (Error) Validate

func (protocolError Error) Validate() error

type FrameType

type FrameType string
const (
	FrameRequest  FrameType = "request"
	FrameResponse FrameType = "response"
	FrameEvent    FrameType = "event"
)

type TransferDirection

type TransferDirection uint8
const (
	TransferUpload TransferDirection = iota + 1
	TransferDownload
)

type TransferFrame

type TransferFrame struct {
	Type           TransferFrameType
	Direction      TransferDirection
	TransferID     string
	PolicyRevision string
	Sequence       uint64
	TotalSize      uint64
	SHA256         [32]byte
	Payload        []byte
}

TransferFrame is the bounded binary frame carried only inside one authenticated node WebSocket generation. The live peer generation is the session binding; a frame is never accepted before admission or routed across peer replacement.

func DecodeTransferFrame

func DecodeTransferFrame(data []byte) (TransferFrame, error)

func (TransferFrame) SameBinding

func (frame TransferFrame) SameBinding(other TransferFrame) bool

func (TransferFrame) Validate

func (frame TransferFrame) Validate() error

type TransferFrameType

type TransferFrameType uint8
const (
	TransferFramePrepare TransferFrameType = iota + 1
	TransferFrameAccept
	TransferFrameDeny
	TransferFrameChunk
	TransferFrameAck
	TransferFrameCommit
	TransferFrameCommitted
	TransferFrameCancel
	TransferFrameStatus
	TransferFrameFailure
)

Jump to

Keyboard shortcuts

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