peer

package
v0.0.0-...-d151d1d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const IDLength = 46

Variables

View Source
var (
	ErrNoPubKey    = errors.New("public key is not embedded in peer ID")
	ErrEmptyPeerID = errors.New("empty peer ID")
)

Functions

This section is empty.

Types

type ID

type ID string

ID represents the unique identity of a peer.

func IDFromPriKey

func IDFromPriKey(sk cc.PriKey) (ID, error)

IDFromPriKey returns the Peer ID corresponding to the secret key sk.

func IDFromPubKey

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

IDFromPubKey returns the Peer ID corresponding to the public key pk.

func (ID) ExtractPubKey

func (i ID) ExtractPubKey() (cc.PubKey, error)

ExtractPubKey attempts to extract the public key from an ID.

This method returns ErrNoPublicKey if the peer ID looks valid, but it can't extract the public key.

func (ID) MatchesPriKey

func (i ID) MatchesPriKey(sk cc.PriKey) bool

MatchesPriKey tests whether this ID was derived from the secret key sk.

func (ID) MatchesPubKey

func (i ID) MatchesPubKey(pk cc.PubKey) bool

MatchesPubKey tests whether this ID was derived from the public key pk.

func (ID) String

func (i ID) String() string

String converts the ID to a string.

func (ID) Validate

func (i ID) Validate() error

Validate checks if ID is empty or not.

func (ID) WeightCompare

func (i ID) WeightCompare(other ID) bool

WeightCompare compares the weight of our ID with another ID. It determines which peer should be saved when a conflict is found between two peers. The function returns true if the weight of our ID is higher than the other ID's weight.

type IDLoader

type IDLoader func([]*x509.Certificate) (ID, error)

IDLoader is a function can load the peer.ID from []*x509.Certificate exchanged during tls handshaking.

Jump to

Keyboard shortcuts

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