Module libp2p_peer

A peeer record represents the current state of a peer on the libp2p network.

Copyright © Helium Systems, Inc.

Description

A peeer record represents the current state of a peer on the libp2p network.

Data Types

metadata()

metadata() = [{string(), binary()}]

nat_type()

nat_type() = libp2p_peer_pb:nat_type()

peer()

peer() = #libp2p_signed_peer_pb{}

peer_map()

peer_map() = #{pubkey_bin => libp2p_crypto:pubkey_bin(), listen_addrs => [string()], connected => [binary()], nat_type => nat_type(), network_id => binary(), signed_metadata => #{binary() => binary()}}

Function Index

blacklist/1Gets the blacklist for this peer.
blacklist_add/2Add a given listen address to the blacklist for the given peer.
blacklist_set/2Sets the blacklist for a given peer.
cleared_listen_addrs/1Returns the listen addrs for this peer filtered using the blacklist for the peer, if one is present.
connected_peers/1Gets the list of peer crypto addresses that the given peer was last known to be connected to.
decode/1Decodes a given binary into a peer.
encode/2Encodes the given peer into its binary form.
from_map/2Create a signed peer from a given map of fields.
is_blacklisted/2Returns whether a given listen address is blacklisted.
is_stale/2Returns whether a given peer is stale relative to a given stale delta time in milliseconds.
listen_addrs/1Gets the list of peer multiaddrs that the given peer is listening on.
metadata/1Gets the metadata map from the given peer.
metadata_get/3Gets the value for a stored Key in metadata.
metadata_put/3Updates the metadata for a given peer with the given key/value pair.
metadata_set/2Replaces the full metadata for a given peer.
nat_type/1Gets the NAT type of the given peer.
network_id/1Returns the declared network id for the peer, if any.
network_id_allowable/2Returns whether a givne network id is compatible with this peer.
pubkey_bin/1Gets the public key for the given peer.
signed_metadata/1Gets the signed metadata of the given peer.
signed_metadata_get/3Gets a key from the signed metadata of the given peer.
supersedes/2Returns whether a given Target is more recent than Other
timestamp/1Gets the timestamp of the given peer.
verify/1Cryptographically verifies a given peer and it's associations.

Function Details

blacklist/1

blacklist(Peer::peer()) -> [string()]

Gets the blacklist for this peer. This is a metadata based feature that enables listen addresses to be blacklisted so they will not be connected to until that address is removed from the blacklist.

blacklist_add/2

blacklist_add(Libp2p_signed_peer_pb::#libp2p_signed_peer_pb{}, ListenAddr::string()) -> {ok, peer()} | {error, term()}

Add a given listen address to the blacklist for the given peer.

blacklist_set/2

blacklist_set(Peer::peer(), BlackList::[string()]) -> {ok, peer()} | {error, term()}

Sets the blacklist for a given peer. Note that currently no validation is done against the existing listen addresses stored in the peer. Blacklisting an address that the peer is not listening to will have no effect anyway.

cleared_listen_addrs/1

cleared_listen_addrs(Peer::peer()) -> [string()]

Returns the listen addrs for this peer filtered using the blacklist for the peer, if one is present. This is just a convenience function to clear the listen adddresses for a peer with the blacklist stored in metadata.

connected_peers/1

connected_peers(Libp2p_signed_peer_pb::peer()) -> [libp2p_crypto:pubkey_bin()]

Gets the list of peer crypto addresses that the given peer was last known to be connected to.

decode/1

decode(Bin::binary()) -> {ok, peer()} | {error, term()}

Decodes a given binary into a peer. Note that a decoded peer may not verify, so ensure to call verify before actually using peer content

encode/2

encode(Msg::peer(), Strip::boolean()) -> binary()

Encodes the given peer into its binary form. The peer is stripped from its metadata before encoding if Strip is true.

from_map/2

from_map(Map::peer_map(), SigFun::fun((binary()) -> binary())) -> {ok, peer()} | {error, term()}

Create a signed peer from a given map of fields.

is_blacklisted/2

is_blacklisted(Peer::peer(), ListenAddr::string()) -> boolean()

Returns whether a given listen address is blacklisted. Note that a blacklisted address may not actually appear in the listen_addrs for this peer.

is_stale/2

is_stale(Libp2p_signed_peer_pb::peer(), StaleMS::integer()) -> boolean()

Returns whether a given peer is stale relative to a given stale delta time in milliseconds.

listen_addrs/1

listen_addrs(Libp2p_signed_peer_pb::peer()) -> [string()]

Gets the list of peer multiaddrs that the given peer is listening on.

metadata/1

metadata(Libp2p_signed_peer_pb::peer()) -> metadata()

Gets the metadata map from the given peer. The metadata for a peer is NOT part of the signed peer since it can be read and updated by anyone to annotate the given peer with extra information

metadata_get/3

metadata_get(Peer::peer(), Key::string(), Default::any()) -> any()

Gets the value for a stored Key in metadata. If not found, the Default is returned.

metadata_put/3

metadata_put(Peer::peer(), Key::string(), Value::binary()) -> {ok, peer()} | {error, term()}

Updates the metadata for a given peer with the given key/value pair. The Key is expected to be a string, while Value is expected to be a binary.

metadata_set/2

metadata_set(Peer::peer(), Metadata::metadata()) -> {ok, peer()} | {error, term()}

Replaces the full metadata for a given peer

nat_type/1

nat_type(Libp2p_signed_peer_pb::peer()) -> nat_type()

Gets the NAT type of the given peer.

network_id/1

network_id(Libp2p_signed_peer_pb::peer()) -> binary() | undefined

Returns the declared network id for the peer, if any

network_id_allowable/2

network_id_allowable(Peer, MyNetworkID) -> any()

Returns whether a givne network id is compatible with this peer.

A network id is compatible with the network id of this peer if they are equal or if either of them is undefined

pubkey_bin/1

pubkey_bin(Libp2p_signed_peer_pb::peer()) -> libp2p_crypto:pubkey_bin()

Gets the public key for the given peer.

signed_metadata/1

signed_metadata(Libp2p_signed_peer_pb::peer()) -> map()

Gets the signed metadata of the given peer

signed_metadata_get/3

signed_metadata_get(Peer::peer(), Key::binary(), Default::any()) -> any()

Gets a key from the signed metadata of the given peer

supersedes/2

supersedes(Target::peer(), Other::peer()) -> boolean()

Returns whether a given Target is more recent than Other

timestamp/1

timestamp(Libp2p_signed_peer_pb::peer()) -> integer()

Gets the timestamp of the given peer.

verify/1

verify(Msg::peer()) -> boolean()

Cryptographically verifies a given peer and it's associations. Returns true if the given peer can be verified, false otherwise.


Generated by EDoc