Module libp2p_peer

Data Types

association()


association() = #libp2p_association_pb{}

association_map()


association_map() = [{Type::string(), [association()]}]

metadata()


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

nat_type()


nat_type() = libp2p_peer_pb:nat_type()

peer()


peer() = #libp2p_signed_peer_pb{}

peer_map()


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

Function Index

association_decode/2Decodes the given binary to an association and verifies it against the given peer key.
association_encode/1Encodes the given association to it's binary form.
association_pubkey_bin/1Gets the address for the given association.
association_pubkey_bins/1Returns a list of association keys.
association_signature/1Gets the signature for the given association.
association_verify/2Returns true if the association can be verified against the given peer key.
associations/1Get the associations for this peer.
associations_get/2Gets the associations of the given AssocType for the given peer.
associations_put/4Adds or replaces a given assocation for the given type to the peer.
associations_set/4Replaces all associations for a given association type in the given peer.
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.
decode_list/1Decodes a given binary into a list of peers.
decode_unsafe/1Decodes a binary peer without verification, use with care.
encode/1Encodes the given peer into its binary form.
encode_list/1Encodes a given list of peer into a binary form.
from_map/2
has_public_ip/1Returns whether the peer is listening on a public, externally visible IP address.
is_association/3Checks whether a given peer has an association stored with the given assocation type and key.
is_blacklisted/2Returns whether a given listen address is blacklisted.
is_dialable/1Returns whether the peer is dialable.
is_similar/2Returns whether a given Target is mostly equal to an Other peer.
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.
mk_association/3Make an association for a given peer key.
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/2
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

association_decode/2


association_decode(Bin::binary(), PeerPubKeyBin::libp2p_crypto:pubkey_bin()) -> association()


Decodes the given binary to an association and verifies it against the given peer key.

association_encode/1


association_encode(Msg::association()) -> binary()


Encodes the given association to it’s binary form

association_pubkey_bin/1


association_pubkey_bin(Libp2p_association_pb::association()) -> libp2p_crypto:pubkey_bin()


Gets the address for the given association

association_pubkey_bins/1


association_pubkey_bins(Libp2p_signed_peer_pb::peer()) -> [{AssocType::string(), [AssocPubKeyBin::libp2p_crypto:pubkey_bin()]}]


Returns a list of association keys. This can be used, for example, to compare to peer assocation records with eachother (like in is_similar/2)

association_signature/1


association_signature(Libp2p_association_pb::association()) -> binary()


Gets the signature for the given association

association_verify/2


association_verify(Assoc::association(), PeerPubKeyBin::libp2p_crypto:pubkey_bin()) -> true


Returns true if the association can be verified against the given peer key. This has to be the same peer key that was used to construct the signature in the assocation and should be the key of the peer record containing the given association.

associations/1


associations(Libp2p_signed_peer_pb::peer()) -> association_map()


Get the associations for this peer. This returns a keyed list with the association type as the key and a list of assocations as the value for that type.

associations_get/2


associations_get(Libp2p_signed_peer_pb::peer(), AssocType::string()) -> [association()]


Gets the associations of the given AssocType for the given peer.

associations_put/4


associations_put(Peer::peer(), AssocType::string(), Assoc::association(), PeerSigFun::libp2p_crypto:sig_fun()) -> peer()


Adds or replaces a given assocation for the given type to the peer. The returned peer is signed with the provided signing function.

associations_set/4


associations_set(Libp2p_signed_peer_pb::peer(), AssocType::string(), NewAssocs::[association()], PeerSigFun::libp2p_crypto:sig_fun()) -> peer()


Replaces all associations for a given association type in the given peer.

blacklist/1


blacklist(Libp2p_signed_peer_pb::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(Peer, ListenAddr) -> any()

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

blacklist_set/2


blacklist_set(Peer::peer(), BlackList::[string()]) -> peer()


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()) -> peer()


Decodes a given binary into a peer.

decode_list/1


decode_list(Bin::binary()) -> [peer()]


Decodes a given binary into a list of peers.

decode_unsafe/1


decode_unsafe(Bin::binary()) -> peer()


Decodes a binary peer without verification, use with care.

encode/1


encode(Msg::peer()) -> binary()


Encodes the given peer into its binary form.

encode_list/1


encode_list(List::[peer()]) -> binary()


Encodes a given list of peer into a binary form. Since encoding lists is primarily used for gossipping peers around, this strips metadata from the peers as part of encoding.

from_map/2


from_map(Map::peer_map(), SigFun::fun((binary()) -> binary())) -> peer()


has_public_ip/1


has_public_ip(Peer::peer()) -> boolean()


Returns whether the peer is listening on a public, externally visible IP address.

is_association/3


is_association(Peer::peer(), AssocType::string(), AssocPubKeyBin::libp2p_crypto:pubkey_bin()) -> boolean()


Checks whether a given peer has an association stored with the given assocation type and key

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_dialable/1

is_dialable(Peer) -> any()

Returns whether the peer is dialable. A peer is dialable if it has a public IP address or it is reachable via a relay address.

is_similar/2


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


Returns whether a given Target is mostly equal to an Other peer. Similarity means equality for all fields, except for the timestamp of the peers.

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::binary()) -> binary()


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()) -> peer()


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()) -> peer()


Replaces the full metadata for a given peer

mk_association/3


mk_association(AssocPubKeyBin::libp2p_crypto:pubkey_bin(), PeerPubKeyBin::libp2p_crypto:pubkey_bin(), AssocSigFun::libp2p_crypto:sig_fun()) -> association()


Make an association for a given peer key. The returned association contains the given assocation key and the given peer key signed with the passed in association provided signature function.

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()

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::any(), 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()) -> true


Cryptographically verifies a given peer and it’s associations. Returns true if the given peer can be verified or throws an error if the peer or one of it’s associations can’t be verified