node

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

interface of local node

ln: abbr. of local node

Index

Constants

View Source
const (
	SharedKeySize = 32
)

for encryption

Variables

View Source
var EmptyNonce [nonceSize]byte

Functions

func DecryptMessage added in v2.2.0

func DecryptMessage(message []byte, sharedKey *[SharedKeySize]byte) ([]byte, bool, error)

func EncryptMessage added in v2.2.0

func EncryptMessage(message []byte, sharedKey *[SharedKeySize]byte) []byte

Types

type IChordInfo added in v2.2.0

type IChordInfo interface{}

type ILocalNode added in v2.2.0

type ILocalNode interface {

	// info
	GetNeighborInfo() []*RemoteNode
	GetChordInfo() IChordInfo

	// node
	GetMinVerifiableHeight() uint32
	GetChordID() []byte

	// handler
	AddMessageHandler(messageType pb.MessageType, handler MessageHandler)

	SerializeMessage(unsignedMsg *pb.UnsignedMessage, sign bool) ([]byte, error)

	// localNode
	MarshalJSON() ([]byte, error)
	Start() error
	GetProposalSubmitted() uint32
	IncrementProposalSubmitted()
	GetRelayMessageCount() uint64
	IncrementRelayMessageCount()
	GetTxnPool() *pool.TxnPool
	GetHeight() uint32
	SetSyncState(s pb.SyncState) bool
	GetSyncState() pb.SyncState
	SetMinVerifiableHeight(height uint32)
	GetWsAddr() string
	GetWssAddr() string
	FindSuccessorAddrs(key []byte, numSucc int) ([]string, error)
	FindWsAddr(key []byte) (string, string, []byte, []byte, error)
	FindWssAddr(key []byte) (string, string, []byte, []byte, error)
	CheckIDChange(v interface{})
	ComputeSharedKey(remotePublicKey []byte) (*[SharedKeySize]byte, error)
	GetNnet() *nnet.NNet

	// neighbor
	GetNeighborByNNetNode(nnetRemoteNode *nnetnode.RemoteNode) *RemoteNode
	GetGossipNeighbors(filter func(*RemoteNode) bool) []*RemoteNode
	GetVotingNeighbors(filter func(*RemoteNode) bool) []*RemoteNode
	VerifySigChain(sc *pb.SigChain, height uint32) error
	VerifySigChainObjection(sc *pb.SigChain, reporterID []byte, height uint32) (int, error)
	GetNeighborNode(id string) *RemoteNode
	RemoveNeighborNode(id string)

	// relay
	SendRelayMessage(srcAddr, destAddr string, payload, signature, blockHash []byte, nonce, maxHoldingSeconds uint32) error
	NewSignatureChainObjectionMessage(height uint32, sigHash []byte) (*pb.UnsignedMessage, error)
	StartSyncing(syncStopHash common.Uint256, syncStopHeight uint32, neighbors []*RemoteNode) (bool, error)
	ResetSyncing()
	BroadcastTransaction(txn *transaction.Transaction) error

	// neighborNodes
	GetConnectionCnt() uint
	GetNeighbors(filter func(*RemoteNode) bool) []*RemoteNode

	// txnpool
	AppendTxnPool(txn *transaction.Transaction) error
}

type MessageHandler

type MessageHandler func(msg *RemoteMessage) (reply []byte, shouldCallNext bool, err error)

MessageHandler handles a message and returns reply, if it should be passed through to other message handler and error

type MessageHandlerStore added in v2.2.0

type MessageHandlerStore map[pb.MessageType][]MessageHandler

messageHandlerStore is the map from message type to message handler

func NewMessageHandlerStore added in v2.2.0

func NewMessageHandlerStore() *MessageHandlerStore

func (MessageHandlerStore) AddMessageHandler added in v2.2.0

func (handlerStore MessageHandlerStore) AddMessageHandler(messageType pb.MessageType, handler MessageHandler)

AddMessageHandler adds a message handler to a message type

func (MessageHandlerStore) GetMessageHandlers added in v2.2.0

func (handlerStore MessageHandlerStore) GetMessageHandlers(messageType pb.MessageType) []MessageHandler

GetMessageHandlers gets all handlers of a message type

type Node

type Node struct {
	*pbnode.Node
	*pb.NodeData

	StartTime time.Time

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNode

func NewNode(nnetNode *pbnode.Node, nodeData *pb.NodeData) (*Node, error)

func (*Node) GetChordID

func (n *Node) GetChordID() []byte

func (*Node) GetHostname

func (n *Node) GetHostname() string

func (*Node) GetID

func (n *Node) GetID() string

func (*Node) GetMinVerifiableHeight

func (n *Node) GetMinVerifiableHeight() uint32

func (*Node) GetPubKey

func (n *Node) GetPubKey() []byte

func (*Node) GetSyncState

func (n *Node) GetSyncState() pb.SyncState

func (*Node) MarshalJSON

func (n *Node) MarshalJSON() ([]byte, error)

func (*Node) SetMinVerifiableHeight

func (n *Node) SetMinVerifiableHeight(height uint32)

func (*Node) SetSyncState

func (n *Node) SetSyncState(s pb.SyncState) bool

type RemoteMessage

type RemoteMessage struct {
	Sender  *Node
	Message []byte
}

RemoteMessage is the message received from remote nodes

type RemoteNode

type RemoteNode struct {
	*Node

	NnetNode *nnetnode.RemoteNode

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRemoteNode

func NewRemoteNode(localNode ILocalNode, nnetNode *nnetnode.RemoteNode) (*RemoteNode, error)

func (*RemoteNode) CloseConn

func (remoteNode *RemoteNode) CloseConn()

func (*RemoteNode) DecryptMessage added in v2.2.0

func (remoteNode *RemoteNode) DecryptMessage(message []byte) ([]byte, bool, error)

func (*RemoteNode) EncryptMessage added in v2.2.0

func (remoteNode *RemoteNode) EncryptMessage(message []byte) []byte

func (*RemoteNode) GetHeight

func (remoteNode *RemoteNode) GetHeight() uint32

func (*RemoteNode) GetLastUpdateTime

func (remoteNode *RemoteNode) GetLastUpdateTime() time.Time

func (*RemoteNode) IsStopped added in v2.1.7

func (remoteNode *RemoteNode) IsStopped() bool

func (*RemoteNode) MarshalJSON

func (remoteNode *RemoteNode) MarshalJSON() ([]byte, error)

func (*RemoteNode) SendBytesAsync

func (remoteNode *RemoteNode) SendBytesAsync(buf []byte) error

func (*RemoteNode) SendBytesReply

func (remoteNode *RemoteNode) SendBytesReply(replyToID, buf []byte) error

func (*RemoteNode) SendBytesSync

func (remoteNode *RemoteNode) SendBytesSync(buf []byte) ([]byte, error)

func (*RemoteNode) SendBytesSyncWithTimeout

func (remoteNode *RemoteNode) SendBytesSyncWithTimeout(buf []byte, replyTimeout time.Duration) ([]byte, error)

func (*RemoteNode) SetHeight

func (remoteNode *RemoteNode) SetHeight(height uint32)

func (*RemoteNode) SetLastUpdateTime

func (remoteNode *RemoteNode) SetLastUpdateTime(lastUpdateTime time.Time)

func (*RemoteNode) String

func (remoteNode *RemoteNode) String() string

Jump to

Keyboard shortcuts

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