Enum libp2p_core::network::peer::Peer [−][src]
pub enum Peer<'a, TTrans, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler, {
Connected(ConnectedPeer<'a, TTrans, THandler>),
Dialing(DialingPeer<'a, TTrans, THandler>),
Disconnected(DisconnectedPeer<'a, TTrans, THandler>),
Local,
}
Expand description
The possible representations of a peer in a Network
, as
seen by the local node.
Note: In any state there may always be a pending incoming connection attempt from the peer, however, the remote identity of a peer is only known once a connection is fully established.
Variants
Connected(ConnectedPeer<'a, TTrans, THandler>)
At least one established connection exists to the peer.
Tuple Fields of Connected
0: ConnectedPeer<'a, TTrans, THandler>
Dialing(DialingPeer<'a, TTrans, THandler>)
There is an ongoing dialing (i.e. outgoing connection) attempt to the peer. There may already be other established connections to the peer.
Tuple Fields of Dialing
0: DialingPeer<'a, TTrans, THandler>
Disconnected(DisconnectedPeer<'a, TTrans, THandler>)
There exists no established connection to the peer and there is currently no ongoing dialing (i.e. outgoing connection) attempt in progress.
Tuple Fields of Disconnected
0: DisconnectedPeer<'a, TTrans, THandler>
The peer represents the local node.
Implementations
impl<'a, TTrans, THandler> Peer<'a, TTrans, THandler> where
TTrans: Transport + Clone + Send + 'static,
TTrans::Output: Send + 'static,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler + Send,
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<THandler::Handler as ConnectionHandler>::Error: Error + Send + 'static,
impl<'a, TTrans, THandler> Peer<'a, TTrans, THandler> where
TTrans: Transport + Clone + Send + 'static,
TTrans::Output: Send + 'static,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler + Send,
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<THandler::Handler as ConnectionHandler>::Error: Error + Send + 'static,
Checks whether the peer is currently connected.
Returns true
iff Peer::into_connected
returns Some
.
Checks whether the peer is currently being dialed.
Returns true
iff Peer::into_dialing
returns Some
.
Checks whether the peer is currently disconnected.
Returns true
iff Peer::into_disconnected
returns Some
.
pub fn dial<I>(
self,
addresses: I,
handler: THandler
) -> Result<(ConnectionId, DialingPeer<'a, TTrans, THandler>), DialError<THandler>> where
I: IntoIterator<Item = Multiaddr>,
I::IntoIter: Send + 'static,
pub fn dial<I>(
self,
addresses: I,
handler: THandler
) -> Result<(ConnectionId, DialingPeer<'a, TTrans, THandler>), DialError<THandler>> where
I: IntoIterator<Item = Multiaddr>,
I::IntoIter: Send + 'static,
Initiates a new dialing attempt to this peer using the given addresses.
The connection ID of the first connection attempt, i.e. to address
,
is returned, together with a DialingPeer
for further use. The
remaining
addresses are tried in order in subsequent connection
attempts in the context of the same dialing attempt, if the connection
attempt to the first address fails.
Converts the peer into a ConnectedPeer
, if an established connection exists.
Succeeds if the there is at least one established connection to the peer.
Converts the peer into a DialingPeer
, if a dialing attempt exists.
Succeeds if the there is at least one pending outgoing connection to the peer.
Converts the peer into a DisconnectedPeer
, if neither an established connection
nor a dialing attempt exists.