protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package protocol 是中继层 v2 的共享约定:帧头、路由标识派生、开发机签名断言。

字符串一律用 corral,不引入旧产品名。

Index

Constants

View Source
const (
	Version     byte = 2
	Subprotocol      = "corral.v2"

	FrameDeviceOpen   = 0x01
	FrameDeviceClose  = 0x02
	FrameHello        = 0x03
	FramePing         = 0x04
	FramePong         = 0x05
	FramePush         = 0x06
	FrameRegistered   = 0x07
	FrameLaneAttached = 0x08
	FramePushReceipt  = 0x09
	FrameData         = 0x10

	ChannelIDLen  = 16
	MaxFrameBytes = 8 << 20
	NonceSize     = 16
	AuthSkew      = 60 * time.Second
	NonceTTL      = 120 * time.Second
	V1HeaderLen   = 1 + ChannelIDLen
	V2HeaderLen   = 2 + ChannelIDLen

	LaneInteraction = "interaction"
	LaneBulk        = "bulk"

	// CapabilityHostLaneAttach is advertised on FrameRegistered so old hosts
	// keep a single socket while new hosts may attach a bulk lane.
	CapabilityHostLaneAttach = "host_lane_attach"
)

Variables

View Source
var (
	RouteContext  = []byte("corral/relay/v2 route")
	AuthContext   = []byte("corral/relay/v2 host-auth")
	AttachContext = []byte("corral/relay/v2 host-lane-attach")

	ErrFrameTooShort = errors.New("帧过短")
	ErrFrameTooLarge = errors.New("帧过大")
	ErrBadVersion    = errors.New("帧版本不是 v2")
	ErrBadAuth       = errors.New("开发机断言不合法")
	ErrAuthSkew      = errors.New("开发机时钟偏差过大")
	ErrAuthReplay    = errors.New("开发机断言重放")
	ErrBadSignature  = errors.New("开发机签名不匹配")
	ErrBadLane       = errors.New("通道种类不合法")
)

Functions

func AssertionsBound

func AssertionsBound(a, prev Assertion) bool

func CheckAssertion

func CheckAssertion(pub ed25519.PublicKey, a Assertion, now time.Time) error

func CheckAttachAssertion

func CheckAttachAssertion(pub ed25519.PublicKey, a AttachAssertion, now time.Time) error

func DecodeV1

func DecodeV1(raw []byte) (kind byte, id [ChannelIDLen]byte, payload []byte, err error)

func DecodeV2

func DecodeV2(raw []byte) (kind byte, id [ChannelIDLen]byte, payload []byte, err error)

func EncodeV1

func EncodeV1(kind byte, id [ChannelIDLen]byte, payload []byte) []byte

func EncodeV2

func EncodeV2(kind byte, id [ChannelIDLen]byte, payload []byte) []byte

func FormatAssertion

func FormatAssertion(routingID string, unixTS int64, nonce, sig []byte) string

func FormatAttachAssertion

func FormatAttachAssertion(routingID, nodeID string, generation uint64, lane string, unixTS int64, nonce, sig []byte) string

func NormalizeLane

func NormalizeLane(lane string) (string, error)

func RoutingID

func RoutingID(x25519Pub []byte) string

func SignAttachMessage

func SignAttachMessage(routingID, nodeID string, generation uint64, lane string, unixTS int64, nonce []byte) []byte

func SignMessage

func SignMessage(routingID string, unixTS int64, nonce []byte) []byte

func VerifyAssertion

func VerifyAssertion(pub ed25519.PublicKey, a Assertion, now time.Time, seen *NonceCache) error

func VerifyAttachAssertion

func VerifyAttachAssertion(pub ed25519.PublicKey, a AttachAssertion, now time.Time, seen *NonceCache) error

Types

type Assertion

type Assertion struct {
	RoutingID string
	UnixTS    int64
	Nonce     []byte
	Sig       []byte
}

func ParseAssertion

func ParseAssertion(header string) (Assertion, error)

type AttachAssertion

type AttachAssertion struct {
	RoutingID  string
	NodeID     string
	Generation uint64
	Lane       string
	UnixTS     int64
	Nonce      []byte
	Sig        []byte
}

AttachAssertion binds an extra host socket to an existing registration generation. It cannot create or replace the primary registration.

func ParseAttachAssertion

func ParseAttachAssertion(header string) (AttachAssertion, error)

type NonceCache

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

NonceCache 记住最近用过的 (routing_id, nonce),挡住重放。

func NewNonceCache

func NewNonceCache() *NonceCache

func (*NonceCache) Accept

func (c *NonceCache) Accept(routingID string, nonce []byte, now time.Time) bool

Jump to

Keyboard shortcuts

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