Struct crust::Service
[−]
[src]
pub struct Service<UID: Uid> { /* fields omitted */ }
A structure representing all the Crust services. This is the main object through which crust is used.
Methods
impl<UID: Uid> Service<UID>
[src]
fn new(event_tx: CrustEventSender<UID>, our_uid: UID) -> 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<UID>,
config: Config,
our_uid: UID
) -> Res<Self>
event_tx: CrustEventSender<UID>,
config: Config,
our_uid: UID
) -> Res<Self>
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 set_accept_bootstrap(&self, accept: bool) -> Res<()>
Allow (or disallow) peers from bootstrapping off us.
fn start_service_discovery(&mut self)
Initialises Service Discovery module and starts listening for responses to our 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 get_peer_ip_addr(&self, peer_uid: &UID) -> Res<IpAddr>
Return the ip address of the peer.
fn is_peer_hard_coded(&self, peer_uid: &UID) -> bool
Returns whether the given peer's IP is in the config file's hard-coded contacts list.
fn has_peers_on_lan(&self) -> bool
Check if we have peers on LAN
fn start_bootstrap(
&mut self,
blacklist: HashSet<SocketAddr>,
crust_user: CrustUser
) -> Res<()>
&mut self,
blacklist: HashSet<SocketAddr>,
crust_user: CrustUser
) -> 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<UID>,
their_ci: PubConnectionInfo<UID>
) -> Res<()>
&self,
our_ci: PrivConnectionInfo<UID>,
their_ci: PubConnectionInfo<UID>
) -> 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_uid: &UID) -> bool
Disconnect from the given peer and returns whether there was a connection at all.
fn send(&self, peer_uid: &UID, 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_uid: &UID) -> bool
Check if we are connected to the given peer
fn id(&self) -> UID
Returns our ID.