Module libp2p_swarm

Data Types

connect_opt()


connect_opt() = {unique_session, boolean()} | {unique_port, boolean()} | no_relay | {no_relay, boolean()}

connect_opts()


connect_opts() = [connect_opt()]

swarm_opt()


swarm_opt() = {key, {libp2p_crypto:pubkey(), libp2p_crypto:sig_fun()}} | {base_dir, string()} | {libp2p_transport_tcp, [libp2p_transport_tcp:opt()]} | {libp2p_peerbook, [libp2p_peerbook:opt()]} | {libp2p_yamux_stream, [libp2p_yamux_stream:opt()]} | {libp2p_group_gossip, [libp2p_group_gossip:opt()]} | {libp2p_nat, [libp2p_nat:opt()]} | {libp2p_proxy, [libp2p_proxy:opt()]}

swarm_opts()


swarm_opts() = [swarm_opt()]

Function Index

add_connection_handler/3
add_group/4
add_stream_handler/3
add_transport_handler/2
cache/1Get the cache for a swarm.
connect/2
connect/4
dial/3
dial/5
dial_framed_stream/5Dial a remote swarm, negotiate a path and start a framed stream client with the given Module as the handler.
dial_framed_stream/7
gossip_group/1
is_stopping/1
keys/1Get the public key and signing function for a swarm.
listen/2
listen_addrs/1
name/1Get the name for a swarm.
network_id/1
network_id/2
opts/1Get the options a swarm was started with.
p2p_address/1Get the p2p address in string form for a swarm.
peerbook/1get the peerbook db handle for a swarm.
peerbook_pid/1Get the peerbook pid for a swarm.
pubkey_bin/1Get cryptographic address for a swarm.
remove_group/2
remove_stream_handler/2
sessions/1Get a list of libp2p_session addresses and pids for all open sessions to remote peers.
start/1Starts a swarm with a given name.
start/2Starts a swarm with a given name and sarm options.
stop/1Stops the given swarm.
store_peerbook/2
stream_handlers/1
swarm/1Get the swarm for a given ets table.
tid/1Gets the ets table for for this swarm.

Function Details

add_connection_handler/3


add_connection_handler(Sup::pid() | ets:tab(), Key::string(), X3::{libp2p_transport:connection_handler(), libp2p_transport:connection_handler() | undefined}) -> ok


add_group/4


add_group(Sup::pid() | ets:tab(), GroupID::string(), Module::atom(), Args::[any()]) -> {ok, pid()} | {error, term()}


add_stream_handler/3


add_stream_handler(Sup::pid() | ets:tab(), Key::string(), HandlerDef::libp2p_session:stream_handler()) -> ok


add_transport_handler/2


add_transport_handler(Sup::pid() | ets:tab(), Transport::atom()) -> ok | {error, term()}


cache/1


cache(Sup::ets:tab() | pid()) -> pid()


Get the cache for a swarm.

connect/2


connect(Sup::pid(), Addr::string()) -> {ok, pid()} | {error, term()}


connect/4


connect(Sup::pid() | ets:tab(), Addr::string(), Options::connect_opts(), Timeout::pos_integer()) -> {ok, pid()} | {error, term()}


dial/3


dial(Sup::pid(), Addr::string(), Path::string()) -> {ok, libp2p_connection:connection()} | {error, term()}


dial/5


dial(Sup::pid() | ets:tab(), Addr::string(), Path::string(), Options::connect_opts(), Timeout::pos_integer()) -> {ok, libp2p_connection:connection()} | {error, term()}


dial_framed_stream/5


dial_framed_stream(Sup::pid() | ets:tab(), Addr::string(), Path::string(), Module::atom(), Args::[any()]) -> {ok, pid()} | {error, term()}


Dial a remote swarm, negotiate a path and start a framed stream client with the given Module as the handler.

dial_framed_stream/7


dial_framed_stream(Sup::pid() | ets:tab(), Addr::string(), Path::string(), Options::connect_opts(), Timeout::pos_integer(), Module::atom(), Args::[any()]) -> {ok, pid()} | {error, term()}


gossip_group/1


gossip_group(Sup::pid() | ets:tab()) -> pid()


is_stopping/1

is_stopping(Sup) -> any()

keys/1


keys(Sup::ets:tab() | pid()) -> {ok, libp2p_crypto:pubkey(), libp2p_crypto:sig_fun(), libp2p_crypto:ecdh_fun()} | {error, term()}


Get the public key and signing function for a swarm

listen/2


listen(Sup::pid() | ets:tab(), Port::string() | non_neg_integer()) -> ok | {error, term()}


listen_addrs/1


listen_addrs(Sup::pid() | ets:tab()) -> [string()]


name/1


name(Sup::ets:tab() | pid()) -> atom()


Get the name for a swarm.

network_id/1


network_id(Sup::ets:tab() | pid()) -> binary() | undefined


network_id/2


network_id(Sup::ets:tab() | pid(), NetworkID::binary()) -> true


opts/1


opts(Sup::ets:tab() | pid()) -> swarm_opts() | any()


Get the options a swarm was started with.

p2p_address/1


p2p_address(TidOrPid::ets:tab() | pid()) -> string()


Get the p2p address in string form for a swarm

peerbook/1


peerbook(Sup::ets:tab() | pid()) -> libp2p_peerbook:peerbook() | false


get the peerbook db handle for a swarm

peerbook_pid/1


peerbook_pid(Sup::ets:tab() | pid()) -> pid()


Get the peerbook pid for a swarm.

pubkey_bin/1


pubkey_bin(Sup::ets:tab() | pid()) -> libp2p_crypto:pubkey_bin()


Get cryptographic address for a swarm.

remove_group/2


remove_group(Sup::pid() | ets:tab(), GroupID::string()) -> ok | {error, term()}


remove_stream_handler/2


remove_stream_handler(Sup::pid() | ets:tab(), Key::string()) -> ok


sessions/1


sessions(Sup::ets:tab() | pid()) -> [{string(), pid()}]


Get a list of libp2p_session addresses and pids for all open sessions to remote peers.

start/1


start(Name::atom()) -> {ok, pid()} | ignore | {error, term()}


Starts a swarm with a given name. This starts a swarm with no listeners. The swarm name is used to distinguish the data folder for the swarm from other started swarms on the same node.

start/2


start(Name::atom(), Opts::swarm_opts()) -> {ok, pid()} | ignore | {error, term()}


Starts a swarm with a given name and sarm options. This starts a swarm with no listeners. The options can be used to configure and control behavior of various subsystems of the swarm.

stop/1


stop(Sup::pid()) -> ok


Stops the given swarm.

store_peerbook/2


store_peerbook(Sup::ets:tab() | pid(), Handle::libp2p_peerbook:peerbook()) -> true


stream_handlers/1


stream_handlers(Sup::pid() | ets:tab()) -> [{string(), libp2p_session:stream_handler()}]


swarm/1


swarm(TID::ets:tab()) -> pid()


Get the swarm for a given ets table. A swarm is represented by the supervisor for the services it contains. Many internal processes get started with the ets table that stores data about a swarm. This function makes it easy to get back to the swarm from a given swarm ets table.

tid/1


tid(Sup::pid()) -> ets:tab()


Gets the ets table for for this swarm. This is the opposite of swarm/1 and used by a number of internal swarm functions and services to find other services in the given swarm.