Module libp2p_peerbook

Data Types

peerbook()

peerbook() = #peerbook{tid = ets:tab(), store = rocksdb:db_handle(), pubkey_bin = libp2p_crypto:pubkey_bin(), network_id = binary(), stale_time = pos_integer()}

Function Index

blacklist_listen_addr/3Black list a given listen address for a peer.
get/2Get a peer from the peerbook given a peer key in it's binary form.
is_key/2Returns if a given peerk key is available in the store.
join_notify/2Join the peerbook change notification group.
keys/1Gets all the keys available in the peerbook store.
leave_notify/2Remove a given pid from peerbook notifications.
peerbook_handle/1Get the handle for a peerbook pid.
peerbook_pid/1Get the pid for a peerbook handle.
put/2Add a peer record to the peerbook.
register_listen_addr/2Registers a listen address.
register_session/2Registers a session with a remote peer with the peerbook.
remove/2Removes the peer for a given peer key.
set_nat_type/2Sets the NAT type for the peerbook.
stale_time/1Returns the configured stale_time for a peerbook.
start_link/1
unregister_listen_addr/2Removes a listen address.
unregister_session/2Removes a session from the list of sessions for the peerbook.
values/1Gets all the values available in the peerbook.

Function Details

blacklist_listen_addr/3

blacklist_listen_addr(Handle::peerbook(), ID::libp2p_crypto:pubkey_bin(), ListenAddr::string()) -> ok | {error, not_found}

Black list a given listen address for a peer.

This is a utility method to add a given listen address (in multiaddr form) to the metadata of the peer with the given peer key. Blacklist metadata is used by networking code to avoid certain listen addresses if they're not reachable.

Since the blacklist is stored in the metadata for a peer it is NOT gossipped over the network and it DOES expire when the peer record expires.

get/2

get(Peerbook::peerbook(), ID::libp2p_crypto:pubkey_bin()) -> {ok, libp2p_peer:peer()} | {error, term()}

Get a peer from the peerbook given a peer key in it's binary form. Note that peers will expire out of the peerbook after a configured stale_time, which means a previously available peer may not be available when requested again.

is_key/2

is_key(Handle::peerbook(), ID::libp2p_crypto:pubkey_bin()) -> boolean()

Returns if a given peerk key is available in the store.

join_notify/2

join_notify(Handle::peerbook(), Joiner::pid()) -> ok

Join the peerbook change notification group.

Adds the given pid to the progress group that is notified of changes to the peerbook. Change notification is collected for a configurable notify_time before it is sent out.

When the peerbook changes a tuple is sent out with form {changed_peers, {{add, ChangeAdd}, {remove, ChangeRemove}}}, where ChangeAdd is a map of peer keys to peers and ChangeRemove is a set of removed peer keys.

keys/1

keys(Handle::peerbook()) -> [libp2p_crypto:pubkey_bin()]

Gets all the keys available in the peerbook store

leave_notify/2

leave_notify(Handle::peerbook(), Pid::pid()) -> ok

Remove a given pid from peerbook notifications.

peerbook_handle/1

peerbook_handle(Pid::pid()) -> {ok, peerbook()} | {error, term()}

Get the handle for a peerbook pid.

Most functions int he peerbook can be done through a thread safe "handle". This utility method retrieves the handle, given the peerbook pid.

peerbook_pid/1

peerbook_pid(Peerbook::peerbook()) -> pid()

Get the pid for a peerbook handle.

Most functions int he peerbook can be done through a thread safe "handle". For the ones where state is involved the actual peerbook pid is required. Thisutility method gets the pid for a given peerbook handle.

put/2

put(Handle::peerbook(), NewPeer::libp2p_peer:peer()) -> ok | {error, term()}

Add a peer record to the peerbook

The peer is validated before being allowed into the peerbook. The peer must:

If the peer validates it is added to the store and notified locally as a changed peer. If the peer does not validate an error is returned

register_listen_addr/2

register_listen_addr(Handle::peerbook(), ListenAddr::string()) -> ok

Registers a listen address.

Registers a network listen address in multiaddr form for the "self" record for this peerbook. A change notification is sent out for the "self" record.

register_session/2

register_session(Handle::peerbook(), SessionPubKeyBin::libp2p_crypto:pubkey_bin()) -> ok

Registers a session with a remote peer with the peerbook.

A session is represented as the public binary key of the remote peer, and is maintained as part of the "self" peer record that the peerbook maintains for pubkey_bin.

remove/2

remove(Handle::peerbook(), ID::libp2p_crypto:pubkey_bin()) -> ok | {error, term()}

Removes the peer for a given peer key.

Returns an error if the key is not found, or if the key is the pubkey_bin key that the peerbook manages. If successful the peerbook will notify our a chnage to any registered listeners.

set_nat_type/2

set_nat_type(Handle::peerbook(), NatType::libp2p_peer:nat_type()) -> ok

Sets the NAT type for the peerbook.

The peerbook manages the nat_type for the "self" record identified by pubkey_bin. Changing the nat type will updathe "self" record and will send out a change notification.

stale_time/1

stale_time(Peerbook::peerbook()) -> pos_integer()

Returns the configured stale_time for a peerbook

start_link/1

start_link(Opts) -> any()

unregister_listen_addr/2

unregister_listen_addr(Handle::peerbook(), ListenAddr::string()) -> ok

Removes a listen address.

Removes a network listen address in multiaddr form from the "self" record for this peerbook.A change notification is sent out for the "self" record.

unregister_session/2

unregister_session(Handle::peerbook(), SessionPid::pid()) -> ok

Removes a session from the list of sessions for the peerbook.

This removes the session key managed for the "self" peer managed by the peerbook.

values/1

values(Handle::peerbook()) -> [libp2p_peer:peer()]

Gets all the values available in the peerbook


Generated by EDoc