posnode

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FakeClient

func FakeClient(host string) grpc.DialOption

FakeClient returns dialer for fake network.

func IDsToWire

func IDsToWire(ids []hash.Peer) *api.PeerIDs

IDsToWire converts to protobuf message.

func PeersHeightsDiff

func PeersHeightsDiff(all, excepts map[string]uint64) (res map[string]uint64)

PeersHeightsDiff returns all heights excluding excepts.

func WireToIDs

func WireToIDs(w *api.PeerIDs) []hash.Peer

WireToIDs converts from protobuf message.

Types

type Config

type Config struct {
	EventParentsCount int // max count of event's parents (includes self-parent)
	Port              int // default service port

	GossipThreads    int           // count of gossiping goroutines
	EmitInterval     time.Duration // event emission interval
	DiscoveryTimeout time.Duration // how often discovery should try to request

	ConnectTimeout time.Duration // how long dialer will for connection to be established
	ClientTimeout  time.Duration // how long will gRPC client will wait for response

	TopPeersCount int // peers hot cache size
}

Config is a set of nodes params.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default config.

type Consensus

type Consensus interface {
	// PushEvent takes event for processing.
	PushEvent(hash.Event)
	// StakeOf returns stake of peer.
	StakeOf(hash.Peer) uint64
	// GetGenesisHash returns hash of genesis poset works with.
	GetGenesisHash() hash.Hash
}

Consensus is a consensus interface.

type Node

type Node struct {
	ID hash.Peer

	logger.Instance
	// contains filtered or unexported fields
}

Node is a Lachesis node implementation.

func New

func New(host string, key *common.PrivateKey, s *Store, c Consensus, conf *Config, listen network.ListenFunc, opts ...grpc.DialOption) *Node

New creates node. It does not start any process.

func (*Node) AddBuiltInPeers

func (n *Node) AddBuiltInPeers(hosts ...string)

AddBuiltInPeers sets hosts for futher peer discovery.

func (*Node) AddExternalTxn

func (n *Node) AddExternalTxn(tx []byte)

AddExternalTxn takes external transaction for new event.

func (*Node) AddInternalTxn

func (n *Node) AddInternalTxn(tx inter.InternalTransaction) (hash.Transaction, error)

AddInternalTxn takes internal transaction for new event.

func (*Node) AsPeer

func (n *Node) AsPeer() *Peer

AsPeer returns nodes peer info.

func (*Node) AskPeerInfo

func (n *Node) AskPeerInfo(host string, id *hash.Peer)

AskPeerInfo gets peer info (network address, public key, etc).

func (*Node) CheckPeerIsKnown

func (n *Node) CheckPeerIsKnown(host string, id *hash.Peer)

CheckPeerIsKnown queues peer checking for a late.

func (*Node) Clean

func (cc *Node) Clean()

func (*Node) ConnectFail

func (n *Node) ConnectFail(p *Peer, err error)

ConnectFail counts unsuccessful connections to peer.

func (*Node) ConnectOK

func (n *Node) ConnectOK(p *Peer)

ConnectOK counts successful connections to peer.

func (*Node) ConnectTo

func (n *Node) ConnectTo(peer *Peer) (client api.NodeClient, free func(), fail func(error), err error)

ConnectTo connects to other node service.

func (*Node) Del

func (pp *Node) Del(e hash.Event)

Del removes whole event tree.

func (*Node) EmitEvent

func (n *Node) EmitEvent() *inter.Event

EmitEvent takes all transactions from buffer builds event, connects it with given amount of parents, sign and put it into the storage. It returns emmited event for test purpose.

func (*Node) EventOf

func (n *Node) EventOf(peer hash.Peer, i uint64) *inter.Event

EventOf returns i-th event of peer.

func (*Node) FreePeer

func (n *Node) FreePeer(p *Peer)

FreePeer marks peer as not busy.

func (*Node) Get

func (cc *Node) Get(addr string) (*connection, error)

func (*Node) GetEvent

func (n *Node) GetEvent(ctx context.Context, req *api.EventRequest) (*wire.Event, error)

GetEvent returns requested event.

func (*Node) GetID

func (n *Node) GetID() hash.Peer

GetID returns node id.

func (*Node) GetPeerInfo

func (n *Node) GetPeerInfo(ctx context.Context, req *api.PeerRequest) (*api.PeerInfo, error)

GetPeerInfo returns requested peer info.

func (*Node) Host

func (n *Node) Host() string

Host returns host.

func (*Node) LastEventOf

func (n *Node) LastEventOf(peer hash.Peer) *inter.Event

LastEventOf returns last event of peer.

func (*Node) NetAddrOf

func (n *Node) NetAddrOf(host string) string

NetAddrOf makes listen address from host and configured port.

func (*Node) NextBuiltInPeer

func (n *Node) NextBuiltInPeer() (host string)

NextBuiltInPeer returns one of builtin hosts.

func (*Node) NextForGossip

func (n *Node) NextForGossip() *Peer

NextForGossip returns the best candidate to gossip with and marks it as busy. You should call FreePeer() to mark candidate as not busy.

func (*Node) PeerReadyForReq

func (n *Node) PeerReadyForReq(host string) bool

PeerReadyForReq returns false if peer is not ready for request.

func (*Node) PeerUnknown

func (n *Node) PeerUnknown(id *hash.Peer) bool

PeerUnknown returns true if peer should be discovered.

func (*Node) PubKey

func (n *Node) PubKey() *common.PublicKey

PubKey returns public key.

func (*Node) Release

func (cc *Node) Release(c *connection, count bool, err error)

func (*Node) Snapshot

func (pp *Node) Snapshot() []hash.Peer

func (*Node) Start

func (n *Node) Start()

Start starts all node services.

func (*Node) StartDiscovery

func (n *Node) StartDiscovery()

StartDiscovery starts single thread network discovery. If there are no tasks for the discovery of unknown peers, after idle time will try to discover one of builtin peers.

func (*Node) StartEventEmission

func (n *Node) StartEventEmission()

StartEventEmission starts event emission.

func (*Node) StartGossip

func (n *Node) StartGossip(threads int)

StartGossip starts gossiping.

func (*Node) StartService

func (n *Node) StartService()

StartService starts node service.

func (*Node) Stop

func (n *Node) Stop()

Stop stops all node services.

func (*Node) StopDiscovery

func (n *Node) StopDiscovery()

StopDiscovery stops network discovery.

func (*Node) StopEventEmission

func (n *Node) StopEventEmission()

StopEventEmission stops event emission.

func (*Node) StopGossip

func (n *Node) StopGossip()

StopGossip stops gossiping.

func (*Node) StopService

func (n *Node) StopService()

StopService stops node service.

func (*Node) Sum

func (pp *Node) Sum(e hash.Event) uint64

Sum returns sum of parent values.

func (*Node) SyncEvents

func (n *Node) SyncEvents(ctx context.Context, req *api.KnownEvents) (*api.KnownEvents, error)

SyncEvents returns their known event heights excluding heights from request.

type Peer

type Peer struct {
	ID     hash.Peer
	PubKey *common.PublicKey
	Host   string
}

Peer is a representation of other node.

func WireToPeer

func WireToPeer(w *api.PeerInfo) *Peer

WireToPeer converts from protobuf message.

func (*Peer) ToWire

func (p *Peer) ToWire() *api.PeerInfo

ToWire converts to protobuf message.

type Store

type Store struct {
	logger.Instance
	// contains filtered or unexported fields
}

Store is a node persistent storage working over physical key-value database.

func NewMemStore

func NewMemStore() *Store

NewMemStore creates store over memory map.

func NewStore

func NewStore(db kvdb.Database) *Store

NewStore creates store over key-value db.

func (*Store) BootstrapPeers

func (s *Store) BootstrapPeers(peers ...*Peer)

BootstrapPeers stores peer list.

func (*Store) Close

func (s *Store) Close()

Close leaves underlying database.

func (*Store) GetEvent

func (s *Store) GetEvent(h hash.Event) *inter.Event

GetEvent returns stored event.

func (*Store) GetEventHash

func (s *Store) GetEventHash(creator hash.Peer, index uint64) *hash.Event

GetEventHash returns stored event hash.

func (*Store) GetPeer

func (s *Store) GetPeer(id hash.Peer) *Peer

GetPeer returns stored peer.

func (*Store) GetPeerHeight

func (s *Store) GetPeerHeight(id hash.Peer) uint64

GetPeerHeight returns last event index of peer.

func (*Store) GetTopPeers

func (s *Store) GetTopPeers() []hash.Peer

GetTopPeers returns peers.top.

func (*Store) GetWireEvent

func (s *Store) GetWireEvent(h hash.Event) *wire.Event

GetWireEvent returns stored event. Result is a ready gRPC message.

func (*Store) GetWirePeer

func (s *Store) GetWirePeer(id hash.Peer) *api.PeerInfo

GetWirePeer returns stored peer info. Result is a ready gRPC message.

func (*Store) HasEvent

func (s *Store) HasEvent(h hash.Event) bool

HasEvent returns true if event exists.

func (*Store) SetEvent

func (s *Store) SetEvent(e *inter.Event)

SetEvent stores event.

func (*Store) SetEventHash

func (s *Store) SetEventHash(creator hash.Peer, index uint64, hash hash.Event)

SetEventHash stores hash.

func (*Store) SetPeer

func (s *Store) SetPeer(peer *Peer)

SetPeer stores peer.

func (*Store) SetPeerHeight

func (s *Store) SetPeerHeight(id hash.Peer, height uint64)

SetPeerHeight stores last event index of peer.

func (*Store) SetTopPeers

func (s *Store) SetTopPeers(ids []hash.Peer)

SetTopPeers stores peers.top.

func (*Store) SetWirePeer

func (s *Store) SetWirePeer(id hash.Peer, info *api.PeerInfo)

SetWirePeer stores peer info.

Directories

Path Synopsis
Package api is a generated GoMock package.
Package api is a generated GoMock package.

Jump to

Keyboard shortcuts

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