Documentation
¶
Overview ¶
Package protocol 是中继层 v2 的共享约定:帧头、路由标识派生、开发机签名断言。
字符串一律用 corral,不引入旧产品名。
Index ¶
- Constants
- Variables
- func AssertionsBound(a, prev Assertion) bool
- func CheckAssertion(pub ed25519.PublicKey, a Assertion, now time.Time) error
- func CheckAttachAssertion(pub ed25519.PublicKey, a AttachAssertion, now time.Time) error
- func DecodeV1(raw []byte) (kind byte, id [ChannelIDLen]byte, payload []byte, err error)
- func DecodeV2(raw []byte) (kind byte, id [ChannelIDLen]byte, payload []byte, err error)
- func EncodeV1(kind byte, id [ChannelIDLen]byte, payload []byte) []byte
- func EncodeV2(kind byte, id [ChannelIDLen]byte, payload []byte) []byte
- func FormatAssertion(routingID string, unixTS int64, nonce, sig []byte) string
- func FormatAttachAssertion(routingID, nodeID string, generation uint64, lane string, unixTS int64, ...) string
- func NormalizeLane(lane string) (string, error)
- func RoutingID(x25519Pub []byte) string
- func SignAttachMessage(routingID, nodeID string, generation uint64, lane string, unixTS int64, ...) []byte
- func SignMessage(routingID string, unixTS int64, nonce []byte) []byte
- func VerifyAssertion(pub ed25519.PublicKey, a Assertion, now time.Time, seen *NonceCache) error
- func VerifyAttachAssertion(pub ed25519.PublicKey, a AttachAssertion, now time.Time, seen *NonceCache) error
- type Assertion
- type AttachAssertion
- type NonceCache
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 CheckAttachAssertion ¶
func FormatAssertion ¶
func FormatAttachAssertion ¶
func NormalizeLane ¶
func SignAttachMessage ¶
func VerifyAssertion ¶
func VerifyAttachAssertion ¶
func VerifyAttachAssertion(pub ed25519.PublicKey, a AttachAssertion, now time.Time, seen *NonceCache) error
Types ¶
type Assertion ¶
func ParseAssertion ¶
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
Click to show internal directories.
Click to hide internal directories.