Skip to content

Commit

Permalink
Fix old task not interrupted after replacing (libp2p#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored Sep 14, 2018
1 parent 063ab17 commit 2a7a48b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/src/nodes/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ enum TaskKnownState {
Connected(PeerId),
}

impl TaskKnownState {
/// Returns `true` for `Pending`.
#[inline]
fn is_pending(&self) -> bool {
match *self {
TaskKnownState::Pending { .. } => true,
TaskKnownState::Interrupted => false,
TaskKnownState::Connected(_) => false,
}
}
}

/// Event that can happen on the `CollectionStream`.
// TODO: implement Debug
pub enum CollectionEvent<TMuxer, TUserData>
Expand Down Expand Up @@ -466,7 +478,9 @@ where

let replaced_node = self.nodes.insert(peer_id.clone(), (task_id, sender));
let user_datas = extract_from_attempt(&mut self.outbound_attempts, &peer_id);
if replaced_node.is_some() {
if let Some(replaced_node) = replaced_node {
let old = self.tasks.insert(replaced_node.0, TaskKnownState::Interrupted);
debug_assert_eq!(old.map(|s| s.is_pending()), Some(false));
Ok(Async::Ready(Some(CollectionEvent::NodeReplaced {
peer_id,
closed_outbound_substreams: user_datas,
Expand Down

0 comments on commit 2a7a48b

Please sign in to comment.