peer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MissingName is the placeholder for a missing peer name.
	MissingName = "MISING_NAME"
)

Variables

This section is empty.

Functions

func AssertPeersEqual

func AssertPeersEqual(t *testing.T, sp *storage.Peer, p Peer)

AssertPeersEqual checks that the stored and non-stored representations of a peer are equal.

func FromAddress

func FromAddress(id id.ID, name string, addr *net.TCPAddr) *api.PeerAddress

FromAddress creates an api.PeerAddress from a net.TCPAddr.

func NewTestPublicAddr

func NewTestPublicAddr(idx int) *net.TCPAddr

NewTestPublicAddr creates a new net.TCPAddr given a particular peer index.

func NewTestStoredPeer

func NewTestStoredPeer(rng *rand.Rand, idx int) *storage.Peer

NewTestStoredPeer generates a new storage.Peer suitable for testing using a random number generator for the ID and an index.

func ToAPIs

func ToAPIs(peers []Peer) []*api.PeerAddress

ToAPIs converts a list of peers into a list of api.PeerAddress objects.

func ToAddress

func ToAddress(addr *api.PeerAddress) *net.TCPAddr

ToAddress creates a net.TCPAddr from an api.PeerAddress.

Types

type Fromer

type Fromer interface {
	// FromAPI creates a new Peer instance.
	FromAPI(address *api.PeerAddress) Peer
}

Fromer creates new Peer instances from api.PeerAddresses.

func NewFromer

func NewFromer() Fromer

NewFromer returns a new Fromer instance.

type Peer

type Peer interface {
	// ID returns the peer ID.
	ID() id.ID

	// Address returns the public address of the peer.
	Address() *net.TCPAddr

	// Merge merges another peer into the existing peer. If there is any conflicting information
	// between the two, the merge returns an error.
	Merge(other Peer) error

	// ToStored returns a storage.Peer version of the peer.
	ToStored() *storage.Peer

	// ToAPI returns an api.PeerAddress version of the peer.
	ToAPI() *api.PeerAddress
}

Peer represents a peer in the network.

func FromStored

func FromStored(stored *storage.Peer) Peer

FromStored creates a new peer.Peer instance from a storage.Peer instance.

func New

func New(id id.ID, name string, address *net.TCPAddr) Peer

New creates a new Peer instance with empty response stats.

func NewStub

func NewStub(id id.ID, name string) Peer

NewStub creates a new peer without a name or connector.

func NewTestPeer

func NewTestPeer(rng *rand.Rand, idx int) Peer

NewTestPeer generates a new peer suitable for testing using a random number generator for the ID and an index.

func NewTestPeers

func NewTestPeers(rng *rand.Rand, n int) []Peer

NewTestPeers generates n new peers suitable for testing use with random IDs and incrementing values of other fields.

Jump to

Keyboard shortcuts

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