node

package
v0.0.0-...-745f595 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package node provides a node implementation that can participate in the Nano network.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxPeers   = errors.New("max amount of peers reached")
	ErrPeerExists = errors.New("this peer already exists in the list")
)
View Source
var (
	DefaultOptions = Options{
		Network:      proto.NetworkLive,
		Address:      ":7075",
		EnableIPv6:   false,
		EnableVoting: true,
		MaxPeers:     15,
	}
)

Functions

func Sync

func Sync(syncer Syncer, p *proto.Proto, peer *Peer) error

Types

type BulkPullBlocksPusher

type BulkPullBlocksPusher struct {
}

type BulkPullBlocksSyncer

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

func (*BulkPullBlocksSyncer) Flush

func (s *BulkPullBlocksSyncer) Flush()

Flush implements the Syncer interface.

func (*BulkPullBlocksSyncer) ReadNext

func (s *BulkPullBlocksSyncer) ReadNext(r io.Reader) (bool, error)

ReadNext implements the Syncer interface.

func (*BulkPullBlocksSyncer) WriteNext

func (s *BulkPullBlocksSyncer) WriteNext(p *proto.Proto, w io.Writer) (done bool, err error)

WriteNext implements the Syncer interface.

type BulkPullBlocksSyncerFunc

type BulkPullBlocksSyncerFunc func([]block.Block)

type BulkPullPusher

type BulkPullPusher struct {
}

type BulkPullSyncer

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

func NewBulkPullSyncer

func NewBulkPullSyncer(cb BulkPullSyncerFunc, frontiers map[nano.Address]block.Hash) *BulkPullSyncer

func (*BulkPullSyncer) Flush

func (s *BulkPullSyncer) Flush()

Flush implements the Syncer interface.

func (*BulkPullSyncer) ReadNext

func (s *BulkPullSyncer) ReadNext(r io.Reader) (bool, error)

ReadNext implements the Syncer interface.

func (*BulkPullSyncer) WriteNext

func (s *BulkPullSyncer) WriteNext(p *proto.Proto, w io.Writer) (done bool, err error)

WriteNext implements the Syncer interface.

type BulkPullSyncerFunc

type BulkPullSyncerFunc func([]block.Block)

type FrontierPusher

type FrontierPusher struct {
}

type FrontierSyncer

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

func NewFrontierSyncer

func NewFrontierSyncer(cb FrontierSyncerFunc) *FrontierSyncer

func (*FrontierSyncer) Flush

func (s *FrontierSyncer) Flush()

Flush implements the Syncer interface.

func (*FrontierSyncer) ReadNext

func (s *FrontierSyncer) ReadNext(r io.Reader) (bool, error)

ReadNext implements the Syncer interface.

func (*FrontierSyncer) WriteNext

func (s *FrontierSyncer) WriteNext(p *proto.Proto, w io.Writer) (done bool, err error)

WriteNext implements the Syncer interface.

type FrontierSyncerFunc

type FrontierSyncerFunc func(*block.Frontier)

type Node

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

func New

func New(ledger *store.Ledger, options Options) (*Node, error)

func (*Node) Publish

func (n *Node) Publish(blk block.Block) error

func (*Node) Run

func (n *Node) Run() error

func (*Node) Stop

func (n *Node) Stop() error

type Options

type Options struct {
	Network      proto.Network
	Address      string
	EnableIPv6   bool
	EnableVoting bool
	MaxPeers     int
	Peers        []string
}

type Peer

type Peer struct {
	Addr *net.UDPAddr
	// contains filtered or unexported fields
}

Peer represents a Nano peer.

func (*Peer) Dead

func (p *Peer) Dead() bool

Dead reports whether this peer should be considered dead and be removed from the peer list.

func (*Peer) Ping

func (p *Peer) Ping(fn func() error) error

Ping will call the given function if the peer needs to be pinged. If fn returns nil, the last ping time is reset.

func (*Peer) Pong

func (p *Peer) Pong()

Pong resets the pong timeout for this peer. It should be called when we've received a keep alive packet from this peer.

func (*Peer) Stale

func (p *Peer) Stale() bool

Stale reports whether it's been a while since we've received a keep alive packet from this peer.

type PeerList

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

PeerList represents a list of peers.

func NewPeerList

func NewPeerList(max int) *PeerList

NewPeerList creates a new peer list with the given maximum capacity.

func (*PeerList) Add

func (l *PeerList) Add(addr *net.UDPAddr) (*Peer, error)

Add creates a new peer instance with the given address, adds it to the internal peer list and returns it.

func (*PeerList) Full

func (l *PeerList) Full() bool

Full reports whether the internal peer list has reached its maximum capacity.

func (*PeerList) Get

func (l *PeerList) Get(addr *net.UDPAddr) *Peer

Get retrieves a peer with the given address. If no such peer exists, nil is returned.

func (*PeerList) Len

func (l *PeerList) Len() int

Len returns the length of the internal peer list.

func (*PeerList) Peers

func (l *PeerList) Peers() []*Peer

Peers returns a copy of the internal peer list.

func (*PeerList) Pick

func (l *PeerList) Pick() ([]*Peer, error)

Pick returns 8 random peers from the internal peer list. This function is usually used to populate a KeepAlivePacket.

func (*PeerList) Random

func (l *PeerList) Random() (*Peer, error)

Random picks one random peer from the internal peer list and returns it.

func (*PeerList) Remove

func (l *PeerList) Remove(peer *Peer)

Remove removes the given peer from the list.

type Pusher

type Pusher interface {
}

type Syncer

type Syncer interface {
	// Flush flushes all items in the cache through the registered callback.
	Flush()
	// ReadNext reads the next packet from the given reader, parses it and adds
	// the item to the cache.
	ReadNext(r io.Reader) (done bool, err error)
	// WriteNext writes the next packet to the given reader. If no packets need
	// to be sent, 'done' is set to true.
	WriteNext(p *proto.Proto, w io.Writer) (done bool, err error)
}

Directories

Path Synopsis
Package proto provides an implementation of the Nano network protocol.
Package proto provides an implementation of the Nano network protocol.

Jump to

Keyboard shortcuts

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