ws: SwarmControlMessage::ConnectionClosed: use Vec for info hashes

This commit is contained in:
Joakim Frostegård 2024-01-08 18:50:17 +01:00
parent 4c831643b1
commit 36954e5f48
3 changed files with 22 additions and 18 deletions

View file

@ -599,19 +599,23 @@ impl ConnectionCleanupData {
config: &Config,
control_message_senders: Rc<Senders<SwarmControlMessage>>,
) {
// Use RefCell::take to avoid issues with Rc borrow across await
let announced_info_hashes = self.announced_info_hashes.take();
// Tell swarm workers to remove peer
for (info_hash, peer_id) in announced_info_hashes.into_iter() {
let message = SwarmControlMessage::ConnectionClosed {
info_hash,
peer_id,
ip_version: self.ip_version,
};
let mut announced_info_hashes = HashMap::new();
for (info_hash, peer_id) in self.announced_info_hashes.take().into_iter() {
let consumer_index = calculate_in_message_consumer_index(&config, info_hash);
announced_info_hashes
.entry(consumer_index)
.or_insert(Vec::new())
.push((info_hash, peer_id));
}
for (consumer_index, announced_info_hashes) in announced_info_hashes.into_iter() {
let message = SwarmControlMessage::ConnectionClosed {
ip_version: self.ip_version,
announced_info_hashes,
};
control_message_senders
.send_to(consumer_index, message)
.await