messages

package
v0.0.0-...-58ee6da Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: Unlicense Imports: 10 Imported by: 0

Documentation

Overview

Internal messages used for data sharing between components, and locally, to avoid race conditions with data access. Local message numbers should start at 1000, message numbers internal to a single package should be negative.

A message to/from a peer.

Index

Constants

View Source
const (
	TypeInternalConnectionFailure  int16 = 1   // payload[0] is an IP as a string, payload[1] is the message type as int16
	TypeInternalConnectionSuccess  int16 = 2   // payload[0] is an IP as a string, payload[1] is the message type as int16
	TypeInternalNewFrozenEdgeBlock int16 = 3   // payload[0] * to the block that has been frozen, payload[1] nil, or * to the block's balance list (during bootstrapping)
	TypeInternalNewRetentionEdge   int16 = 4   // payload[0] is the new retention edge as int64
	TypeInternalNewTrailingEdge    int16 = 5   // payload[0] is the new trailing edge as int64
	TypeInternalSendToRandomNode   int16 = 6   // payload[0] is the message to send to a random node
	TypeInternalBootstrapBlock     int16 = 7   // payload[0] is the block height, payload[1] is the hash of this block's balance list
	TypeInternalChainInitialized   int16 = 8   // no payload
	TypeInternalDataStoreHeight    int16 = 9   // payload[0] is the highest height stored in the data store, used to bootstrap archive mode
	TypeInternalTransaction        int16 = 10  // transaction DB storage event, payload: see balance_authority, emitTransaction
	TypeInternalCycleEvent         int16 = 11  // cycle DB storage event, payload: see block_file_handler, emitCycleEvents
	TypeInternalBlock              int16 = 12  // block DB storage event, payload: see block_file_handler, emitBlock
	TypeInternalNodeStatus         int16 = 13  // node status DB storage event, payload: see node.Status
	TypeInternalExiting            int16 = 200 // exit program gracefully
)
View Source
const (
	ConnectionTimeout = time.Second * 5
	ReadTimeout       = time.Second * 5
	WriteTimeout      = time.Second * 5
)
View Source
const (
	TypeNodeJoinLegacy           int16 = 3
	TypeNodeJoinResponseLegacy   int16 = 4
	TypeBlockRequest             int16 = 11
	TypeBlockResponse            int16 = 12
	TypeMeshRequest              int16 = 15 // request node-information for in-cycle nodes
	TypeMeshResponse             int16 = 16 // a (capped) list of in-cycle nodes
	TypeStatusRequest            int16 = 17
	TypeStatusResponse           int16 = 18
	TypeBlockVote                int16 = 19
	TypeMissingBlockVoteRequest  int16 = 23
	TypeMissingBlockVoteResponse int16 = 24
	TypeMissingBlockRequest      int16 = 25
	TypeMissingBlockResponse     int16 = 26
	TypeBootstrapRequest         int16 = 35 // request "starter" information about the frozen edge and the cycle
	TypeBootstrapResponse        int16 = 36 // frozen edge height, frozen edge block hash, a list of all in-cycle verifier IDs
	TypeBlockWithVotesRequest    int16 = 37
	TypeBlockWithVotesResponse   int16 = 38
	TypeFullMeshRequest          int16 = 41 // request node-information for all nodes
	TypeFullMeshResponse         int16 = 42 // a (capped) list of all known nodes
	TypeNodeJoin                 int16 = 43
	TypeNodeJoinResponse         int16 = 44
	TypeIpAddressRequest         int16 = 53
	TypeIpAddressResponse        int16 = 54
	TypeWhitelistRequest         int16 = 424
	TypeWhitelistResponse        int16 = 425
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InternalMessage

type InternalMessage struct {
	Type         int16
	Payload      []interface{}
	ReplyChannel chan *InternalMessage
}

func NewInternalMessage

func NewInternalMessage(messageType int16, a ...interface{}) *InternalMessage

type Message

type Message struct {
	Timestamp    int64 // millisecond precision -- when the message is first generated
	Type         int16
	Content      Serializable  // tbd
	SourceId     []byte        // the public key of the node that created this message
	Signature    []byte        // the signature of all preceding parts
	SourceIP     []byte        // not serialized, source IP in byte format
	ReplyChannel chan *Message // channel to receive an internal reply to this message
}

func NewLocal

func NewLocal(messageType int16, messageContent Serializable, identity *identity.Identity) *Message

Create a new message, local variant (the ones we can sign).

func ReadNew

func ReadNew(r io.Reader, sourceAddress string) (*Message, error)

Construct a new message from a byte slice Format + byte length:

Message Length  4
Timestamp       8
Type            2
Content        <variable>
Identifier     32
Signature      64

func (*Message) SerializeForSigning

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

Serialize for signing. Format + byte length:

Timestamp       8
Type            2
Content        <variable>
Identifier     32

func (*Message) SerializeForTransmission

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

Serialize for transmission. Format + byte length:

Message Length  4
Timestamp       8
Type            2
Content        <variable>
Identifier     32
Signature      64

func (*Message) SignatureIsValid

func (m *Message) SignatureIsValid() bool

Verify this messages's signature and return whether it's valid.

type Serializable

type Serializable interface {
	GetSerializedLength() int // how many bytes will ToBytes return?
	ToBytes() []byte          // convert to bytes
	Read(r io.Reader) error   // read from bytes
}

Serialization to and from bytes

Directories

Path Synopsis
TODO: the Java version sends V1 join messages during the startup process, but V2s in some other contexts.
TODO: the Java version sends V1 join messages during the startup process, but V2s in some other contexts.
message_fields
Byte level message field sizes Byte level message field serialization.
Byte level message field sizes Byte level message field serialization.

Jump to

Keyboard shortcuts

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