peer

package
v2.0.0-...-59fec89 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: Apache-2.0, BSD-2-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedsPeeringService = errors.New("needs peering service")
)

Errors in the peer package.

Functions

func RecoverKeyFromSignedData

func RecoverKeyFromSignedData(m SignedData) (ed25519.PublicKey, error)

RecoverKeyFromSignedData validates and returns the key that was used to sign the data.

Types

type DB

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

DB is the peer database, storing previously seen peers and any collected properties of them.

func NewDB

func NewDB(store kvstore.KVStore) (*DB, error)

NewDB creates a new peer database.

func (*DB) Close

func (db *DB) Close()

Close closes the peer database.

func (*DB) LastPing

func (db *DB) LastPing(id identity.ID, ip net.IP) time.Time

LastPing returns that property for the given peer ID and address.

func (*DB) LastPong

func (db *DB) LastPong(id identity.ID, ip net.IP) time.Time

LastPong returns that property for the given peer ID and address.

func (*DB) LocalPrivateKey

func (db *DB) LocalPrivateKey() (privateKey ed25519.PrivateKey, err error)

LocalPrivateKey returns the private key stored in the database or creates a new one.

func (*DB) Peer

func (db *DB) Peer(id identity.ID) (*Peer, error)

Peer retrieves a peer from the database.

func (*DB) SeedPeers

func (db *DB) SeedPeers() []*Peer

SeedPeers retrieves random nodes to be used as potential bootstrap peers.

func (*DB) UpdateLastPing

func (db *DB) UpdateLastPing(id identity.ID, ip net.IP, t time.Time) error

UpdateLastPing updates that property for the given peer ID and address.

func (*DB) UpdateLastPong

func (db *DB) UpdateLastPong(id identity.ID, ip net.IP, t time.Time) error

UpdateLastPong updates that property for the given peer ID and address.

func (*DB) UpdateLocalPrivateKey

func (db *DB) UpdateLocalPrivateKey(key ed25519.PrivateKey) error

UpdateLocalPrivateKey stores the provided key in the database.

func (*DB) UpdatePeer

func (db *DB) UpdatePeer(p *Peer) error

UpdatePeer updates a peer in the database.

type Local

type Local struct {
	*Peer
	// contains filtered or unexported fields
}

Local defines the struct of a local peer

func NewLocal

func NewLocal(ip net.IP, serviceRecord *service.Record, db *DB, seed ...[]byte) (*Local, error)

NewLocal creates a new local peer linked to the provided store. If an optional seed is provided, the seed is used to generate the private key. Without a seed, the provided key is loaded from the provided database and generated if not stored there.

func (*Local) Database

func (l *Local) Database() *DB

Database returns the node database associated with the local peer.

func (*Local) GetPrivateSalt

func (l *Local) GetPrivateSalt() *salt.Salt

GetPrivateSalt returns the private salt

func (*Local) GetPublicSalt

func (l *Local) GetPublicSalt() *salt.Salt

GetPublicSalt returns the public salt

func (*Local) LocalIdentity

func (l *Local) LocalIdentity() *identity.LocalIdentity

LocalIdentity returns the local identity

func (*Local) SetPrivateSalt

func (l *Local) SetPrivateSalt(salt *salt.Salt)

SetPrivateSalt sets the private salt

func (*Local) SetPublicSalt

func (l *Local) SetPublicSalt(salt *salt.Salt)

SetPublicSalt sets the public salt

func (*Local) Sign

func (l *Local) Sign(message []byte) ed25519.Signature

Sign signs a message using the node's LocalIdentity.

func (*Local) UpdateService

func (l *Local) UpdateService(key service.Key, network string, port int) error

UpdateService updates the endpoint address of the given local service.

type Peer

type Peer struct {
	*identity.Identity
	// contains filtered or unexported fields
}

Peer defines the immutable data of a peer.

func FromProto

func FromProto(in *pb.Peer) (*Peer, error)

FromProto decodes a given proto buffer Peer message (in) and returns the corresponding Peer.

func NewPeer

func NewPeer(id *identity.Identity, ip net.IP, services service.Service) *Peer

NewPeer creates a new unmodifiable peer.

func Unmarshal

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

Unmarshal de-serializes a given slice of bytes (data) into a Peer.

func (*Peer) Address

func (p *Peer) Address() *net.UDPAddr

Address returns the autopeering address of a peer.

func (*Peer) IP

func (p *Peer) IP() net.IP

IP returns the public IP of the peer.

func (*Peer) Marshal

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

Marshal serializes a given Peer (p) into a slice of bytes.

func (*Peer) MarshalJSON

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

MarshalJSON serializes Peer into json data.

func (*Peer) Network

func (p *Peer) Network() string

Network returns the autopeering network of the peer.

func (*Peer) Services

func (p *Peer) Services() service.Service

Services returns the supported services of the peer.

func (*Peer) String

func (p *Peer) String() string

String returns a string representation of the peer.

func (*Peer) ToProto

func (p *Peer) ToProto() *pb.Peer

ToProto encodes a given peer into a proto buffer Peer message

func (*Peer) UnmarshalJSON

func (p *Peer) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes given json data into a Peer struct.

type PeerDistance

type PeerDistance struct {
	Remote   *Peer
	Distance uint32
}

PeerDistance defines the relative distance wrt a remote peer

func NewPeerDistance

func NewPeerDistance(anchorID, salt []byte, remote *Peer) PeerDistance

NewPeerDistance returns a new PeerDistance

func SortBySalt

func SortBySalt(anchor, salt []byte, remotePeers []*Peer) (result []PeerDistance)

SortBySalt returns a slice of PeerDistance given a list of remote peers

type PublicKey

type PublicKey ed25519.PublicKey

PublicKey is the type of Ed25519 public keys used for peers.

type SignedData

type SignedData interface {
	GetData() []byte
	GetPublicKey() []byte
	GetSignature() []byte
}

SignedData is an interface wrapper around data with key and signature.

Directories

Path Synopsis
Package peertest provides utilities for writing tests with the peer package.
Package peertest provides utilities for writing tests with the peer package.

Jump to

Keyboard shortcuts

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