Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
fix: restored inject_connected and inject_disconnected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rand0m-cloud committed Mar 14, 2022
1 parent cdc9a7c commit b5df04a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/p2p/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@ impl NetworkBehaviour for SwarmApi {
}
}
}

// we have at least one fully open connection and handler is running
//
// just finish all of the subscriptions that remain.
trace!("inject connected {}", peer_id);

let all_subs = self
.pending_addresses
.remove(peer_id)
.unwrap_or_default()
.into_iter()
.chain(
self.pending_connections
.remove(peer_id)
.unwrap_or_default()
.into_iter(),
);

for addr in all_subs {
// fail the other than already connected subscriptions in
// inject_connection_established. while the whole swarmapi is quite unclear on the
// actual use cases, assume that connecting one is good enough for all outstanding
// connection requests.
self.connect_registry.finish_subscription(
addr.into(),
Err("finished connecting to another address".into()),
);
}
}

fn inject_connection_closed(
Expand Down Expand Up @@ -294,6 +322,27 @@ impl NetworkBehaviour for SwarmApi {
// we were not dialing to the peer, thus we cannot have a pending subscription to
// finish.
}

trace!("inject_disconnected: {}", peer_id);
assert!(!self.connected_peers.contains_key(peer_id));
self.roundtrip_times.remove(peer_id);

let failed = self
.pending_addresses
.remove(peer_id)
.unwrap_or_default()
.into_iter()
.chain(
self.pending_connections
.remove(peer_id)
.unwrap_or_default()
.into_iter(),
);

for addr in failed {
self.connect_registry
.finish_subscription(addr.into(), Err("disconnected".into()));
}
}

fn inject_event(&mut self, _peer_id: PeerId, _connection: ConnectionId, _event: void::Void) {}
Expand Down

0 comments on commit b5df04a

Please sign in to comment.