node

package
v0.0.0-...-e85cc61 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHashRequestMessage

type BlockHashRequestMessage struct {
	Height int32
}

type BlockHashResponseMessage

type BlockHashResponseMessage struct {
	Hash          common.Hash
	CurrentHeight int32
}

type BlockRequestMessage

type BlockRequestMessage struct {
	Height int32
}

type BlockResponseMessage

type BlockResponseMessage struct {
	Block *types.Block
}

type ChainInfoRequestMessage

type ChainInfoRequestMessage struct {
}

type ChainInfoResponseMessage

type ChainInfoResponseMessage struct {
	To            string
	Version       uint32
	CurrentHeight int32
}

type DecodedMessage

type DecodedMessage struct {
	From net.Addr
	Data any
}

func DecodeRPCDefaultFunc

func DecodeRPCDefaultFunc(rpc RPC) (*DecodedMessage, error)

type Message

type Message struct {
	Header MessageType
	Data   []byte
}

func NewMessage

func NewMessage(t MessageType, data []byte) *Message

func (*Message) Bytes

func (msg *Message) Bytes() []byte

type MessageType

type MessageType byte
const (
	MessageTypeTx                MessageType = 0x1
	MessageTypeBlock             MessageType = 0x2
	MessageTypeChainInfoResponse MessageType = 0x3
	MessageTypeChainInfoRequest  MessageType = 0x4
	MessageTypeBlockRequest      MessageType = 0x5
	MessageTypeBlockResponse     MessageType = 0x6
	MessageTypeBlockHashRequest  MessageType = 0x7
	MessageTypeBlockHashResponse MessageType = 0x8
)

type NetAddr

type NetAddr string

type Node

type Node struct {
	TCPTransport *TCPTransport

	NodeOpts
	// contains filtered or unexported fields
}

func NewNode

func NewNode(opts NodeOpts) (*Node, error)

func (*Node) HandleMessage

func (n *Node) HandleMessage(msg *DecodedMessage) error

func (*Node) Start

func (n *Node) Start()

type NodeOpts

type NodeOpts struct {
	APIListenAddr string
	SeedNodes     []string
	ListenAddr    string
	TCPTransport  *TCPTransport
	Name          string
	Logger        log.Logger
	RPCDecodeFunc RPCDecodeFunc
	RPCProcessor  RPCProcessor
	BlockTime     time.Duration
	PrivateKey    *types.PrivateKey
}

type RPC

type RPC struct {
	From    net.Addr //string
	Payload io.Reader
}

type RPCDecodeFunc

type RPCDecodeFunc func(RPC) (*DecodedMessage, error)

type RPCProcessor

type RPCProcessor interface {
	HandleMessage(*DecodedMessage) error
}

type TCPPeer

type TCPPeer struct {
	Outgoing bool
	// contains filtered or unexported fields
}

func (*TCPPeer) Close

func (p *TCPPeer) Close() error

func (*TCPPeer) Send

func (p *TCPPeer) Send(b []byte) error

type TCPTransport

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

func NewTCPTransport

func NewTCPTransport(addr string, peerCh chan *TCPPeer) *TCPTransport

func (*TCPTransport) Start

func (t *TCPTransport) Start() error

type Transport

type Transport interface {
	Consume() <-chan RPC
	Connect(Transport) error
	SendMessage(net.Addr, []byte) error
	Broadcast([]byte) error
	Addr() net.Addr
}

type TxPool

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

func NewTxPool

func NewTxPool(maxLength int) *TxPool

func (*TxPool) Add

func (p *TxPool) Add(tx *types.Transaction, chain *core.Blockchain) error

func (*TxPool) ClearPending

func (p *TxPool) ClearPending()

func (*TxPool) Contains

func (p *TxPool) Contains(hash common.Hash) bool

func (*TxPool) Pending

func (p *TxPool) Pending() []*types.Transaction

func (*TxPool) PendingCount

func (p *TxPool) PendingCount() int

type TxSortedMap

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

func NewTxSortedMap

func NewTxSortedMap() *TxSortedMap

func (*TxSortedMap) Add

func (t *TxSortedMap) Add(tx *types.Transaction)

func (*TxSortedMap) Clear

func (t *TxSortedMap) Clear()

func (*TxSortedMap) Contains

func (t *TxSortedMap) Contains(h common.Hash) bool

func (*TxSortedMap) Count

func (t *TxSortedMap) Count() int

func (*TxSortedMap) First

func (t *TxSortedMap) First() *types.Transaction

func (*TxSortedMap) Get

func (*TxSortedMap) Remove

func (t *TxSortedMap) Remove(h common.Hash)

Jump to

Keyboard shortcuts

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