mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 10:31:21 +00:00
Fix several errors reported by clippy. (#715)
This commit is contained in:
@ -634,10 +634,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Poll the existing nodes.
|
// Poll the existing nodes.
|
||||||
loop {
|
|
||||||
let (action, out_event);
|
let (action, out_event);
|
||||||
match self.active_nodes.poll() {
|
match self.active_nodes.poll() {
|
||||||
Async::NotReady => break,
|
Async::NotReady => return Async::NotReady,
|
||||||
Async::Ready(CollectionEvent::NodeReached(reach_event)) => {
|
Async::Ready(CollectionEvent::NodeReached(reach_event)) => {
|
||||||
let (a, e) = handle_node_reached(&mut self.reach_attempts, reach_event);
|
let (a, e) = handle_node_reached(&mut self.reach_attempts, reach_event);
|
||||||
action = a;
|
action = a;
|
||||||
@ -681,7 +680,7 @@ where
|
|||||||
action = Default::default();
|
action = Default::default();
|
||||||
out_event = RawSwarmEvent::NodeEvent { peer_id, event };
|
out_event = RawSwarmEvent::NodeEvent { peer_id, event };
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if let Some((peer_id, handler, first, rest)) = action.start_dial_out {
|
if let Some((peer_id, handler, first, rest)) = action.start_dial_out {
|
||||||
self.start_dial_out(peer_id, handler, first, rest);
|
self.start_dial_out(peer_id, handler, first, rest);
|
||||||
@ -699,10 +698,7 @@ where
|
|||||||
attempts; QED");
|
attempts; QED");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Async::Ready(out_event);
|
Async::Ready(out_event)
|
||||||
}
|
|
||||||
|
|
||||||
Async::NotReady
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,13 +171,10 @@ where
|
|||||||
mut substream: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
|
mut substream: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
|
||||||
_info: Self::OutboundOpenInfo
|
_info: Self::OutboundOpenInfo
|
||||||
) {
|
) {
|
||||||
match mem::replace(&mut self.out_state, OutState::Poisoned) {
|
if let OutState::Upgrading { expires } = mem::replace(&mut self.out_state, OutState::Poisoned) {
|
||||||
OutState::Upgrading { expires } => {
|
|
||||||
// We always upgrade with the intent of immediately pinging.
|
// We always upgrade with the intent of immediately pinging.
|
||||||
substream.ping(Instant::now());
|
substream.ping(Instant::now());
|
||||||
self.out_state = OutState::WaitingForPong { substream, expires };
|
self.out_state = OutState::WaitingForPong { substream, expires }
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,15 +229,14 @@ where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
|
||||||
match mem::replace(&mut self.out_state, OutState::Poisoned) {
|
match mem::replace(&mut self.out_state, OutState::Poisoned) {
|
||||||
OutState::Shutdown | OutState::Poisoned => {
|
OutState::Shutdown | OutState::Poisoned => {
|
||||||
// This shuts down the whole connection with the remote.
|
// This shuts down the whole connection with the remote.
|
||||||
return Ok(Async::Ready(None));
|
Ok(Async::Ready(None))
|
||||||
},
|
},
|
||||||
|
|
||||||
OutState::Disabled => {
|
OutState::Disabled => {
|
||||||
return Ok(Async::NotReady);
|
Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to open an outgoing substream.
|
// Need to open an outgoing substream.
|
||||||
@ -248,32 +244,29 @@ where
|
|||||||
// Note that we ignore the expiration here, as it's pretty unlikely to happen.
|
// Note that we ignore the expiration here, as it's pretty unlikely to happen.
|
||||||
// The expiration is only here to be transmitted to the `Upgrading`.
|
// The expiration is only here to be transmitted to the `Upgrading`.
|
||||||
self.out_state = OutState::Upgrading { expires };
|
self.out_state = OutState::Upgrading { expires };
|
||||||
return Ok(Async::Ready(Some(
|
Ok(Async::Ready(Some(
|
||||||
ProtocolsHandlerEvent::OutboundSubstreamRequest {
|
ProtocolsHandlerEvent::OutboundSubstreamRequest {
|
||||||
upgrade: self.ping_config,
|
upgrade: self.ping_config,
|
||||||
info: (),
|
info: (),
|
||||||
},
|
},
|
||||||
)));
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waiting for the upgrade to be negotiated.
|
// Waiting for the upgrade to be negotiated.
|
||||||
OutState::Upgrading { mut expires } => poll_delay!(expires => {
|
OutState::Upgrading { mut expires } => poll_delay!(expires => {
|
||||||
NotReady => {
|
NotReady => {
|
||||||
self.out_state = OutState::Upgrading { expires };
|
self.out_state = OutState::Upgrading { expires };
|
||||||
return Ok(Async::NotReady);
|
Ok(Async::NotReady)
|
||||||
},
|
},
|
||||||
Ready => {
|
Ready => {
|
||||||
self.out_state = OutState::Shutdown;
|
self.out_state = OutState::Shutdown;
|
||||||
let ev = OutEvent::Unresponsive;
|
let ev = OutEvent::Unresponsive;
|
||||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))));
|
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))))
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Waiting for the pong.
|
// Waiting for the pong.
|
||||||
OutState::WaitingForPong {
|
OutState::WaitingForPong { mut substream, mut expires } => {
|
||||||
mut substream,
|
|
||||||
mut expires,
|
|
||||||
} => {
|
|
||||||
// We start by dialing the substream, leaving one last chance for it to
|
// We start by dialing the substream, leaving one last chance for it to
|
||||||
// produce the pong even if the expiration happened.
|
// produce the pong even if the expiration happened.
|
||||||
match substream.poll()? {
|
match substream.poll()? {
|
||||||
@ -290,7 +283,7 @@ where
|
|||||||
self.out_state = OutState::Shutdown;
|
self.out_state = OutState::Shutdown;
|
||||||
return Ok(Async::Ready(None));
|
return Ok(Async::Ready(None));
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Check the expiration.
|
// Check the expiration.
|
||||||
poll_delay!(expires => {
|
poll_delay!(expires => {
|
||||||
@ -298,35 +291,31 @@ where
|
|||||||
self.out_state = OutState::WaitingForPong { substream, expires };
|
self.out_state = OutState::WaitingForPong { substream, expires };
|
||||||
// Both `substream` and `expires` and not ready, so it's fine to return
|
// Both `substream` and `expires` and not ready, so it's fine to return
|
||||||
// not ready.
|
// not ready.
|
||||||
return Ok(Async::NotReady);
|
Ok(Async::NotReady)
|
||||||
},
|
},
|
||||||
Ready => {
|
Ready => {
|
||||||
self.out_state = OutState::Shutdown;
|
self.out_state = OutState::Shutdown;
|
||||||
let ev = OutEvent::Unresponsive;
|
let ev = OutEvent::Unresponsive;
|
||||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))));
|
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(ev))))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
OutState::Idle {
|
OutState::Idle { mut substream, mut next_ping } => {
|
||||||
mut substream,
|
|
||||||
mut next_ping,
|
|
||||||
} => {
|
|
||||||
// Poll the future that fires when we need to ping the node again.
|
// Poll the future that fires when we need to ping the node again.
|
||||||
poll_delay!(next_ping => {
|
poll_delay!(next_ping => {
|
||||||
NotReady => {
|
NotReady => {
|
||||||
self.out_state = OutState::Idle { substream, next_ping };
|
self.out_state = OutState::Idle { substream, next_ping };
|
||||||
return Ok(Async::NotReady);
|
Ok(Async::NotReady)
|
||||||
},
|
},
|
||||||
Ready => {
|
Ready => {
|
||||||
let expires = Delay::new(Instant::now() + self.ping_timeout);
|
let expires = Delay::new(Instant::now() + self.ping_timeout);
|
||||||
substream.ping(Instant::now());
|
substream.ping(Instant::now());
|
||||||
self.out_state = OutState::WaitingForPong { substream, expires };
|
self.out_state = OutState::WaitingForPong { substream, expires };
|
||||||
return Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(OutEvent::PingStart))));
|
Ok(Async::Ready(Some(ProtocolsHandlerEvent::Custom(OutEvent::PingStart))))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,6 @@ pub trait PeerAccess {
|
|||||||
/// Sets the TTL of an address of a peer. Adds the address if it is currently unknown.
|
/// Sets the TTL of an address of a peer. Adds the address if it is currently unknown.
|
||||||
///
|
///
|
||||||
/// Contrary to `add_addr`, this operation is never a no-op.
|
/// Contrary to `add_addr`, this operation is never a no-op.
|
||||||
#[inline]
|
|
||||||
fn set_addr_ttl(&mut self, addr: Multiaddr, ttl: TTL);
|
fn set_addr_ttl(&mut self, addr: Multiaddr, ttl: TTL);
|
||||||
|
|
||||||
// Similar to calling `set_addr_ttl` multiple times in a row.
|
// Similar to calling `set_addr_ttl` multiple times in a row.
|
||||||
|
Reference in New Issue
Block a user