Struct crust::Service
[−]
[src]
pub struct Service { // some fields omitted }
A structure representing a connection manager. This is the main object through which crust is used.
Methods
impl Service
[src]
fn new(event_tx: CrustEventSender) -> Res<Self>
Construct a service. event_tx
is the sending half of the channel which crust will send
notifications on.
fn with_config(event_tx: CrustEventSender, config: Config) -> Res<Service>
Constructs a service with the given config. User needs to create an asynchronous channel,
and provide the sender half to this method. Receiver will receive all Event
s from this
library.
fn start_service_discovery(&mut self)
Starts listening for beacon broadcasts.
fn set_service_discovery_listen(&self, listen: bool)
Enable (or disable) listening and responding to peers searching for us. This can be used to allow others to discover us on the local network.
fn is_peer_whitelisted(&self, peer_id: &PeerId) -> bool
Check if the provided peer address is whitelisted in config.
fn has_peers_on_lan(&self) -> bool
Check if we have peers on LAN
fn start_bootstrap(&mut self, blacklist: HashSet<SocketAddr>) -> Res<()>
Start the bootstrapping procedure. It will auto terminate after indicating success or failure via the event channel.
fn stop_bootstrap(&mut self) -> Res<()>
Stop the bootstraping procedure explicitly
fn start_listening_tcp(&mut self) -> Res<()>
Starts accepting TCP connections. This is persistant until it errors out or is stopped explicitly.
fn stop_tcp_listener(&mut self) -> Res<()>
Stops Listener explicitly and stops accepting TCP connections.
fn connect(&self, our_ci: PrivConnectionInfo, their_ci: PubConnectionInfo) -> Res<()>
Connect to a peer. To call this method you must follow these steps:
* Generate a PrivConnectionInfo
via Service::prepare_connection_info
.
* Create a PubConnectionInfo
via PrivConnectionInfo::to_pub_connection_info
.
* Swap PubConnectionInfo
s out-of-band with the peer you are connecting to.
* Call Service::connect
using your PrivConnectionInfo
and the PubConnectionInfo
obtained from the peer
fn disconnect(&self, peer_id: PeerId) -> bool
Disconnect from the given peer and returns whether there was a connection at all.
fn send(&self, peer_id: PeerId, msg: Vec<u8>, priority: Priority) -> Res<()>
Send data to a peer.
fn prepare_connection_info(&self, result_token: u32)
Generate connection info. The connection info is returned via the ConnectionInfoPrepared
event on the event channel. Calling this method is the first step of connecting to another
peer, see Service::connect
for more info.
fn is_connected(&self, peer_id: &PeerId) -> bool
Check if we are connected to the given peer
fn id(&self) -> PeerId
Returns our ID.