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 ¶
- Variables
- func IDB58Encode(id ID) string
- func IDHexEncode(id ID) string
- type ID
- func (id ID) ExtractPublicKey() (ic.PubKey, error)
- func (id ID) Loggable() map[string]interface{}
- func (id ID) Marshal() ([]byte, error)
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalTo(data []byte) (n int, err error)
- func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool
- func (id ID) MatchesPublicKey(pk ic.PubKey) bool
- func (id ID) Pretty() string
- func (id ID) Size() int
- func (id ID) String() string
- func (id *ID) Unmarshal(data []byte) (err error)
- func (id *ID) UnmarshalJSON(data []byte) (err error)
- func (id ID) Validate() error
- type IDSlice
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
Types ¶
type ID ¶
type ID string
ID is a libp2p peer identity.
func IDFromBytes ¶
IDFromBytes cast a string to ID type, and validate the id to make sure it is a multihash.
func IDFromPrivateKey ¶
IDFromPrivateKey returns the Peer ID corresponding to sk
func IDFromPublicKey ¶
IDFromPublicKey returns the Peer ID corresponding to pk
func IDFromString ¶
IDFromString cast a string to ID type, and validate the id to make sure it is a multihash.
func (ID) ExtractPublicKey ¶
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) MarshalJSON ¶
func (ID) MatchesPrivateKey ¶
MatchesPrivateKey tests whether this ID was derived from sk
func (ID) MatchesPublicKey ¶
MatchesPublicKey tests whether this ID was derived from pk
func (ID) Size ¶
Implements Gogo's proto.Sizer, but we omit the compile-time assertion to avoid introducing a hard dependency on gogo.
func (ID) 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.