[][src]Struct libp2prs_swarm::Control

pub struct Control { /* fields omitted */ }

The Swarm controller.

While a Yamux connection makes progress via its next_stream method, this controller can be used to concurrently direct the connection, e.g. to open a new stream to the remote or to close the connection.

Implementations

impl Control[src]

pub fn peer_in_iter(&self) -> IntoIter<PeerId, usize>[src]

Return an iterator that contains all input bytes group by peer.

pub fn peer_out_iter(&self) -> IntoIter<PeerId, usize>[src]

Return an iterator that contains all output bytes group by peer.

pub fn protocol_in_iter(&self) -> IntoIter<String, usize>[src]

Return an iterator that contains all input bytes group by protocol.

pub fn protocol_out_iter(&self) -> IntoIter<String, usize>[src]

Return an iterator that contains all output bytes group by protocol.

pub fn get_peers(&self) -> Vec<PeerId>[src]

Get all peers in the AddrBook of Peerstore.

pub fn get_recv_count_and_size(&self) -> (usize, usize)[src]

Get recv package count&bytes

pub fn get_sent_count_and_size(&self) -> (usize, usize)[src]

Get send package count&bytes

pub fn get_protocol_in_and_out(
    &self,
    protocol_id: &str
) -> (Option<usize>, Option<usize>)
[src]

Get recv&send bytes by protocol_id

pub fn get_peer_in_and_out(
    &self,
    peer_id: &PeerId
) -> (Option<usize>, Option<usize>)
[src]

Get recv&send bytes by peer_id

pub async fn connect_with_addrs(
    &mut self,
    peer_id: PeerId,
    addrs: Vec<Multiaddr>
) -> Result<(), SwarmError>
[src]

Make a new connection towards the remote peer with addresses specified.

pub async fn new_connection(
    &mut self,
    peer_id: PeerId
) -> Result<(), SwarmError>
[src]

Make a new connection towards the remote peer.

It will lookup the peer store for address of the peer, otherwise initiate the routing interface for querying the addresses, if routing is available.

pub async fn new_connection_no_routing(
    &mut self,
    peer_id: PeerId
) -> Result<(), SwarmError>
[src]

Make a new connection towards the remote peer, without using routing(Kad-DHT).

pub async fn disconnect(&mut self, peer_id: PeerId) -> Result<(), SwarmError>[src]

Close connection towards the remote peer.

pub async fn new_stream(
    &mut self,
    peer_id: PeerId,
    pids: Vec<ProtocolId>
) -> Result<Substream, SwarmError>
[src]

Open a new outbound stream towards the remote peer.

It will lookup the peer store for address of the peer, otherwise initiate the routing interface for address querying, when routing is enabled. In the end, it will open an outgoing sub-stream when the connection is eventually established.

pub async fn new_stream_no_routing(
    &mut self,
    peer_id: PeerId,
    pids: Vec<ProtocolId>
) -> Result<Substream, SwarmError>
[src]

Open a new outbound stream towards the remote peer, without routing.

pub async fn self_addrs(&mut self) -> Result<Vec<Multiaddr>, SwarmError>[src]

Retrieve the all listened addresses from Swarm.

All listened addresses on interface and the observed addresses from Identify protocol.

pub async fn retrieve_networkinfo(&mut self) -> Result<NetworkInfo, SwarmError>[src]

Retrieve network information from Swarm.

pub async fn retrieve_identify_info(
    &mut self
) -> Result<IdentifyInfo, SwarmError>
[src]

Retrieve identify information from Swarm.

pub async fn dump_connections(
    &mut self,
    peer_id: Option<PeerId>
) -> Result<Vec<ConnectionView>, SwarmError>
[src]

pub async fn dump_streams(
    &mut self,
    peer_id: PeerId
) -> Result<Vec<SubstreamView>, SwarmError>
[src]

pub async fn close(&mut self)[src]

Close the swarm.

pub fn pin(&self, peer_id: &PeerId)[src]

Pins the peer Id so that GC wouldn't recycle the multiaddr of the peer.

pub fn unpin(&self, peer_id: &PeerId)[src]

Unpins the peer Id.

pub fn pinned(&self, peer_id: &PeerId) -> bool[src]

Checks if the peer is currently being pinned in peer store.

pub fn get_key(&self, peer_id: &PeerId) -> Option<PublicKey>[src]

Gets the public key by peer_id.

pub fn get_addrs(&self, peer_id: &PeerId) -> Option<Vec<Multiaddr>>[src]

Gets all multiaddr of a peer.

pub fn add_addr(&self, peer_id: &PeerId, addr: Multiaddr, ttl: Duration)[src]

Adds a address to address_book by peer_id, if exists, update rtt.

pub fn add_addrs(&self, peer_id: &PeerId, addrs: Vec<Multiaddr>, ttl: Duration)[src]

Adds many new addresses if they're not already in the peer store.

pub fn clear_addrs(&self, peer_id: &PeerId)[src]

Clears all multiaddr of a peer from the peer store.

pub fn update_addr(&self, peer_id: &PeerId, new_ttl: Duration)[src]

Updates ttl.

pub fn add_protocols(&self, peer_id: &PeerId, protos: Vec<String>)[src]

Adds the protocols by peer_id.

pub fn clear_protocols(&self, peer_id: &PeerId)[src]

Removes the protocols by peer_id.

pub fn get_protocols(&self, peer_id: &PeerId) -> Option<Vec<String>>[src]

Gets the protocols supported by the specified PeerId.

pub fn first_supported_protocol(
    &self,
    peer_id: &PeerId,
    protos: Vec<String>
) -> Option<String>
[src]

Tests if the PeerId supports the given protocols.

Trait Implementations

impl Clone for Control[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,