node

package
v0.8.1-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashCacheExpiration      = 3600 * time.Second
	HashCacheCleanupInterval = 60 * time.Second
)

Variables

This section is empty.

Functions

func NewGetBlockHeadersMessage

func NewGetBlockHeadersMessage(startHeight, endHeight uint32) (*pb.UnsignedMessage, error)

NewGetBlockHeadersMessage creates a GET_BLOCK_HEADERS message

func NewGetBlockHeadersReply

func NewGetBlockHeadersReply(headers []*ledger.Header) (*pb.UnsignedMessage, error)

NewGetBlockHeadersReply creates a GET_BLOCK_HEADERS_REPLY message in respond to GET_BLOCK_HEADERS message

func NewGetBlocksMessage

func NewGetBlocksMessage(startHeight, endHeight uint32) (*pb.UnsignedMessage, error)

NewGetBlocksMessage creates a GET_BLOCKS message

func NewGetBlocksReply

func NewGetBlocksReply(blocks []*ledger.Block) (*pb.UnsignedMessage, error)

NewGetBlocksReply creates a GET_BLOCKS_REPLY message in respond to GET_BLOCKS message

func NewHashCache

func NewHashCache() *hashCache

func NewRelayMessage

func NewRelayMessage(srcAddr string, destID, payload []byte, sigChain *por.SigChain, maxHoldingSeconds uint32) (*pb.UnsignedMessage, error)

NewRelayMessage creates a RELAY message

func NewTransactionsMessage

func NewTransactionsMessage(transactions []*transaction.Transaction) (*pb.UnsignedMessage, error)

NewTransactionsMessage creates a TRANSACTIONS message

Types

type ChordInfo

type ChordInfo struct {
	LocalNode    *LocalNode                     `json:"localNode"`
	Successors   []*ChordRemoteNodeInfo         `json:"successors"`
	Predecessors []*ChordRemoteNodeInfo         `json:"predecessors"`
	FingerTable  map[int][]*ChordRemoteNodeInfo `json:"fingerTable"`
}

type ChordRemoteNodeInfo

type ChordRemoteNodeInfo nnetnode.RemoteNode

func (*ChordRemoteNodeInfo) MarshalJSON

func (rn *ChordRemoteNodeInfo) MarshalJSON() ([]byte, error)

type LocalNode

type LocalNode struct {
	*Node

	*pool.TxnPool // transaction pool of local node

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLocalNode

func NewLocalNode(wallet vault.Wallet, nn *nnet.NNet) (*LocalNode, error)

func (LocalNode) AddMessageHandler

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

AddMessageHandler adds a message handler to a message type

func (*LocalNode) AddNbrNode

func (nm *LocalNode) AddNbrNode(remoteNode *RemoteNode) error

func (*LocalNode) BroadcastTransaction

func (localNode *LocalNode) BroadcastTransaction(txn *transaction.Transaction) error

BroadcastTransaction broadcast a transaction to the network using TRANSACTIONS message

func (*LocalNode) DelNbrNode

func (nm *LocalNode) DelNbrNode(id string)

func (LocalNode) ExistHash

func (hc LocalNode) ExistHash(hash common.Uint256) bool

func (*LocalNode) FindSuccessorAddrs

func (localNode *LocalNode) FindSuccessorAddrs(key []byte, numSucc int) ([]string, error)

func (*LocalNode) FindWsAddr

func (localNode *LocalNode) FindWsAddr(key []byte) (string, error)

func (*LocalNode) GetChordInfo

func (localNode *LocalNode) GetChordInfo() *ChordInfo

func (*LocalNode) GetConnectionCnt

func (nm *LocalNode) GetConnectionCnt() uint

func (*LocalNode) GetEvent

func (eq *LocalNode) GetEvent(eventName string) *events.Event

func (*LocalNode) GetHeight

func (localNode *LocalNode) GetHeight() uint32

func (LocalNode) GetMessageHandlers

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

GetMessageHandlers gets all handlers of a message type

func (*LocalNode) GetNbrNode

func (nm *LocalNode) GetNbrNode(id string) *RemoteNode

func (*LocalNode) GetNeighborHeights

func (nm *LocalNode) GetNeighborHeights() ([]uint32, uint)

func (*LocalNode) GetNeighborInfo

func (localNode *LocalNode) GetNeighborInfo() []*RemoteNode

func (*LocalNode) GetNeighbors

func (nm *LocalNode) GetNeighbors(filter func(*RemoteNode) bool) []*RemoteNode

func (*LocalNode) GetRelayMessageCount

func (localNode *LocalNode) GetRelayMessageCount() uint64

func (*LocalNode) GetTxnPool

func (localNode *LocalNode) GetTxnPool() *pool.TxnPool

func (*LocalNode) GetWsAddr

func (localNode *LocalNode) GetWsAddr() string

func (*LocalNode) IncrementRelayMessageCount

func (localNode *LocalNode) IncrementRelayMessageCount()

func (*LocalNode) MarshalJSON

func (localNode *LocalNode) MarshalJSON() ([]byte, error)

func (*LocalNode) ResetSyncing

func (localNode *LocalNode) ResetSyncing()

ResetSyncing resets syncOnce and allows for future block syncing

func (*LocalNode) SendRelayMessage

func (localNode *LocalNode) SendRelayMessage(srcAddr, destAddr string, payload, signature []byte, maxHoldingSeconds uint32) error

func (*LocalNode) SerializeMessage

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

func (*LocalNode) SetSyncState

func (localNode *LocalNode) SetSyncState(s pb.SyncState)

func (*LocalNode) Start

func (localNode *LocalNode) Start() error

func (*LocalNode) StartSyncing

func (localNode *LocalNode) StartSyncing(stopHash common.Uint256, stopHeight uint32, neighbors []*RemoteNode) (bool, error)

StartSyncing starts block syncing from current local ledger until it gets to block height stopHeight with block hash stopHash from given neighbors

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 Node

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

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNode

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

func (*Node) GetChordID

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

func (*Node) GetHostname

func (node *Node) GetHostname() string

func (*Node) GetID

func (node *Node) GetID() string

func (*Node) GetPubKey

func (node *Node) GetPubKey() *crypto.PubKey

func (*Node) GetSyncState

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

func (*Node) MarshalJSON

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

func (*Node) SetSyncState

func (node *Node) SetSyncState(s pb.SyncState)

type RelayService

type RelayService struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRelayService

func NewRelayService(wallet vault.Wallet, localNode *LocalNode) *RelayService

func (*RelayService) Start

func (rs *RelayService) Start() error

type RemoteMessage

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

RemoteMessage is the message received from remote nodes

type RemoteNode

type RemoteNode struct {
	*Node

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRemoteNode

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

func (*RemoteNode) CloseConn

func (remoteNode *RemoteNode) CloseConn()

func (*RemoteNode) GetBlockHeaders

func (remoteNode *RemoteNode) GetBlockHeaders(startHeight, endHeight uint32) ([]*ledger.Header, error)

GetBlockHeaders requests a range of consecutive block headers from a neighbor using GET_BLOCK_HEADERS message

func (*RemoteNode) GetBlocks

func (remoteNode *RemoteNode) GetBlocks(startHeight, endHeight uint32) ([]*ledger.Block, error)

GetBlocks requests a range of consecutive blocks from a neighbor using GET_BLOCKS message

func (*RemoteNode) GetHeight

func (remoteNode *RemoteNode) GetHeight() uint32

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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