peers

package
v0.0.0-...-437c9e2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONPeerSet

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

JSONPeerSet is used to provide peer persistence on disk in the form of a JSON file.

func NewJSONPeerSet

func NewJSONPeerSet(base string, isCurrent bool) *JSONPeerSet

NewJSONPeerSet creates a new JSONPeerSet.

func (*JSONPeerSet) PeerSet

func (j *JSONPeerSet) PeerSet() (*PeerSet, error)

PeerSet creates a PeerSet from the JSONPeerSet

func (*JSONPeerSet) Write

func (j *JSONPeerSet) Write(peers []*Peer) error

Write persists a PeerSet to a JSON file in path

type Peer

type Peer struct {
	NetAddr   string
	PubKeyHex string
	Moniker   string
	// contains filtered or unexported fields
}

Peer is a struct that holds Peer data

func ExcludePeer

func ExcludePeer(peers []*Peer, peer uint32) (int, []*Peer)

ExcludePeer is used to exclude a single peer from a list of peers.

func NewPeer

func NewPeer(pubKeyHex, netAddr, moniker string) *Peer

NewPeer is a factory method for creating a new Peer instance

func (*Peer) ID

func (p *Peer) ID() uint32

ID returns an ID for the peer, calculating a hash is one is not available XXX Not very nice

func (*Peer) Marshal

func (p *Peer) Marshal() ([]byte, error)

Marshal marshals the json representation of the peer json encoding excludes the ID field

func (*Peer) PubKeyBytes

func (p *Peer) PubKeyBytes() []byte

PubKeyBytes converts hex string representation of the public key and returns a byte array

func (*Peer) PubKeyString

func (p *Peer) PubKeyString() string

PubKeyString returns the upper-case version of PubKeyHex. It is used for indexing in maps with string keys. XXX do something nicer

func (*Peer) Unmarshal

func (p *Peer) Unmarshal(data []byte) error

Unmarshal generates a JSON representation of the peer

type PeerSet

type PeerSet struct {
	Peers    []*Peer          `json:"peers"`
	ByPubKey map[string]*Peer `json:"-"`
	ByID     map[uint32]*Peer `json:"-"`
	// contains filtered or unexported fields
}

PeerSet is a set of Peers forming a consensus network

func NewPeerSet

func NewPeerSet(peers []*Peer) *PeerSet

NewPeerSet creates a new PeerSet from a list of Peers

func NewPeerSetFromPeerSliceBytes

func NewPeerSetFromPeerSliceBytes(peerSliceBytes []byte) (*PeerSet, error)

NewPeerSetFromPeerSliceBytes creates a new PeerSet from a peerSlice in Bytes format

func (*PeerSet) Hash

func (peerSet *PeerSet) Hash() ([]byte, error)

Hash uniquely identifies a PeerSet. It is computed by sorting the peers set by ID, and hashing (SHA256) their public keys together, one by one.

func (*PeerSet) Hex

func (peerSet *PeerSet) Hex() string

Hex is the hexadecimal representation of Hash

func (*PeerSet) IDs

func (peerSet *PeerSet) IDs() []uint32

IDs returns the PeerSet's slice of IDs

func (*PeerSet) Len

func (peerSet *PeerSet) Len() int

Len returns the number of Peers in the PeerSet

func (*PeerSet) Marshal

func (peerSet *PeerSet) Marshal() ([]byte, error)

Marshal marshals the peerset

func (*PeerSet) PubKeys

func (peerSet *PeerSet) PubKeys() []string

PubKeys returns the PeerSet's slice of public keys

func (*PeerSet) SuperMajority

func (peerSet *PeerSet) SuperMajority() int

SuperMajority return the number of peers that forms a strong majortiy (+2/3) in the PeerSet

func (*PeerSet) TrustCount

func (peerSet *PeerSet) TrustCount() int

TrustCount calculates the Trust Count for a peerset

func (*PeerSet) WithNewPeer

func (peerSet *PeerSet) WithNewPeer(peer *Peer) *PeerSet

WithNewPeer returns a new PeerSet with a list of peers including the new one.

func (*PeerSet) WithRemovedPeer

func (peerSet *PeerSet) WithRemovedPeer(peer *Peer) *PeerSet

WithRemovedPeer returns a new PeerSet with a list of peers excluding the provided one

Jump to

Keyboard shortcuts

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