peer

package
v0.0.0-...-8b9b725 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT, MIT Imports: 8 Imported by: 317

README

go-libp2p-peer

standard-readme compliant GoDoc Coverage Status Build Status

PKI based identities for use in go-libp2p

Install

TODO

Usage

TODO

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Documentation

Overview

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

This file contains Protobuf and JSON serialization/deserialization methods for peer IDs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPeerID is an error for empty peer ID.
	ErrEmptyPeerID = errors.New("empty peer ID")
	// ErrNoPublicKey is an error for peer IDs that don't embed public keys
	ErrNoPublicKey = errors.New("public key is not embedded in peer ID")
)
View Source
var AdvancedEnableInlining = true

AdvancedEnableInlining enables automatically inlining keys shorter than 42 bytes into the peer ID (using the "identity" multihash function).

WARNING: This flag will likely be set to false in the future and eventually be removed in favor of using a hash function specified by the key itself. See: https://github.com/libp2p/specs/issues/138

DO NOT change this flag unless you know what you're doing.

This currently defaults to true for backwards compatibility but will likely be set to false by default when an upgrade path is determined.

Functions

func IDB58Encode

func IDB58Encode(id ID) string

IDB58Encode returns b58-encoded string

func IDHexEncode

func IDHexEncode(id ID) string

IDHexEncode returns hex-encoded string

Types

type ID

type ID string

ID is a libp2p peer identity.

func IDB58Decode

func IDB58Decode(s string) (ID, error)

IDB58Decode returns a b58-decoded Peer

func IDFromBytes

func IDFromBytes(b []byte) (ID, error)

IDFromBytes cast a string to ID type, and validate the id to make sure it is a multihash.

func IDFromPrivateKey

func IDFromPrivateKey(sk ic.PrivKey) (ID, error)

IDFromPrivateKey returns the Peer ID corresponding to sk

func IDFromPublicKey

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

IDFromPublicKey returns the Peer ID corresponding to pk

func IDFromString

func IDFromString(s string) (ID, error)

IDFromString cast a string to ID type, and validate the id to make sure it is a multihash.

func IDHexDecode

func IDHexDecode(s string) (ID, error)

IDHexDecode returns a hex-decoded Peer

func (ID) ExtractPublicKey

func (id ID) ExtractPublicKey() (ic.PubKey, error)

ExtractPublicKey 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) Loggable

func (id ID) Loggable() map[string]interface{}

Loggable returns a pretty peerID string in loggable JSON format

func (ID) Marshal

func (id ID) Marshal() ([]byte, error)

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

BinaryMarshal returns the byte representation of the peer ID.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

TextMarshal returns the text encoding of the ID.

func (ID) MarshalTo

func (id ID) MarshalTo(data []byte) (n int, err error)

func (ID) MatchesPrivateKey

func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool

MatchesPrivateKey tests whether this ID was derived from sk

func (ID) MatchesPublicKey

func (id ID) MatchesPublicKey(pk ic.PubKey) bool

MatchesPublicKey tests whether this ID was derived from pk

func (ID) Pretty

func (id ID) Pretty() string

Pretty returns a b58-encoded string of the ID

func (ID) Size

func (id ID) Size() int

Implements Gogo's proto.Sizer, but we omit the compile-time assertion to avoid introducing a hard dependency on gogo.

func (ID) String

func (id ID) String() string

String prints out the peer.

TODO(brian): ensure correctness at ID generation and enforce this by only exposing functions that generate IDs safely. Then any peer.ID type found in the codebase is known to be correct.

func (*ID) Unmarshal

func (id *ID) Unmarshal(data []byte) (err error)

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

BinaryUnmarshal sets the ID from its binary representation.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) (err error)

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(data []byte) error

TextUnmarshal restores the ID from its text encoding.

func (ID) Validate

func (id ID) Validate() error

Validate check if ID is empty or not

type IDSlice

type IDSlice []ID

IDSlice for sorting peers

func (IDSlice) Len

func (es IDSlice) Len() int

func (IDSlice) Less

func (es IDSlice) Less(i, j int) bool

func (IDSlice) Swap

func (es IDSlice) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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