messages

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package messages objects and methods for basic serialization of data into structured messages that can be read by this project.

Integers are encoded using config.encoding BigInts are encoded using GOB Binary values are stored as a single byte, a 0 value byte is considered 0, any other value is considered 1

A struture of a message for the consensus is as follows:

  • A 4 byte encoded integer indicating the total size of the message in bytes (not including these 4 bytes)

  • A series of header/contents

  • A 4 byte integer indicating the size of the header (including these 4 bytes).

  • A 4 byte encoded integer indicating the header type.

  • If the header is signed, an encoded consensus id indicating the consensus index this header belongs to, which can be either:

  • An 8 byte encoded integer.

  • Or a hash (encoding defined by the hash type defined in the configuration).

  • An uint64 encoded as a uvarint indicating the number of additional consensus ids this header belongs to (if total order is being used this will be 0, see causal ordering for more details on where this is used).

  • The additional consensus indices as given by the previous field.

  • If the header contains at least 1 consensus index then a 32 byte unique ID for this consensus (see CsID) which is included in every signed header (TODO insure only messages with indices can be signed).

  • The contents are then defined custom for each header type

For signed headers, the signed part starts after the size and includes the consensus index, the consensus unique ID, and any other contents as determined by the result of the call to InternalSignedMsgHeader.SerializeInternal for the message type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendMessage

func AppendMessage(front *Message, end *Message)

AppendMessage appends two messages together into a single message and upates the size Only front is updated

func CreateSingleMsgBytes

func CreateSingleMsgBytes(header SeralizeHeader) []byte

SerializeSingle serializes a header by itself into a byte slice

func DecodeHelperMsg

func DecodeHelperMsg(msg *MsgBuffer) (n int, buff []byte, err error)

DecodeHelperMsg reads a slice of bytes that was written to the message by utils.EncodeHelper

func DeserializeHelper

func DeserializeHelper(headerID HeaderID, item types.BasicEncodeInterface,
	m *Message) (n int, err error)

func DeserialzeInternalSignedHeader

func DeserialzeInternalSignedHeader(hdr InternalSignedMsgHeader, unmarFunc types.ConsensusIndexFuncs,
	m *Message) (index types.ConsensusIndex, bytesRead, signOffset,
	signEndOffset int, size uint32, err error)

func GetBytesHelper

func GetBytesHelper(m *Message) ([]byte, error)

func GetMsgSizeLen

func GetMsgSizeLen() int

func IsProposalHeader

func IsProposalHeader(msgIndex types.ConsensusIndex, hdr InternalSignedMsgHeader) bool

func PeekHeaderHead

func PeekHeaderHead(unmarFunc types.ConsensusIndexFuncs, m *MsgBuffer) (index types.ConsensusIndex, err error)

PeekHeaderHead is a helper method used before deserialization, it returns the indices of the message.

func ReadHeaderHead

func ReadHeaderHead(id HeaderID, unmarFunc types.ConsensusIDUnMarshaler, m *MsgBuffer) (l int,
	index types.ConsensusID, additionalIndices []types.ConsensusID, size uint32, offset int, err error)

ReadHeaderHead is a helper method used during MsgHeader.Serialize to read the first part of the header to message m. It reads the HeaderID and header size according to the message format described in the root documentation of this package. It checks the HeaderID is correct as well as the CsID. It returns the number of bytes read, the size of the full header, and the offset in the message where the header starts. IMPORTANT: if unmarFunc is nil it expects not to have any indecies, which meas it will not include CsID either.

func SerializeHelper

func SerializeHelper(headerID HeaderID, item types.BasicEncodeInterface, m *Message) (n int, err error)

func SerializeInternalSignedHeader

func SerializeInternalSignedHeader(index types.ConsensusIndex,
	hdr InternalSignedMsgHeader, m *Message) (bytesWritten, signOffset, signEndOffset, sizeOffset int, err error)

func SerializeSingleItem

func SerializeSingleItem(header MsgHeader) []byte

SerializeSingleItem serializes a header by itself into a byte slice

func WriteHeaderHead

func WriteHeaderHead(index types.ConsensusID, additionalIndecies []types.ConsensusID, id HeaderID,
	size uint32, m *MsgBuffer) (l int, sizeOffset int, offset int)

WriteHeaderHead is a helper method used during MsgHeader.Serialize to write the first part of the header to message m. It reads the HeaderID and header size according to the message format described in the root documentation of this package. It writes the size of the header, the HeaderID and the CsID. It returns the number of bytes written, the offset in the message where the size is stored, and the offset in the message where the header starts. Important: if index is nil, it will not write any indecies and will not include the CsID.

Types

type Any

type Any interface {
}

type BasicMsgID

type BasicMsgID HeaderID

BasicMsgID implements the MsgID interface as a HeaderID. So every message header with the same HeaderID will have equal MsgIDs.

func (BasicMsgID) IsMsgID

func (BasicMsgID) IsMsgID() bool

IsMsgID to satisfy the interface and returns true

func (BasicMsgID) ToBytes

func (bm BasicMsgID) ToBytes(index types.ConsensusIndex) []byte

func (BasicMsgID) ToMsgIDInfo

func (bm BasicMsgID) ToMsgIDInfo() MsgIDInfo

ToMsgIDInfo converts the MsgID to a MsgIDInfo

type EventInfoMsgID

type EventInfoMsgID types.HashBytes

EventInfoMsgID implements the MsgID interface as a Hash, so every different message is different

func (EventInfoMsgID) IsMsgID

func (EventInfoMsgID) IsMsgID() bool

IsMsgID to satisfy the interface and returns true

func (EventInfoMsgID) ToBytes

func (bm EventInfoMsgID) ToBytes(types.ConsensusIndex) []byte

func (EventInfoMsgID) ToMsgIDInfo

func (bm EventInfoMsgID) ToMsgIDInfo() MsgIDInfo

ToMsgIDInfo converts the MsgID to a MsgIDInfo

type HeaderID

type HeaderID uint32

HeaderID Each message type has a its own header id, this will identify serialized messages

const (
	HdrBcons            HeaderID = iota // A binary consensus message
	HdrBconsAux                         // A binary consensus aux message
	HdrTest                             // A test message
	HdrNetworkTest                      // A network test message
	HdrTestTimeout                      // A timeout test message
	HdrNoProgress                       // A message indicating a node has not made progress towards a decision after a timeout
	HdrConsMsg                          // A consensus message
	HdrBinState                         // A message containing multiple consensus messages
	HdrSimpleCons                       // A message for the simple consensus test protocol
	HdrPropose                          // A message containing a consensus proposal, used in the sime consensus and tests
	HdrBinPropose                       // A message containing a single binary value consensus proposal
	HdrMvPropose                        // A message containing a multi-value proposal
	HdrEcsig                            // A message containing an EC signature
	HdrEcpub                            // A message containing an EC public key
	HdrEcpriv                           // A message containing an EC private key
	HdrSignTest                         // A message for a signature test
	HdrAuxProof                         // A message containing proof supporting an aux binary value
	HdrAuxStage0                        // A message containing proof supporting an aux binary value
	HdrAuxStage1                        // A message containing proof supporting an aux binary value
	HdrAuxBoth                          // A message containing proof supporting an aux binary value or both binary values
	HdrBV0                              // A binary value message for 0
	HdrBV1                              // A binary message for 1
	HdrCoin                             // A message used to compute a random coin for a round for StrongCoin1.
	HdrCoinPre                          // A message sent before the coin to change a t+1 coin to an n-t one
	HdrCoinProof                        // A proof for a coin.
	HdrAuxProofTimeout                  // A round timeout in binary consensus
	HdrMvInitTimeout                    // An init message timeout in multivalue consensus
	HdrMvInitVRFTimeout                 // An init message timeout in multivalue consensus
	HdrMvEchoTimeout                    // An echo message timeout in multivalue consensus
	HdrMvCommitTimeout                  // A commit message timeout in multivalue consensus
	HdrMvInit                           // A multivalue consensus init message
	HdrMvMultiInit                      // A multivalue consensus init message with multiple proposals
	HdrMvInitSupport                    // A multivalue consensus init message with pointers to a previous init message
	HdrMvEcho                           // A multivalue consensus echo message
	HdrMvEchoHash                       // A multivalue consensus echo message with an additional hash
	HdrMvCommit                         // A multivalue consensus commit message
	HdrMvRecoverTimeout                 // A multivalue consensus recovery timeout message
	HdrMvRequestRecover                 // A multivalue consensus message requesting the decided value
	// HdrDSSPartSig                       // A partial threshold signature message
	// HdrDSSPartPub                       // A partial threshold public key message
	HdrEdsig      // An EDDSA signature message
	HdrEdpub      // An EDDSA public key message
	HdrSleepPub   // A Sleep pub message
	HdrSleepCoin  // A sleep coin message
	HdrSchnorrsig // A schnorr signature message
	HdrSleepSig   // A sleep signature message
	HdrSchnorrpub // A schnorr public key message
	HdrBlssig     // A BLS signature message
	HdrBlspub     // A BLS public key message
	HdrEdPartPub  // A partial threshold signature
	HdrDualPub    // A dual pub message
	HdrPartialMsg // A message that is broken into several parts
	HdrHash       // A message that contains a hash
	HdrIdx        // A message that contains an index for each node
	HdrIdxRecover // Same as HdrIdx except used during recovery
	HdrEventInfo  // A message that contains a hash event info
	HdrVrfProof   // A message that contains a VRF proof
	HdrQsafeSig   // A quantum safe signature
	HdrQsafePub   // A quantum safe public key
)

Each message type is encoded in a 4 byte integer

func (HeaderID) String

func (hi HeaderID) String() string

String returns the header id name as a string

func (HeaderID) StringShort

func (h HeaderID) StringShort() string

type InternalSignedMsgHeader

type InternalSignedMsgHeader interface {
	MsgIDHeader
	// GetBaseMsgHeader returns the header pertaning to the message contents (in most cases just directly returns the same header).
	GetBaseMsgHeader() InternalSignedMsgHeader
	// SerializeInternal serializes the header contents, returning the number of bytes written and the end of the part of the message that should be signed.
	SerializeInternal(m *Message) (bytesWritten, signEndOffset int, err error)
	// DeserializeInternal deserializes the header contents, returning the number of bytes read and the end of the signed part of the message.
	DeserializeInternal(m *Message) (bytesRead, signEndOffset int, err error)
	// ShallowCopy preforms a shallow copy of the header.
	ShallowCopy() InternalSignedMsgHeader
	// NeedsSMValidation should return a byte slice if the message should be validated by the state machine before being processed,
	// otherwise it should return nil.
	// If proposal is non-nil idx should be the state machine index that will be used to validate this message.
	// It takes as input the current index.
	// If the message has multiple proposals then proposalIdx is the index of the proposal being requested.
	// If causal ordering is used then the idx returned is not used.
	NeedsSMValidation(msgIndex types.ConsensusIndex, proposalIdx int) (idx types.ConsensusIndex, proposal []byte, err error)
	// NeedsCoinProof returns true if this message must include a proof for a coin message.
	GetSignType() types.SignType
}

type Message

type Message MsgBuffer

func AppendHeader

func AppendHeader(msg *Message, header MsgHeader) (*Message, error)

AppendHeader adds a serialized header to the end of msg and updates the size

func AppendHeaders

func AppendHeaders(msg *Message, headers []MsgHeader) (*Message, error)

AppendHeaders serialized the list of headers and appends them to the end of msg

func AppendSerialize

func AppendSerialize(msg *Message, header SeralizeHeader) (*Message, error)

AppendSerialize adds a serialized header to the end of msg and updates the size

func CreateMsg

func CreateMsg(headers []MsgHeader) (*Message, error)

CreateMsg creates a serialzed messages from a set of headers

func CreateMsgFromBytes

func CreateMsgFromBytes(buf []byte) (*Message, error)

CreateMsgFromBytes creates a serialzed messages from bytes.

func CreateMsgSingle

func CreateMsgSingle(header MsgHeader) (*Message, error)

CreateMsgSingle creates a serialized message containing a single header.

func InitMsgSetup

func InitMsgSetup(hdrs []MsgHeader, t *testing.T) *Message

InitMsgSetup is used by tests to create a serialized message from hdrs.

func NewMessage

func NewMessage(buff []byte) *Message

func SerializeHeader

func SerializeHeader(header MsgHeader) (*Message, error)

Serialize seralizes a header

func SerializeHeaders

func SerializeHeaders(headers []MsgHeader) (*Message, error)

Serialize seralizes a header

func (*Message) CheckHash

func (m *Message) CheckHash(offset int, endoffset int, includesHash bool) (types.HashBytes, int, error)

func (*Message) ComputeHash

func (m *Message) ComputeHash(offset, endoffset int, includeHash bool) (types.HashBytes, int, error)

func (*Message) GetBytes

func (m *Message) GetBytes() []byte

func (*Message) GetDebug

func (m *Message) GetDebug() []byte

func (*Message) Len

func (m *Message) Len() int

func (*Message) PeekHeaderType

func (m *Message) PeekHeaderType() (HeaderID, error)

func (*Message) PeekHeaderTypeAt

func (m *Message) PeekHeaderTypeAt(offs int) (HeaderID, error)

func (*Message) PeekMsgConsID

func (m *Message) PeekMsgConsID(unmarFunc types.ConsensusIDUnMarshaler) (cid types.ConsensusID, err error)

func (*Message) PeekMsgIndex

func (m *Message) PeekMsgIndex() (types.ConsensusInt, error)

func (*Message) PopHeaderType

func (m *Message) PopHeaderType() (int, error)

func (*Message) PopMsgSize

func (m *Message) PopMsgSize() (int, error)

func (*Message) ResetOffset

func (m *Message) ResetOffset()

type MsgBuffer

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

MsgBuffer is for serializing a message. Read/get and write/put operations can be performed on the buffer. Read operations read based on the index of the previous read, where each operation incraments the index. E.g. the first ReadUint32 reads bytes 0-3, and the follow reads 3-7 Peek operations do not change the index. Write operations write to the end of the buffer. ReadAt/WriteAt operations read/write at a specific index in the buffer.

func NewMsgBuffer

func NewMsgBuffer() *MsgBuffer

NewMsgBuffer creates a new empty buffer

func NewMsgBufferSize

func NewMsgBufferSize(i int, n int) *MsgBuffer

NewMsgBuffer creates a new buffer using the following: "make([]byte, i, n)"

func ToMsgBuffer

func ToMsgBuffer(buff []byte) *MsgBuffer

ToMsgBuffer creates a MsgBuffer object from the bytes, the read offset is set to the beginning and the writeoffset is set to the end

func (*MsgBuffer) AddBigInt

func (mb *MsgBuffer) AddBigInt(v *big.Int) (int, int)

AddBinInt encodes v and appends it to the end of the buffer. It returns the number of bytes written, and the offset of where it was written.

func (*MsgBuffer) AddBin

func (mb *MsgBuffer) AddBin(v types.BinVal, allowCoin bool) int

AddBin appends binary value v to the end of the buffer. It returns the offset where v was written to the buffer.

func (*MsgBuffer) AddBool

func (mb *MsgBuffer) AddBool(v bool) int

AddBool appends a boolean value v to the end of the buffer. It returns the offset where v was written to the buffer.

func (*MsgBuffer) AddByte

func (mb *MsgBuffer) AddByte(v byte) int

AddByte appends v to the end of the buffer. It returns the offset where v was written in the buffer.

func (*MsgBuffer) AddBytes

func (mb *MsgBuffer) AddBytes(v []byte) (int, int)

AddBytes append v to the end of the buffer. It reutrns len(v) and the offset where v was written in the buffer.

func (*MsgBuffer) AddConsensusID

func (mb *MsgBuffer) AddConsensusID(v types.ConsensusID) (int, int)

AddConsensusID encodes the id and appends to the end of the buffer. It returns the number of bytes written and where v was written in the buffer.

func (*MsgBuffer) AddConsensusRound

func (mb *MsgBuffer) AddConsensusRound(v types.ConsensusRound) (int, int)

AddConsensusRound encodes the round and appends to the end of the buffer. It returns the number of bytes written and where v was written in the buffer.

func (*MsgBuffer) AddHeaderID

func (mb *MsgBuffer) AddHeaderID(v HeaderID) (int, int)

AddHeaderID encodes v and appends it to the end of the buffer. It returns 4 and the offset of where v was written in the buffer.

func (*MsgBuffer) AddSizeBytes

func (mb *MsgBuffer) AddSizeBytes(buff []byte) (int, int)

WriteSizeBytes writes a slice of bytes to be read by ReadSizeBytes (it contains a serialized number followed by the bytes) It returns the number of bytes written and the offset where the values were written in the buffer.

func (*MsgBuffer) AddUint32

func (mb *MsgBuffer) AddUint32(v uint32) (int, int)

AddUint32 encodes v and appends it to the end of the buffer. It returns 4 and the offset of where v was written in the buffer.

func (*MsgBuffer) AddUint64

func (mb *MsgBuffer) AddUint64(v uint64) (int, int)

AddUint64 encodes v and appends it to the end of the buffer. It returns 8 and the index where v was written

func (*MsgBuffer) AddUvarint

func (mb *MsgBuffer) AddUvarint(v uint64) (n int, offest int)

AddUvarint writes a unsigned variable size integer. It returns the number of bytes written and where v was written in the buffer.

func (*MsgBuffer) GetReadOffset

func (mb *MsgBuffer) GetReadOffset() int

GetReadOffset returns the current read offset

func (*MsgBuffer) GetRemainingBytes

func (mb *MsgBuffer) GetRemainingBytes() []byte

GetRemainingBytes returns the remaining bytes from the current read offset.

func (*MsgBuffer) GetSlice

func (mb *MsgBuffer) GetSlice(start, end int) ([]byte, error)

GetSlice returns the slice of bytes from start to end in the buffer

func (*MsgBuffer) GetSliceFrom

func (mb *MsgBuffer) GetSliceFrom(start int) ([]byte, error)

GetSlice from returns the slice starting at start until the end of the buffer

func (*MsgBuffer) GetWriteOffset

func (mb *MsgBuffer) GetWriteOffset() int

GetWriteOffest returns the current write offset (this will always be the end of the buffer)

func (*MsgBuffer) PeekConsIDAt

func (mb *MsgBuffer) PeekConsIDAt(offs int, unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)

PeekConsIDAt gets the consensusID at the given offset using the unmarshal function. It returns the id and the number of bytes read.

func (*MsgBuffer) PeekUint32

func (mb *MsgBuffer) PeekUint32() (uint32, error)

PeekUint32 returns the uint32 at the current read offset

func (*MsgBuffer) PeekUint32At

func (mb *MsgBuffer) PeekUint32At(offs int) (uint32, error)

PeekUint32 returns the uint32 at the current offset plus offs

func (*MsgBuffer) PeekUint64

func (mb *MsgBuffer) PeekUint64() (uint64, error)

PeekUint64 returns the uint64 at the current read offset

func (*MsgBuffer) PeekUint64At

func (mb *MsgBuffer) PeekUint64At(offs int) (uint64, error)

PeekUint64At returns the uint64 at the current read offset plus offs

func (*MsgBuffer) PeekUvarintAt

func (mb *MsgBuffer) PeekUvarintAt(offset int) (v uint64, n int, err error)

PeekUvarintAt returns the uvarint at the current read offset plus offset. It returns the uint64 and the number of bytes read

func (*MsgBuffer) Read

func (mb *MsgBuffer) Read(p []byte) (n int, err error)

Read implements io.Reader read

func (*MsgBuffer) ReadBigInt

func (mb *MsgBuffer) ReadBigInt() (*big.Int, int, error)

ReadBigInt reads a big integer from the buffer, It returns the big int, and the new read index

func (*MsgBuffer) ReadBin

func (mb *MsgBuffer) ReadBin(allowCoin bool) (types.BinVal, error)

ReadBin reads a binary value from the buffer and increments the read offset. A binVal is 1 byte, any non-zero value is 1.

func (*MsgBuffer) ReadBool

func (mb *MsgBuffer) ReadBool() (bool, error)

ReadBool reads a boolean value from the buffer and increments the read offset. A bool is encoded as a byte, any non-zero value is considered true.

func (*MsgBuffer) ReadByte

func (mb *MsgBuffer) ReadByte() (byte, error)

ReadByte reads a byte from the buffer and increments the read offset

func (*MsgBuffer) ReadBytes

func (mb *MsgBuffer) ReadBytes(n int) ([]byte, error)

ReadBytes reads n bytes from the buffer and updates the read offset

func (*MsgBuffer) ReadConsensusID

func (mb *MsgBuffer) ReadConsensusID(unmarFunc types.ConsensusIDUnMarshaler) (types.ConsensusID, int, error)

ReadConsensusID reads a consensus id from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.

func (*MsgBuffer) ReadConsensusIndex

func (mb *MsgBuffer) ReadConsensusIndex() (types.ConsensusInt, int, error)

ReadConsensusIndex reads a consensus index from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.

func (*MsgBuffer) ReadConsensusRound

func (mb *MsgBuffer) ReadConsensusRound() (types.ConsensusRound, int, error)

ReadConsensusRound reads a consensus round from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.

func (*MsgBuffer) ReadHeaderID

func (mb *MsgBuffer) ReadHeaderID() (HeaderID, int, error)

ReadHeaderID reads a HeaderID from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.

func (*MsgBuffer) ReadSizeBytes

func (mb *MsgBuffer) ReadSizeBytes() ([]byte, int, error)

ReadSizeBytes reads a slice of bytes written by AddSizeBytes, it returns the nubmer of bytes read (i.e. a serialized number followed by that many bytes)

func (*MsgBuffer) ReadUint32

func (mb *MsgBuffer) ReadUint32() (uint32, int, error)

ReadUint32 reads a uint32 from the buffer. It returns the value read, the number of bytes read, and any errors. It also increments the read offset.

func (*MsgBuffer) ReadUint64

func (mb *MsgBuffer) ReadUint64() (uint64, int, error)

ReadKey return the uint64 at the current offset, the number of bytes read, and any error. It also increments the read offset.

func (*MsgBuffer) ReadUvarint

func (mb *MsgBuffer) ReadUvarint() (v uint64, n int, err error)

ReadUvarint reads an unsigned variable sized integer from the buffer. It returns the value read, the number of bytes read and any errors.

func (*MsgBuffer) RemainingLen

func (mb *MsgBuffer) RemainingLen() int

RemainingLen returns the number of bytes from the current read offset to the end of the buffer.

func (*MsgBuffer) ResetOffset

func (mb *MsgBuffer) ResetOffset()

ResetOffest sets the read offset to 0, so the following read will read from the beginning of the buffer

func (*MsgBuffer) Write

func (mb *MsgBuffer) Write(p []byte) (n int, err error)

Write appends p to the end of the buffer and returns len(p)

func (*MsgBuffer) WriteAt

func (mb *MsgBuffer) WriteAt(offset int, p []byte) (n int, err error)

WriteAt writes p to the buffer at offset and returns len(p)

func (*MsgBuffer) WriteByte

func (mb *MsgBuffer) WriteByte(p byte) error

WriteByte appends p to the end of the buffer

func (*MsgBuffer) WriteUint32At

func (mb *MsgBuffer) WriteUint32At(offset int, v uint32) error

WriteUint32At encodes v and overwrites the bytes at offset

func (*MsgBuffer) WriteUint32AtStart

func (mb *MsgBuffer) WriteUint32AtStart(v uint32) error

WriteUint32 encodes and overwrites the beggning of the message with v

type MsgHeader

type MsgHeader interface {
	MsgIDHeader
	SeralizeHeader
	// PeekHeader returns the indices related to the messages without impacting m.
	PeekHeaders(m *Message, unmarFunc types.ConsensusIndexFuncs) (index types.ConsensusIndex, err error)
	Deserialize(m *Message, unmarFunc types.ConsensusIndexFuncs) (int, error) // Deserialize deserialzes a header into the object, returning the number of bytes read
	GetBytes(m *Message) ([]byte, error)                                      // GetBytes returns the bytes that make up the header
}

MsgHeader is a component of a messsage that contains an id (an encoded 4 byte integer), followed by any data The interface allows for serialization and deserialzation of the message

func AppendCopyMsgHeader

func AppendCopyMsgHeader(slice []MsgHeader, elems ...MsgHeader) []MsgHeader

AppendCopyMsgHeader appends the input into a new slice.

type MsgID

type MsgID interface {
	IsMsgID() bool                             // IsMsgID to satisfy the interface and returns true
	ToBytes(index types.ConsensusIndex) []byte // Returns the byte representation of MsgID
	ToMsgIDInfo() MsgIDInfo                    // ToMsgIDInfo converts the MsgID to a MsgIDInfo

}

MsgID: Each message has a MsgID, that may differentiate it between messages of the same type for example a binary messages have the same MsgID for the same round (for both 1 and 0) but have different MsgIDs for different rounds this is only used internally and not serialized The idea is so we can cout how many messages of each type we have gotten. For example if we want to have 'n-t' messages of type 'aux' for round 1 of binary consensus, we will use the MsgID to count these, since they will have the same MsgID even if they support different binary values. Note it is importat that MsgID is comparable with == (i.e. if it returns a pointer to a new object then every message header will have a different MsgID) TODO maybe this check should happen in a method instead like 'CheckEqual'

type MsgIDHeader

type MsgIDHeader interface {
	GetID() HeaderID // GetID returns the header id for this header
	GetMsgID() MsgID // GetMsgID returns the MsgID for this specific header (see MsgID definition for more details)
}

type MsgIDInfo

type MsgIDInfo struct {
	Round    uint32
	HeaderID uint32
	Extra    byte
}

MsgIDInfo is just used for statistics

func (MsgIDInfo) Less

func (a MsgIDInfo) Less(b MsgIDInfo) bool

type SeralizeBuff

type SeralizeBuff []byte

Interface for using byte slice with the serialize method

func (SeralizeBuff) Serialize

func (buff SeralizeBuff) Serialize(m *Message) (int, error)

Serialize appends a serialized header to the message m, and returns the size of bytes written.

type SeralizeHeader

type SeralizeHeader interface {
	Serialize(m *Message) (int, error) // Serialize appends a serialized header to the message m, and returns the size of bytes written
}

SerializeHeader implements the serialize method

Jump to

Keyboard shortcuts

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