zap

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package zap provides Zero-Copy App Proto (ZAP) serialization for high-performance RPC communication. ZAP minimizes CPU overhead and memory allocations through:

  • Direct memory access for fixed-size fields
  • Length-prefixed variable data without copying
  • Buffer pooling to avoid allocations
  • Simple framing for TCP transport (no HTTP/2 overhead)

Wire protocol:

[4 bytes: message length][1 byte: message type][payload...]

The message type allows multiplexing multiple RPC calls over a single connection.

Index

Constants

View Source
const (
	// MaxMessageSize is the maximum allowed message size (16MB)
	MaxMessageSize = 16 * 1024 * 1024

	// HeaderSize is the size of the message header (4 bytes length + 1 byte type)
	HeaderSize = 5

	// DefaultBufferSize for pooled buffers
	DefaultBufferSize = 64 * 1024
)

Variables

View Source
var (
	ErrClosed         = errors.New("zap: connection closed")
	ErrTimeout        = errors.New("zap: request timeout")
	ErrResponseFailed = errors.New("zap: response failed")
)
View Source
var (
	ErrMessageTooLarge = errors.New("zap: message exceeds maximum size")
	ErrInvalidMessage  = errors.New("zap: invalid message format")
	ErrUnknownType     = errors.New("zap: unknown message type")
)
View Source
var BufferPool = sync.Pool{
	New: func() interface{} {
		return &Buffer{
			Data: make([]byte, DefaultBufferSize),
		}
	},
}

BufferPool manages reusable buffers to minimize allocations

Functions

func PutBuffer

func PutBuffer(buf *Buffer)

PutBuffer returns a buffer to the pool

func WriteMessage

func WriteMessage(w io.Writer, msgType MessageType, payload []byte) error

WriteMessage writes a complete ZAP message with header

Types

type BatchedParseBlockRequest

type BatchedParseBlockRequest struct {
	Requests [][]byte
}

BatchedParseBlockRequest contains multiple blocks to parse

func (*BatchedParseBlockRequest) Decode

func (m *BatchedParseBlockRequest) Decode(r *Reader) error

Decode deserializes BatchedParseBlockRequest from the reader

func (*BatchedParseBlockRequest) Encode

func (m *BatchedParseBlockRequest) Encode(buf *Buffer)

Encode serializes BatchedParseBlockRequest to the buffer

type BatchedParseBlockResponse

type BatchedParseBlockResponse struct {
	Responses []BlockResponse
}

BatchedParseBlockResponse contains parsed blocks

func (*BatchedParseBlockResponse) Decode

func (m *BatchedParseBlockResponse) Decode(r *Reader) error

Decode deserializes BatchedParseBlockResponse from the reader

func (*BatchedParseBlockResponse) Encode

func (m *BatchedParseBlockResponse) Encode(buf *Buffer)

Encode serializes BatchedParseBlockResponse to the buffer

type BlockAcceptRequest

type BlockAcceptRequest struct {
	ID []byte
}

BlockAcceptRequest contains block ID to accept

func (*BlockAcceptRequest) Decode

func (m *BlockAcceptRequest) Decode(r *Reader) error

Decode deserializes BlockAcceptRequest from the reader

func (*BlockAcceptRequest) Encode

func (m *BlockAcceptRequest) Encode(buf *Buffer)

Encode serializes BlockAcceptRequest to the buffer

type BlockRejectRequest

type BlockRejectRequest struct {
	ID []byte
}

BlockRejectRequest contains block ID to reject

func (*BlockRejectRequest) Decode

func (m *BlockRejectRequest) Decode(r *Reader) error

Decode deserializes BlockRejectRequest from the reader

func (*BlockRejectRequest) Encode

func (m *BlockRejectRequest) Encode(buf *Buffer)

Encode serializes BlockRejectRequest to the buffer

type BlockResponse

type BlockResponse struct {
	ID                []byte
	ParentID          []byte
	Bytes             []byte // Zero-copy block data
	Height            uint64
	Timestamp         int64
	VerifyWithContext bool
	Err               Error
}

BlockResponse contains block data (used by BuildBlock, ParseBlock, GetBlock)

func (*BlockResponse) Decode

func (m *BlockResponse) Decode(r *Reader) error

Decode deserializes BlockResponse from the reader

func (*BlockResponse) Encode

func (m *BlockResponse) Encode(buf *Buffer)

Encode serializes BlockResponse to the buffer

type BlockVerifyRequest

type BlockVerifyRequest struct {
	Bytes           []byte
	PChainHeight    uint64
	HasPChainHeight bool
}

BlockVerifyRequest contains block verification parameters

func (*BlockVerifyRequest) Decode

func (m *BlockVerifyRequest) Decode(r *Reader) error

Decode deserializes BlockVerifyRequest from the reader

func (*BlockVerifyRequest) Encode

func (m *BlockVerifyRequest) Encode(buf *Buffer)

Encode serializes BlockVerifyRequest to the buffer

type BlockVerifyResponse

type BlockVerifyResponse struct {
	Timestamp int64
}

BlockVerifyResponse contains verification result

func (*BlockVerifyResponse) Decode

func (m *BlockVerifyResponse) Decode(r *Reader) error

Decode deserializes BlockVerifyResponse from the reader

func (*BlockVerifyResponse) Encode

func (m *BlockVerifyResponse) Encode(buf *Buffer)

Encode serializes BlockVerifyResponse to the buffer

type Buffer

type Buffer struct {
	Data []byte
	// contains filtered or unexported fields
}

Buffer is a reusable byte buffer for zero-copy operations

func GetBuffer

func GetBuffer() *Buffer

GetBuffer retrieves a buffer from the pool

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the written portion of the buffer

func (*Buffer) Grow

func (b *Buffer) Grow(n int)

Grow ensures the buffer has at least n bytes available

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes written

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset prepares the buffer for reuse

func (*Buffer) WriteBool

func (b *Buffer) WriteBool(v bool)

WriteBool writes a boolean to the buffer

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(data []byte)

WriteBytes writes a length-prefixed byte slice to the buffer

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(v int32)

WriteInt32 writes an int32 to the buffer (big-endian)

func (*Buffer) WriteInt64

func (b *Buffer) WriteInt64(v int64)

WriteInt64 writes an int64 to the buffer (big-endian)

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string)

WriteString writes a length-prefixed string to the buffer

func (*Buffer) WriteUint8

func (b *Buffer) WriteUint8(v uint8)

WriteUint8 writes a uint8 to the buffer

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(v uint16)

WriteUint16 writes a uint16 to the buffer (big-endian)

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(v uint32)

WriteUint32 writes a uint32 to the buffer (big-endian)

func (*Buffer) WriteUint64

func (b *Buffer) WriteUint64(v uint64)

WriteUint64 writes a uint64 to the buffer (big-endian)

type BuildBlockRequest

type BuildBlockRequest struct {
	PChainHeight    uint64
	HasPChainHeight bool
}

BuildBlockRequest contains block building parameters

func (*BuildBlockRequest) Decode

func (m *BuildBlockRequest) Decode(r *Reader) error

Decode deserializes BuildBlockRequest from the reader

func (*BuildBlockRequest) Encode

func (m *BuildBlockRequest) Encode(buf *Buffer)

Encode serializes BuildBlockRequest to the buffer

type Config

type Config struct {
	// ReadTimeout is the timeout for reading a message
	ReadTimeout time.Duration
	// WriteTimeout is the timeout for writing a message
	WriteTimeout time.Duration
	// MaxConcurrent is the maximum number of concurrent requests
	MaxConcurrent int
	// BufferSize is the read/write buffer size
	BufferSize int
}

Config contains transport configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with reasonable defaults

type Conn

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

Conn is a ZAP connection that multiplexes requests

func Dial

func Dial(ctx context.Context, addr string, config *Config) (*Conn, error)

Dial connects to a ZAP server

func NewConn

func NewConn(conn net.Conn, config *Config) *Conn

NewConn wraps an existing net.Conn as a ZAP connection

func (*Conn) Call

func (c *Conn) Call(ctx context.Context, msgType MessageType, payload []byte) (MessageType, []byte, error)

Call sends a request and waits for a response

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection

func (*Conn) Send

func (c *Conn) Send(msgType MessageType, payload []byte) error

Send sends a one-way message (no response expected)

type ConnectedRequest

type ConnectedRequest struct {
	NodeID []byte
	Name   string
	Major  uint32
	Minor  uint32
	Patch  uint32
}

ConnectedRequest contains connection info

func (*ConnectedRequest) Decode

func (m *ConnectedRequest) Decode(r *Reader) error

Decode deserializes ConnectedRequest from the reader

func (*ConnectedRequest) Encode

func (m *ConnectedRequest) Encode(buf *Buffer)

Encode serializes ConnectedRequest to the buffer

type CreateHandlersResponse

type CreateHandlersResponse struct {
	Handlers []HTTPHandler
}

CreateHandlersResponse contains handler list

func (*CreateHandlersResponse) Decode

func (m *CreateHandlersResponse) Decode(r *Reader) error

Decode deserializes CreateHandlersResponse from the reader

func (*CreateHandlersResponse) Encode

func (m *CreateHandlersResponse) Encode(buf *Buffer)

Encode serializes CreateHandlersResponse to the buffer

type DisconnectedRequest

type DisconnectedRequest struct {
	NodeID []byte
}

DisconnectedRequest contains disconnection info

func (*DisconnectedRequest) Decode

func (m *DisconnectedRequest) Decode(r *Reader) error

Decode deserializes DisconnectedRequest from the reader

func (*DisconnectedRequest) Encode

func (m *DisconnectedRequest) Encode(buf *Buffer)

Encode serializes DisconnectedRequest to the buffer

type Error

type Error uint8

Error represents VM errors

const (
	ErrorUnspecified Error = iota
	ErrorClosed
	ErrorNotFound
	ErrorStateSyncNotImplemented
)

type GetAncestorsRequest

type GetAncestorsRequest struct {
	BlkID                 []byte
	MaxBlocksNum          int32
	MaxBlocksSize         int32
	MaxBlocksRetrivalTime int64
}

GetAncestorsRequest contains ancestor retrieval parameters

func (*GetAncestorsRequest) Decode

func (m *GetAncestorsRequest) Decode(r *Reader) error

Decode deserializes GetAncestorsRequest from the reader

func (*GetAncestorsRequest) Encode

func (m *GetAncestorsRequest) Encode(buf *Buffer)

Encode serializes GetAncestorsRequest to the buffer

type GetAncestorsResponse

type GetAncestorsResponse struct {
	BlksBytes [][]byte
}

GetAncestorsResponse contains ancestor blocks

func (*GetAncestorsResponse) Decode

func (m *GetAncestorsResponse) Decode(r *Reader) error

Decode deserializes GetAncestorsResponse from the reader

func (*GetAncestorsResponse) Encode

func (m *GetAncestorsResponse) Encode(buf *Buffer)

Encode serializes GetAncestorsResponse to the buffer

type GetBlockIDAtHeightRequest

type GetBlockIDAtHeightRequest struct {
	Height uint64
}

GetBlockIDAtHeightRequest contains height to query

func (*GetBlockIDAtHeightRequest) Decode

func (m *GetBlockIDAtHeightRequest) Decode(r *Reader) error

Decode deserializes GetBlockIDAtHeightRequest from the reader

func (*GetBlockIDAtHeightRequest) Encode

func (m *GetBlockIDAtHeightRequest) Encode(buf *Buffer)

Encode serializes GetBlockIDAtHeightRequest to the buffer

type GetBlockIDAtHeightResponse

type GetBlockIDAtHeightResponse struct {
	BlkID []byte
	Err   Error
}

GetBlockIDAtHeightResponse contains block ID at height

func (*GetBlockIDAtHeightResponse) Decode

func (m *GetBlockIDAtHeightResponse) Decode(r *Reader) error

Decode deserializes GetBlockIDAtHeightResponse from the reader

func (*GetBlockIDAtHeightResponse) Encode

func (m *GetBlockIDAtHeightResponse) Encode(buf *Buffer)

Encode serializes GetBlockIDAtHeightResponse to the buffer

type GetBlockRequest

type GetBlockRequest struct {
	ID []byte
}

GetBlockRequest contains block ID to retrieve

func (*GetBlockRequest) Decode

func (m *GetBlockRequest) Decode(r *Reader) error

Decode deserializes GetBlockRequest from the reader

func (*GetBlockRequest) Encode

func (m *GetBlockRequest) Encode(buf *Buffer)

Encode serializes GetBlockRequest to the buffer

type GossipMsg

type GossipMsg struct {
	NodeID []byte
	Msg    []byte
}

GossipMsg contains gossip message

func (*GossipMsg) Decode

func (m *GossipMsg) Decode(r *Reader) error

Decode deserializes GossipMsg from the reader

func (*GossipMsg) Encode

func (m *GossipMsg) Encode(buf *Buffer)

Encode serializes GossipMsg to the buffer

type HTTPHandler

type HTTPHandler struct {
	Prefix     string
	ServerAddr string
}

HTTPHandler contains HTTP handler info

func (*HTTPHandler) Decode

func (m *HTTPHandler) Decode(r *Reader) error

Decode deserializes HTTPHandler from the reader

func (*HTTPHandler) Encode

func (m *HTTPHandler) Encode(buf *Buffer)

Encode serializes HTTPHandler to the buffer

type Handler

type Handler interface {
	// Handle processes a request and returns a response
	Handle(ctx context.Context, msgType MessageType, payload []byte) (MessageType, []byte, error)
}

Handler processes ZAP requests

type HandlerFunc

type HandlerFunc func(ctx context.Context, msgType MessageType, payload []byte) (MessageType, []byte, error)

HandlerFunc is a function that implements Handler

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, msgType MessageType, payload []byte) (MessageType, []byte, error)

Handle implements Handler

type HealthResponse

type HealthResponse struct {
	Details []byte
}

HealthResponse contains health check result

func (*HealthResponse) Decode

func (m *HealthResponse) Decode(r *Reader) error

Decode deserializes HealthResponse from the reader

func (*HealthResponse) Encode

func (m *HealthResponse) Encode(buf *Buffer)

Encode serializes HealthResponse to the buffer

type InitializeRequest

type InitializeRequest struct {
	NetworkID       uint32
	ChainID         []byte
	NodeID          []byte
	PublicKey       []byte
	XChainID        []byte
	CChainID        []byte
	LuxAssetID      []byte
	ChainDataDir    string
	GenesisBytes    []byte
	UpgradeBytes    []byte
	ConfigBytes     []byte
	DBServerAddr    string
	ServerAddr      string
	NetworkUpgrades NetworkUpgrades
}

InitializeRequest contains initialization parameters

func (*InitializeRequest) Decode

func (m *InitializeRequest) Decode(r *Reader) error

Decode deserializes InitializeRequest from the reader

func (*InitializeRequest) Encode

func (m *InitializeRequest) Encode(buf *Buffer)

Encode serializes InitializeRequest to the buffer

type InitializeResponse

type InitializeResponse struct {
	LastAcceptedID       []byte
	LastAcceptedParentID []byte
	Height               uint64
	Bytes                []byte
	Timestamp            int64
}

InitializeResponse contains initialization results

func (*InitializeResponse) Decode

func (m *InitializeResponse) Decode(r *Reader) error

Decode deserializes InitializeResponse from the reader

func (*InitializeResponse) Encode

func (m *InitializeResponse) Encode(buf *Buffer)

Encode serializes InitializeResponse to the buffer

type Listener

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

Listener accepts ZAP connections

func Listen

func Listen(addr string, config *Config) (*Listener, error)

Listen creates a new ZAP listener

func (*Listener) Accept

func (l *Listener) Accept() (*ServerConn, error)

Accept accepts a new connection

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's address

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener

type MessageType

type MessageType uint8

MessageType identifies the RPC method being called

const (
	// VM service methods (1-31)
	MsgInitialize MessageType = iota + 1
	MsgSetState
	MsgShutdown
	MsgCreateHandlers
	MsgNewHTTPHandler
	MsgWaitForEvent
	MsgConnected
	MsgDisconnected
	MsgBuildBlock
	MsgParseBlock
	MsgGetBlock
	MsgSetPreference
	MsgHealth
	MsgVersion
	MsgRequest
	MsgRequestFailed
	MsgResponse
	MsgGossip
	MsgGather
	MsgGetAncestors
	MsgBatchedParseBlock
	MsgGetBlockIDAtHeight
	MsgStateSyncEnabled
	MsgGetOngoingSyncStateSummary
	MsgGetLastStateSummary
	MsgParseStateSummary
	MsgGetStateSummary
	MsgBlockVerify
	MsgBlockAccept
	MsgBlockReject
	MsgStateSummaryAccept // = 31

	// p2p.Sender methods (40-49)
	MsgSendRequest  MessageType = 40
	MsgSendResponse MessageType = 41
	MsgSendError    MessageType = 42
	MsgSendGossip   MessageType = 43

	// Warp signing methods (50-59)
	MsgWarpSign         MessageType = 50
	MsgWarpGetPublicKey MessageType = 51
	MsgWarpBatchSign    MessageType = 52

	// Response flag - set on response messages (high bit)
	// All message types must be < 128 to allow OR with this flag
	MsgResponseFlag MessageType = 128
)

func ReadMessage

func ReadMessage(r io.Reader) (MessageType, []byte, error)

ReadMessage reads a complete ZAP message with header

type NetworkUpgrades

type NetworkUpgrades struct {
	ApricotPhase1Time            int64
	ApricotPhase2Time            int64
	ApricotPhase3Time            int64
	ApricotPhase4Time            int64
	ApricotPhase4MinPChainHeight uint64
	ApricotPhase5Time            int64
	ApricotPhasePre6Time         int64
	ApricotPhase6Time            int64
	ApricotPhasePost6Time        int64
	BanffTime                    int64
	CortinaTime                  int64
	CortinaXChainStopVertexID    []byte
	DurangoTime                  int64
	EtnaTime                     int64
	FortunaTime                  int64
	GraniteTime                  int64
}

NetworkUpgrades contains network upgrade timestamps

func (*NetworkUpgrades) Decode

func (n *NetworkUpgrades) Decode(r *Reader) error

Decode deserializes NetworkUpgrades from the reader

func (*NetworkUpgrades) Encode

func (n *NetworkUpgrades) Encode(buf *Buffer)

Encode serializes NetworkUpgrades to the buffer

type NewHTTPHandlerResponse

type NewHTTPHandlerResponse struct {
	ServerAddr string
}

NewHTTPHandlerResponse contains HTTP handler address

func (*NewHTTPHandlerResponse) Decode

func (m *NewHTTPHandlerResponse) Decode(r *Reader) error

Decode deserializes NewHTTPHandlerResponse from the reader

func (*NewHTTPHandlerResponse) Encode

func (m *NewHTTPHandlerResponse) Encode(buf *Buffer)

Encode serializes NewHTTPHandlerResponse to the buffer

type ParseBlockRequest

type ParseBlockRequest struct {
	Bytes []byte // Zero-copy input
}

ParseBlockRequest contains bytes to parse

func (*ParseBlockRequest) Decode

func (m *ParseBlockRequest) Decode(r *Reader) error

Decode deserializes ParseBlockRequest from the reader

func (*ParseBlockRequest) Encode

func (m *ParseBlockRequest) Encode(buf *Buffer)

Encode serializes ParseBlockRequest to the buffer

type Reader

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

Reader provides zero-copy reading from a byte slice

func NewReader

func NewReader(data []byte) *Reader

NewReader creates a new reader from a byte slice

func (*Reader) ReadBool

func (r *Reader) ReadBool() (bool, error)

ReadBool reads a boolean from the buffer

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() ([]byte, error)

ReadBytes reads a length-prefixed byte slice (zero-copy - returns slice into original buffer)

func (*Reader) ReadInt32

func (r *Reader) ReadInt32() (int32, error)

ReadInt32 reads an int32 from the buffer (big-endian)

func (*Reader) ReadInt64

func (r *Reader) ReadInt64() (int64, error)

ReadInt64 reads an int64 from the buffer (big-endian)

func (*Reader) ReadString

func (r *Reader) ReadString() (string, error)

ReadString reads a length-prefixed string

func (*Reader) ReadUint8

func (r *Reader) ReadUint8() (uint8, error)

ReadUint8 reads a uint8 from the buffer

func (*Reader) ReadUint16

func (r *Reader) ReadUint16() (uint16, error)

ReadUint16 reads a uint16 from the buffer (big-endian)

func (*Reader) ReadUint32

func (r *Reader) ReadUint32() (uint32, error)

ReadUint32 reads a uint32 from the buffer (big-endian)

func (*Reader) ReadUint64

func (r *Reader) ReadUint64() (uint64, error)

ReadUint64 reads a uint64 from the buffer (big-endian)

func (*Reader) Remaining

func (r *Reader) Remaining() int

Remaining returns the number of unread bytes

type RequestFailedMsg

type RequestFailedMsg struct {
	NodeID       []byte
	RequestID    uint32
	ErrorCode    int32
	ErrorMessage string
}

RequestFailedMsg contains failed request info

func (*RequestFailedMsg) Decode

func (m *RequestFailedMsg) Decode(r *Reader) error

Decode deserializes RequestFailedMsg from the reader

func (*RequestFailedMsg) Encode

func (m *RequestFailedMsg) Encode(buf *Buffer)

Encode serializes RequestFailedMsg to the buffer

type RequestMsg

type RequestMsg struct {
	NodeID    []byte
	RequestID uint32
	Deadline  int64
	Request   []byte
}

RequestMsg contains incoming request data

func (*RequestMsg) Decode

func (m *RequestMsg) Decode(r *Reader) error

Decode deserializes RequestMsg from the reader

func (*RequestMsg) Encode

func (m *RequestMsg) Encode(buf *Buffer)

Encode serializes RequestMsg to the buffer

type ResponseMsg

type ResponseMsg struct {
	NodeID    []byte
	RequestID uint32
	Response  []byte
}

ResponseMsg contains response data

func (*ResponseMsg) Decode

func (m *ResponseMsg) Decode(r *Reader) error

Decode deserializes ResponseMsg from the reader

func (*ResponseMsg) Encode

func (m *ResponseMsg) Encode(buf *Buffer)

Encode serializes ResponseMsg to the buffer

type SendErrorMsg

type SendErrorMsg struct {
	NodeID       []byte
	RequestID    uint32
	ErrorCode    int32
	ErrorMessage string
}

SendErrorMsg contains error to send to a node (p2p.Sender.SendError)

func (*SendErrorMsg) Decode

func (m *SendErrorMsg) Decode(r *Reader) error

Decode deserializes SendErrorMsg from the reader

func (*SendErrorMsg) Encode

func (m *SendErrorMsg) Encode(buf *Buffer)

Encode serializes SendErrorMsg to the buffer

type SendGossipMsg

type SendGossipMsg struct {
	NodeIDs       [][]byte
	Validators    uint64
	NonValidators uint64
	Peers         uint64
	Msg           []byte // Zero-copy gossip payload
}

SendGossipMsg contains gossip message to send (p2p.Sender.SendGossip)

func (*SendGossipMsg) Decode

func (m *SendGossipMsg) Decode(r *Reader) error

Decode deserializes SendGossipMsg from the reader

func (*SendGossipMsg) Encode

func (m *SendGossipMsg) Encode(buf *Buffer)

Encode serializes SendGossipMsg to the buffer

type SendRequestMsg

type SendRequestMsg struct {
	NodeIDs   [][]byte
	RequestID uint32
	Request   []byte // Zero-copy payload
}

SendRequestMsg contains request to send to nodes (p2p.Sender.SendRequest)

func (*SendRequestMsg) Decode

func (m *SendRequestMsg) Decode(r *Reader) error

Decode deserializes SendRequestMsg from the reader

func (*SendRequestMsg) Encode

func (m *SendRequestMsg) Encode(buf *Buffer)

Encode serializes SendRequestMsg to the buffer

type SendResponseMsg

type SendResponseMsg struct {
	NodeID    []byte
	RequestID uint32
	Response  []byte // Zero-copy payload
}

SendResponseMsg contains response to send to a node (p2p.Sender.SendResponse)

func (*SendResponseMsg) Decode

func (m *SendResponseMsg) Decode(r *Reader) error

Decode deserializes SendResponseMsg from the reader

func (*SendResponseMsg) Encode

func (m *SendResponseMsg) Encode(buf *Buffer)

Encode serializes SendResponseMsg to the buffer

type Server

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

Server serves ZAP requests

func NewServer

func NewServer(listener *Listener, handler Handler) *Server

NewServer creates a new ZAP server

func (*Server) Close

func (s *Server) Close() error

Close closes the server

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve accepts and processes connections

type ServerConn

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

ServerConn is a server-side ZAP connection

func (*ServerConn) Close

func (c *ServerConn) Close() error

Close closes the server connection

func (*ServerConn) Read

func (c *ServerConn) Read() (uint32, MessageType, []byte, error)

Read reads the next request from the connection

func (*ServerConn) RemoteAddr

func (c *ServerConn) RemoteAddr() net.Addr

RemoteAddr returns the remote address

func (*ServerConn) Write

func (c *ServerConn) Write(reqID uint32, msgType MessageType, payload []byte) error

Write writes a response

type SetPreferenceRequest

type SetPreferenceRequest struct {
	ID []byte
}

SetPreferenceRequest contains preferred block ID

func (*SetPreferenceRequest) Decode

func (m *SetPreferenceRequest) Decode(r *Reader) error

Decode deserializes SetPreferenceRequest from the reader

func (*SetPreferenceRequest) Encode

func (m *SetPreferenceRequest) Encode(buf *Buffer)

Encode serializes SetPreferenceRequest to the buffer

type SetStateRequest

type SetStateRequest struct {
	State State
}

SetStateRequest contains state change request. State values are defined in github.com/luxfi/vm (vm.State):

Unknown=0, Starting=1, Syncing=2, Bootstrapping=3,
Ready=4, Degraded=5, Stopping=6, Stopped=7

func (*SetStateRequest) Decode

func (m *SetStateRequest) Decode(r *Reader) error

Decode deserializes SetStateRequest from the reader

func (*SetStateRequest) Encode

func (m *SetStateRequest) Encode(buf *Buffer)

Encode serializes SetStateRequest to the buffer

type SetStateResponse

type SetStateResponse struct {
	LastAcceptedID       []byte
	LastAcceptedParentID []byte
	Height               uint64
	Bytes                []byte
	Timestamp            int64
}

SetStateResponse contains state change results

func (*SetStateResponse) Decode

func (m *SetStateResponse) Decode(r *Reader) error

Decode deserializes SetStateResponse from the reader

func (*SetStateResponse) Encode

func (m *SetStateResponse) Encode(buf *Buffer)

Encode serializes SetStateResponse to the buffer

type State

type State uint8

State represents VM state values

const (
	StateUnknown       State = 0
	StateStarting      State = 1
	StateSyncing       State = 2
	StateBootstrapping State = 3
	StateReady         State = 4
	StateDegraded      State = 5
	StateStopping      State = 6
	StateStopped       State = 7
)

type VersionResponse

type VersionResponse struct {
	Version string
}

VersionResponse contains version info

func (*VersionResponse) Decode

func (m *VersionResponse) Decode(r *Reader) error

Decode deserializes VersionResponse from the reader

func (*VersionResponse) Encode

func (m *VersionResponse) Encode(buf *Buffer)

Encode serializes VersionResponse to the buffer

type WaitForEventResponse

type WaitForEventResponse struct {
	Message uint8
}

WaitForEventResponse contains event type

func (*WaitForEventResponse) Decode

func (m *WaitForEventResponse) Decode(r *Reader) error

Decode deserializes WaitForEventResponse from the reader

func (*WaitForEventResponse) Encode

func (m *WaitForEventResponse) Encode(buf *Buffer)

Encode serializes WaitForEventResponse to the buffer

type WarpBatchSignRequest

type WarpBatchSignRequest struct {
	Messages []WarpSignRequest
}

WarpBatchSignRequest encodes a batch signing request

func (*WarpBatchSignRequest) Decode

func (r *WarpBatchSignRequest) Decode(rd *Reader) error

Decode reads the request from the reader

func (*WarpBatchSignRequest) Encode

func (r *WarpBatchSignRequest) Encode(buf *Buffer)

Encode writes the request to the buffer

type WarpBatchSignResponse

type WarpBatchSignResponse struct {
	Signatures [][]byte
	Errors     []string
}

WarpBatchSignResponse encodes a batch signing response

func (*WarpBatchSignResponse) Decode

func (r *WarpBatchSignResponse) Decode(rd *Reader) error

Decode reads the response from the reader

func (*WarpBatchSignResponse) Encode

func (r *WarpBatchSignResponse) Encode(buf *Buffer)

Encode writes the response to the buffer

type WarpGetPublicKeyRequest

type WarpGetPublicKeyRequest struct{}

WarpGetPublicKeyRequest encodes a get public key request

func (*WarpGetPublicKeyRequest) Decode

func (r *WarpGetPublicKeyRequest) Decode(rd *Reader) error

Decode reads the request from the reader

func (*WarpGetPublicKeyRequest) Encode

func (r *WarpGetPublicKeyRequest) Encode(buf *Buffer)

Encode writes the request to the buffer

type WarpGetPublicKeyResponse

type WarpGetPublicKeyResponse struct {
	PublicKey []byte
	Error     string
}

WarpGetPublicKeyResponse encodes a get public key response

func (*WarpGetPublicKeyResponse) Decode

func (r *WarpGetPublicKeyResponse) Decode(rd *Reader) error

Decode reads the response from the reader

func (*WarpGetPublicKeyResponse) Encode

func (r *WarpGetPublicKeyResponse) Encode(buf *Buffer)

Encode writes the response to the buffer

type WarpSignRequest

type WarpSignRequest struct {
	NetworkID     uint32
	SourceChainID []byte // 32 bytes
	Payload       []byte
}

WarpSignRequest encodes a warp signing request

func (*WarpSignRequest) Decode

func (r *WarpSignRequest) Decode(rd *Reader) error

Decode reads the request from the reader

func (*WarpSignRequest) Encode

func (r *WarpSignRequest) Encode(buf *Buffer)

Encode writes the request to the buffer

type WarpSignResponse

type WarpSignResponse struct {
	Signature []byte
	Error     string
}

WarpSignResponse encodes a warp signing response

func (*WarpSignResponse) Decode

func (r *WarpSignResponse) Decode(rd *Reader) error

Decode reads the response from the reader

func (*WarpSignResponse) Encode

func (r *WarpSignResponse) Encode(buf *Buffer)

Encode writes the response to the buffer

Jump to

Keyboard shortcuts

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