peer

package
v0.0.0-...-e4696f9 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

package peer implements an object used to represent peers in the ipfs network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID mh.Multihash

ID is a byte slice representing the identity of a peer.

func DecodePrettyID

func DecodePrettyID(s string) ID

DecodePrettyID returns a b58-encoded string of the ID

func IDFromPubKey

func IDFromPubKey(pk ic.PubKey) (ID, error)

IDFromPubKey retrieves a Public Key from the peer given by pk

func (ID) Equal

func (id ID) Equal(other ID) bool

Equal is utililty function for comparing two peer ID's

func (ID) Pretty

func (id ID) Pretty() string

Pretty returns a b58-encoded string of the ID

func (ID) String

func (id ID) String() string

String is utililty function for printing out peer ID strings.

type Map

type Map map[u.Key]Peer

Map maps Key (string) : *peer (slices are not comparable).

type Peer

type Peer interface {

	// ID returns the peer's ID
	ID() ID

	// Key returns the ID as a Key (string) for maps.
	Key() u.Key

	// Addresses returns the peer's multiaddrs
	Addresses() []ma.Multiaddr

	// AddAddress adds the given Multiaddr address to Peer's addresses.
	// returns whether this was a newly added address.
	AddAddress(a ma.Multiaddr) bool

	// NetAddress returns the first Multiaddr found for a given network.
	NetAddress(n string) ma.Multiaddr

	// Priv/PubKey returns the peer's Private Key
	PrivKey() ic.PrivKey
	PubKey() ic.PubKey

	// LoadAndVerifyKeyPair unmarshalls, loads a private/public key pair.
	// Error if (a) unmarshalling fails, or (b) pubkey does not match id.
	LoadAndVerifyKeyPair(marshalled []byte) error
	VerifyAndSetPrivKey(sk ic.PrivKey) error
	VerifyAndSetPubKey(pk ic.PubKey) error

	// Get/SetLatency manipulate the current latency measurement.
	GetLatency() (out time.Duration)
	SetLatency(laten time.Duration)

	// Get/SetType indicate whether this is a local or remote peer
	GetType() Type
	SetType(Type)

	//Get/Set Agent and Protocol Versions
	GetVersions() (agent, protocol string)
	SetVersions(agent, protocol string)
	// Update with the data of another peer instance
	Update(Peer) error

	Loggable() map[string]interface{}
}

Peer represents the identity information of an IPFS Node, including ID, and relevant Addresses.

func WithID

func WithID(id ID) Peer

WithID constructs a peer with given ID.

func WithIDString

func WithIDString(id string) Peer

WithIDString constructs a peer with given ID (string).

func WithKeyPair

func WithKeyPair(sk ic.PrivKey, pk ic.PubKey) (Peer, error)

WithKeyPair returns a Peer object with given keys.

type Peerstore

type Peerstore interface {
	Get(ID) (Peer, error)
	Add(Peer) (Peer, error)
	Delete(ID) error
	All() (*Map, error)
}

Peerstore provides a threadsafe collection for peers.

func NewPeerstore

func NewPeerstore() Peerstore

NewPeerstore creates a threadsafe collection of peers.

type Type

type Type uint8
const (
	// Unspecified indicates peer was created without specifying Type
	Unspecified Type = iota
	Local
	Remote
)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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