network

package
v0.0.0-...-a6ba2ba Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlocksMessage

type BlocksMessage struct {
	Blocks []*core.Block
}

type DecodedMessage

type DecodedMessage struct {
	From net.Addr
	Data any
}

func DefaultRPCDecodeFunc

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

type GetBlocksMessage

type GetBlocksMessage struct {
	From uint32
	// If To is 0 the maximum blocks will be returned.
	To uint32
}

type GetStatusMessage

type GetStatusMessage struct{}

type LocalTransport

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

func NewLocalTransport

func NewLocalTransport(addr net.Addr) *LocalTransport

func (*LocalTransport) Addr

func (t *LocalTransport) Addr() net.Addr

func (*LocalTransport) Broadcast

func (t *LocalTransport) Broadcast(payload []byte) error

func (*LocalTransport) Connect

func (t *LocalTransport) Connect(tr Transport) error

func (*LocalTransport) Consume

func (t *LocalTransport) Consume() <-chan RPC

func (*LocalTransport) SendMessage

func (t *LocalTransport) SendMessage(to net.Addr, payload []byte) 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
	MessageTypeGetBlocks MessageType = 0x3
	MessageTypeStatus    MessageType = 0x4
	MessageTypeGetStatus MessageType = 0x5
	MessageTypeBlocks    MessageType = 0x6
)

type NetAddr

type NetAddr string

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 {
	ProcessMessage(*DecodedMessage) error
}

type Server

type Server struct {
	TCPTransport *TCPTransport

	ServerOpts
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ServerOpts) (*Server, error)

func (*Server) ProcessMessage

func (s *Server) ProcessMessage(msg *DecodedMessage) error

func (*Server) Start

func (s *Server) Start()

type ServerOpts

type ServerOpts struct {
	APIListenAddr string
	SeedNodes     []string
	ListenAddr    string
	TCPTransport  *TCPTransport
	ID            string
	Logger        log.Logger
	RPCDecodeFunc RPCDecodeFunc
	RPCProcessor  RPCProcessor
	BlockTime     time.Duration
	PrivateKey    *crypto.PrivateKey
}

type StatusMessage

type StatusMessage struct {
	// the id of the server
	ID            string
	Version       uint32
	CurrentHeight uint32
}

type TCPPeer

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

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 *core.Transaction)

func (*TxPool) ClearPending

func (p *TxPool) ClearPending()

func (*TxPool) Contains

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

func (*TxPool) Pending

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

Pending returns a slice of transactions that are in the pending pool

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 *core.Transaction)

func (*TxSortedMap) Clear

func (t *TxSortedMap) Clear()

func (*TxSortedMap) Contains

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

func (*TxSortedMap) Count

func (t *TxSortedMap) Count() int

func (*TxSortedMap) First

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

func (*TxSortedMap) Get

func (t *TxSortedMap) Get(h types.Hash) *core.Transaction

func (*TxSortedMap) Remove

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

Jump to

Keyboard shortcuts

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