peerbook() = #peerbook{tid = ets:tab(), store = rocksdb:db_handle(), pubkey_bin = libp2p_crypto:pubkey_bin(), network_id = binary(), stale_time = pos_integer()}
blacklist_listen_addr/3 | Black list a given listen address for a peer. |
get/2 | Get a peer from the peerbook given a peer key in it's binary form. |
is_key/2 | Returns if a given peerk key is available in the store. |
join_notify/2 | Join the peerbook change notification group. |
keys/1 | Gets all the keys available in the peerbook store. |
leave_notify/2 | Remove a given pid from peerbook notifications. |
peerbook_handle/1 | Get the handle for a peerbook pid. |
peerbook_pid/1 | Get the pid for a peerbook handle. |
put/2 | Add a peer record to the peerbook. |
register_listen_addr/2 | Registers a listen address. |
register_session/2 | Registers a session with a remote peer with the peerbook. |
remove/2 | Removes the peer for a given peer key. |
set_nat_type/2 | Sets the NAT type for the peerbook. |
stale_time/1 | Returns the configured stale_time for a peerbook. |
start_link/1 | |
unregister_listen_addr/2 | Removes a listen address. |
unregister_session/2 | Removes a session from the list of sessions for the peerbook. |
values/1 | Gets all the values available in the peerbook. |
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(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(Handle::peerbook(), ID::libp2p_crypto:pubkey_bin()) -> boolean()
Returns if a given peerk key is available in the store.
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.
{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(Handle::peerbook()) -> [libp2p_crypto:pubkey_bin()]
Gets all the keys available in the peerbook store
leave_notify(Handle::peerbook(), Pid::pid()) -> ok
Remove a given pid from peerbook notifications.
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(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(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:
stale_time
for this peerbook 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(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 forpubkey_bin
.
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 thepubkey_bin
key that the peerbook manages. If successful the
peerbook will notify our a chnage to any registered listeners.
set_nat_type(Handle::peerbook(), NatType::libp2p_peer:nat_type()) -> ok
Sets the NAT type for the peerbook.
The peerbook manages thenat_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(Peerbook::peerbook()) -> pos_integer()
Returns the configured stale_time
for a peerbook
start_link(Opts) -> any()
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(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(Handle::peerbook()) -> [libp2p_peer:peer()]
Gets all the values available in the peerbook
Generated by EDoc