Documentation
¶
Overview ¶
Package message implements XRPL peer protocol message types and serialization. This package provides message encoding/decoding compatible with rippled's protocol buffer format and wire protocol.
Index ¶
- Constants
- Variables
- func BuildWireMessage(msgType MessageType, payload []byte) ([]byte, error)
- func Encode(msg Message) ([]byte, error)
- func EncodeHeader(buf []byte, payloadSize uint32, msgType MessageType, ...) error
- func WriteMessage(w io.Writer, msgType MessageType, payload []byte) error
- func WriteMessageCompressed(w io.Writer, msgType MessageType, payload []byte, ...) error
- type Cluster
- type ClusterNode
- type CompressionAlgorithm
- type Endpoints
- type Endpointv2
- type GetLedger
- type GetObjectByHash
- type HaveTransactionSet
- type HaveTransactions
- type Header
- type IndexedObject
- type LedgerData
- type LedgerInfoType
- type LedgerMapType
- type LedgerNode
- type LedgerType
- type LoadSource
- type Manifest
- type Manifests
- type Message
- type MessageType
- type NodeEvent
- type NodeStatus
- type ObjectType
- type Ping
- type PingType
- type ProofPathRequest
- type ProofPathResponse
- type ProposeSet
- type QueryType
- type ReplayDeltaRequest
- type ReplayDeltaResponse
- type ReplyError
- type Squelch
- type StatusChange
- type Transaction
- type TransactionStatus
- type Transactions
- type TxSetStatus
- type Validation
- type ValidatorBlobInfo
- type ValidatorList
- type ValidatorListCollection
Constants ¶
const ( // HeaderSizeUncompressed is the size of an uncompressed message header. // Format: 4 bytes (6 bits flags + 26 bits size) + 2 bytes (type) HeaderSizeUncompressed = 6 // HeaderSizeCompressed is the size of a compressed message header. // Format: 4 bytes (flags + size) + 2 bytes (type) + 4 bytes (uncompressed size) HeaderSizeCompressed = 10 // MaxMessageSize is the maximum allowed message size (64 MB). MaxMessageSize = 64 * 1024 * 1024 // MaxPayloadSizeBits is the number of bits used for payload size (26 bits). MaxPayloadSizeBits = 26 // MaxPayloadSize is the maximum payload size that can be encoded. MaxPayloadSize = (1 << MaxPayloadSizeBits) - 1 // CompressionFlagMask is the mask for compression flags in the first byte. CompressionFlagMask = 0xF0 // CompressionNone indicates no compression. CompressionNone = 0x00 // CompressionLZ4 indicates LZ4 compression. CompressionLZ4 = 0x80 // First bit set + algorithm bits )
Variables ¶
var ( // ErrMessageTooLarge is returned when a message exceeds the maximum size. ErrMessageTooLarge = errors.New("message too large") // ErrInvalidHeader is returned when the message header is invalid. ErrInvalidHeader = errors.New("invalid message header") // ErrUnknownCompression is returned for unknown compression algorithms. ErrUnknownCompression = errors.New("unknown compression algorithm") // ErrTruncatedMessage is returned when a message is truncated. ErrTruncatedMessage = errors.New("truncated message") )
Functions ¶
func BuildWireMessage ¶
func BuildWireMessage(msgType MessageType, payload []byte) ([]byte, error)
BuildWireMessage creates a complete wire-protocol message (header + payload) as bytes.
func EncodeHeader ¶
func EncodeHeader(buf []byte, payloadSize uint32, msgType MessageType, algorithm CompressionAlgorithm, uncompressedSize uint32) error
EncodeHeader encodes a message header into the provided buffer. For uncompressed messages, buf must be at least 6 bytes. For compressed messages, buf must be at least 10 bytes. Reference: rippled Message.cpp setHeader()
func WriteMessage ¶
func WriteMessage(w io.Writer, msgType MessageType, payload []byte) error
WriteMessage writes a message with header to the writer.
func WriteMessageCompressed ¶
func WriteMessageCompressed(w io.Writer, msgType MessageType, payload []byte, algorithm CompressionAlgorithm, uncompressedSize uint32) error
WriteMessageCompressed writes a potentially compressed message.
Types ¶
type Cluster ¶
type Cluster struct {
ClusterNodes []ClusterNode `json:"cluster_nodes"`
LoadSources []LoadSource `json:"load_sources"`
}
Cluster represents cluster status.
func (*Cluster) Type ¶
func (c *Cluster) Type() MessageType
type ClusterNode ¶
type ClusterNode struct {
PublicKey string `json:"public_key"`
ReportTime uint32 `json:"report_time"`
NodeLoad uint32 `json:"node_load"`
NodeName string `json:"node_name,omitempty"`
Address string `json:"address,omitempty"`
}
ClusterNode represents a node in the cluster.
type CompressionAlgorithm ¶
type CompressionAlgorithm uint8
CompressionAlgorithm represents a compression algorithm.
const ( // AlgorithmNone means no compression. AlgorithmNone CompressionAlgorithm = 0 // AlgorithmLZ4 means LZ4 compression. AlgorithmLZ4 CompressionAlgorithm = 1 )
type Endpoints ¶
type Endpoints struct {
Version uint32 `json:"version"`
EndpointsV2 []Endpointv2 `json:"endpoints_v2"`
}
Endpoints represents peer endpoints for discovery.
func (*Endpoints) Type ¶
func (e *Endpoints) Type() MessageType
type Endpointv2 ¶
Endpointv2 represents a peer endpoint.
type GetLedger ¶
type GetLedger struct {
InfoType LedgerInfoType `json:"itype"`
LType LedgerType `json:"ltype,omitempty"`
LedgerHash []byte `json:"ledger_hash,omitempty"`
LedgerSeq uint32 `json:"ledger_seq,omitempty"`
NodeIDs [][]byte `json:"node_ids,omitempty"`
RequestCookie uint64 `json:"request_cookie,omitempty"`
QueryDepth uint32 `json:"query_depth,omitempty"`
QueryType QueryType `json:"query_type,omitempty"`
}
GetLedger requests ledger data.
func (*GetLedger) Type ¶
func (g *GetLedger) Type() MessageType
type GetObjectByHash ¶
type GetObjectByHash struct {
ObjType ObjectType `json:"type"`
Query bool `json:"query"`
Seq uint32 `json:"seq,omitempty"`
LedgerHash []byte `json:"ledger_hash,omitempty"`
Fat bool `json:"fat,omitempty"`
Objects []IndexedObject `json:"objects,omitempty"`
}
GetObjectByHash requests objects by hash.
func (*GetObjectByHash) Type ¶
func (g *GetObjectByHash) Type() MessageType
type HaveTransactionSet ¶
type HaveTransactionSet struct {
Status TxSetStatus `json:"status"`
Hash []byte `json:"hash"`
}
HaveTransactionSet indicates availability of a transaction set.
func (*HaveTransactionSet) Type ¶
func (h *HaveTransactionSet) Type() MessageType
type HaveTransactions ¶
type HaveTransactions struct {
Hashes [][]byte `json:"hashes"`
}
HaveTransactions indicates available transaction hashes.
func (*HaveTransactions) Type ¶
func (h *HaveTransactions) Type() MessageType
type Header ¶
type Header struct {
// PayloadSize is the size of the payload in bytes.
PayloadSize uint32
// MessageType is the type of the message.
MessageType MessageType
// Compressed indicates if the message is compressed.
Compressed bool
// UncompressedSize is the original size before compression (if compressed).
UncompressedSize uint32
// Algorithm is the compression algorithm used.
Algorithm CompressionAlgorithm
}
Header represents a parsed message header.
func DecodeHeader ¶
DecodeHeader decodes a message header from the provided buffer. The buffer must contain at least 6 bytes. If the message is compressed, an additional 4 bytes will be read. Reference: rippled ProtocolMessage.h
func PeekHeader ¶
PeekHeader reads and returns the header without consuming the payload. Useful for determining message type and size before full read.
func ReadMessage ¶
ReadMessage reads a complete message from the reader. Returns the header and the payload.
func (*Header) HeaderSize ¶
HeaderSize returns the size of the header based on compression.
type IndexedObject ¶
type IndexedObject struct {
Hash []byte `json:"hash,omitempty"`
NodeID []byte `json:"node_id,omitempty"`
Index []byte `json:"index,omitempty"`
Data []byte `json:"data,omitempty"`
LedgerSeq uint32 `json:"ledger_seq,omitempty"`
}
IndexedObject represents an indexed object.
type LedgerData ¶
type LedgerData struct {
LedgerHash []byte `json:"ledger_hash"`
LedgerSeq uint32 `json:"ledger_seq"`
InfoType LedgerInfoType `json:"type"`
Nodes []LedgerNode `json:"nodes,omitempty"`
RequestCookie uint32 `json:"request_cookie,omitempty"`
Error ReplyError `json:"error,omitempty"`
}
LedgerData contains ledger data response.
func (*LedgerData) Type ¶
func (l *LedgerData) Type() MessageType
type LedgerInfoType ¶
type LedgerInfoType int32
LedgerInfoType represents types of ledger information.
const ( LedgerInfoBase LedgerInfoType = 0 LedgerInfoTxNode LedgerInfoType = 1 LedgerInfoAsNode LedgerInfoType = 2 LedgerInfoTsCandidate LedgerInfoType = 3 )
type LedgerMapType ¶
type LedgerMapType int32
LedgerMapType represents types of ledger maps.
const ( LedgerMapTransaction LedgerMapType = 1 LedgerMapAccountState LedgerMapType = 2 )
type LedgerNode ¶
type LedgerNode struct {
NodeData []byte `json:"nodedata"`
NodeID []byte `json:"nodeid,omitempty"`
}
LedgerNode represents a node in the ledger.
type LedgerType ¶
type LedgerType int32
LedgerType represents types of ledgers.
const ( LedgerTypeAccepted LedgerType = 0 LedgerTypeCurrent LedgerType = 1 LedgerTypeClosed LedgerType = 2 )
type LoadSource ¶
type LoadSource struct {
Name string `json:"name"`
Cost uint32 `json:"cost"`
Count uint32 `json:"count,omitempty"`
}
LoadSource represents a source of load.
type Manifest ¶
type Manifest struct {
STObject []byte `json:"stobject"`
}
Manifest represents a validator manifest.
type Manifests ¶
Manifests is a collection of manifests.
func (*Manifests) Type ¶
func (m *Manifests) Type() MessageType
type Message ¶
type Message interface {
// Type returns the message type.
Type() MessageType
}
Message is the interface implemented by all protocol messages.
type MessageType ¶
type MessageType uint16
MessageType represents the type of a peer protocol message. Reference: rippled ripple.proto MessageType enum
const ( TypeUnknown MessageType = 0 TypeManifests MessageType = 2 TypePing MessageType = 3 TypeCluster MessageType = 5 TypeEndpoints MessageType = 15 TypeTransaction MessageType = 30 TypeGetLedger MessageType = 31 TypeLedgerData MessageType = 32 TypeProposeLedger MessageType = 33 TypeStatusChange MessageType = 34 TypeHaveSet MessageType = 35 TypeValidation MessageType = 41 TypeGetObjects MessageType = 42 TypeValidatorList MessageType = 54 TypeSquelch MessageType = 55 TypeValidatorListCollection MessageType = 56 TypeProofPathReq MessageType = 57 TypeProofPathResponse MessageType = 58 TypeReplayDeltaReq MessageType = 59 TypeReplayDeltaResponse MessageType = 60 TypeHaveTransactions MessageType = 63 TypeTransactions MessageType = 64 )
func (MessageType) String ¶
func (t MessageType) String() string
String returns the string representation of a MessageType.
type NodeStatus ¶
type NodeStatus int32
NodeStatus represents the status of a node.
const ( NodeStatusConnecting NodeStatus = 1 NodeStatusConnected NodeStatus = 2 NodeStatusMonitoring NodeStatus = 3 NodeStatusValidating NodeStatus = 4 NodeStatusShutting NodeStatus = 5 )
type ObjectType ¶
type ObjectType int32
ObjectType represents types of objects that can be requested.
const ( ObjectTypeUnknown ObjectType = 0 ObjectTypeLedger ObjectType = 1 ObjectTypeTransaction ObjectType = 2 ObjectTypeTransactionNode ObjectType = 3 ObjectTypeStateNode ObjectType = 4 ObjectTypeCasObject ObjectType = 5 ObjectTypeFetchPack ObjectType = 6 ObjectTypeTransactions ObjectType = 7 )
type Ping ¶
type Ping struct {
PType PingType `json:"type"`
Seq uint32 `json:"seq,omitempty"`
PingTime uint64 `json:"ping_time,omitempty"`
NetTime uint64 `json:"net_time,omitempty"`
}
Ping represents a ping/pong message for keepalive and latency measurement.
func (*Ping) Type ¶
func (p *Ping) Type() MessageType
type ProofPathRequest ¶
type ProofPathRequest struct {
Key []byte `json:"key"`
LedgerHash []byte `json:"ledger_hash"`
MapType LedgerMapType `json:"type"`
}
ProofPathRequest requests a proof path.
func (*ProofPathRequest) Type ¶
func (p *ProofPathRequest) Type() MessageType
type ProofPathResponse ¶
type ProofPathResponse struct {
Key []byte `json:"key"`
LedgerHash []byte `json:"ledger_hash"`
MapType LedgerMapType `json:"type"`
LedgerHeader []byte `json:"ledger_header,omitempty"`
Path [][]byte `json:"path,omitempty"`
Error ReplyError `json:"error,omitempty"`
}
ProofPathResponse contains a proof path response.
func (*ProofPathResponse) Type ¶
func (p *ProofPathResponse) Type() MessageType
type ProposeSet ¶
type ProposeSet struct {
ProposeSeq uint32 `json:"propose_seq"`
CurrentTxHash []byte `json:"current_tx_hash"`
NodePubKey []byte `json:"node_pub_key"`
CloseTime uint32 `json:"close_time"`
Signature []byte `json:"signature"`
PreviousLedger []byte `json:"previous_ledger"`
AddedTransactions [][]byte `json:"added_transactions,omitempty"`
RemovedTransactions [][]byte `json:"removed_transactions,omitempty"`
}
ProposeSet represents a ledger proposal.
func (*ProposeSet) Type ¶
func (p *ProposeSet) Type() MessageType
type ReplayDeltaRequest ¶
type ReplayDeltaRequest struct {
LedgerHash []byte `json:"ledger_hash"`
}
ReplayDeltaRequest requests replay delta.
func (*ReplayDeltaRequest) Type ¶
func (r *ReplayDeltaRequest) Type() MessageType
type ReplayDeltaResponse ¶
type ReplayDeltaResponse struct {
LedgerHash []byte `json:"ledger_hash"`
LedgerHeader []byte `json:"ledger_header,omitempty"`
Transactions [][]byte `json:"transaction,omitempty"`
Error ReplyError `json:"error,omitempty"`
}
ReplayDeltaResponse contains replay delta response.
func (*ReplayDeltaResponse) Type ¶
func (r *ReplayDeltaResponse) Type() MessageType
type ReplyError ¶
type ReplyError int32
ReplyError represents error codes in replies.
const ( ReplyErrorNone ReplyError = 0 ReplyErrorNoLedger ReplyError = 1 ReplyErrorNoNode ReplyError = 2 ReplyErrorBadRequest ReplyError = 3 )
type Squelch ¶
type Squelch struct {
Squelch bool `json:"squelch"`
ValidatorPubKey []byte `json:"validator_pub_key"`
SquelchDuration uint32 `json:"squelch_duration,omitempty"`
}
Squelch represents a squelch message for reduce-relay.
func (*Squelch) Type ¶
func (s *Squelch) Type() MessageType
type StatusChange ¶
type StatusChange struct {
NewStatus NodeStatus `json:"new_status,omitempty"`
NewEvent NodeEvent `json:"new_event,omitempty"`
LedgerSeq uint32 `json:"ledger_seq,omitempty"`
LedgerHash []byte `json:"ledger_hash,omitempty"`
LedgerHashPrevious []byte `json:"ledger_hash_previous,omitempty"`
NetworkTime uint64 `json:"network_time,omitempty"`
FirstSeq *uint32 `json:"first_seq,omitempty"`
LastSeq *uint32 `json:"last_seq,omitempty"`
}
StatusChange represents a node status change.
func (*StatusChange) Type ¶
func (s *StatusChange) Type() MessageType
type Transaction ¶
type Transaction struct {
RawTransaction []byte `json:"raw_transaction"`
Status TransactionStatus `json:"status"`
ReceiveTimestamp uint64 `json:"receive_timestamp,omitempty"`
Deferred bool `json:"deferred,omitempty"`
}
Transaction represents a transaction message.
func (*Transaction) Type ¶
func (t *Transaction) Type() MessageType
type TransactionStatus ¶
type TransactionStatus int32
TransactionStatus represents the status of a transaction.
const ( TxStatusNew TransactionStatus = 1 TxStatusCurrent TransactionStatus = 2 TxStatusCommitted TransactionStatus = 3 TxStatusRejectConflict TransactionStatus = 4 TxStatusRejectInvalid TransactionStatus = 5 TxStatusRejectFunds TransactionStatus = 6 TxStatusHeldSeq TransactionStatus = 7 TxStatusHeldLedger TransactionStatus = 8 )
type Transactions ¶
type Transactions struct {
Transactions []Transaction `json:"transactions"`
}
Transactions is a collection of transactions.
func (*Transactions) Type ¶
func (t *Transactions) Type() MessageType
type TxSetStatus ¶
type TxSetStatus int32
TxSetStatus represents the status of a transaction set.
const ( TxSetStatusHave TxSetStatus = 1 TxSetStatusCanGet TxSetStatus = 2 TxSetStatusNeed TxSetStatus = 3 )
type Validation ¶
type Validation struct {
Validation []byte `json:"validation"`
}
Validation represents a ledger validation message.
func (*Validation) Type ¶
func (v *Validation) Type() MessageType
type ValidatorBlobInfo ¶
type ValidatorBlobInfo struct {
Manifest []byte `json:"manifest,omitempty"`
Blob []byte `json:"blob"`
Signature []byte `json:"signature"`
}
ValidatorBlobInfo represents v2 validator blob info.
type ValidatorList ¶
type ValidatorList struct {
Manifest []byte `json:"manifest"`
Blob []byte `json:"blob"`
Signature []byte `json:"signature"`
Version uint32 `json:"version"`
}
ValidatorList represents a validator list (UNL).
func (*ValidatorList) Type ¶
func (v *ValidatorList) Type() MessageType
type ValidatorListCollection ¶
type ValidatorListCollection struct {
Version uint32 `json:"version"`
Manifest []byte `json:"manifest"`
Blobs []ValidatorBlobInfo `json:"blobs"`
}
ValidatorListCollection represents a collection of v2 validator lists.
func (*ValidatorListCollection) Type ¶
func (v *ValidatorListCollection) Type() MessageType