mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
ws: SwarmControlMessage::ConnectionClosed: use Vec for info hashes
This commit is contained in:
parent
4c831643b1
commit
36954e5f48
3 changed files with 22 additions and 18 deletions
|
|
@ -67,11 +67,10 @@ impl Into<OutMessageMeta> for InMessageMeta {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SwarmControlMessage {
|
||||
ConnectionClosed {
|
||||
info_hash: InfoHash,
|
||||
peer_id: PeerId,
|
||||
ip_version: IpVersion,
|
||||
announced_info_hashes: Vec<(InfoHash, PeerId)>,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -102,13 +102,14 @@ where
|
|||
while let Some(message) = stream.next().await {
|
||||
match message {
|
||||
SwarmControlMessage::ConnectionClosed {
|
||||
info_hash,
|
||||
peer_id,
|
||||
ip_version,
|
||||
announced_info_hashes,
|
||||
} => {
|
||||
torrents
|
||||
.borrow_mut()
|
||||
.handle_connection_closed(info_hash, peer_id, ip_version);
|
||||
let mut torrents = torrents.borrow_mut();
|
||||
|
||||
for (info_hash, peer_id) in announced_info_hashes {
|
||||
torrents.handle_connection_closed(info_hash, peer_id, ip_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue