blob: 4e1d158a7e180411fcf3016c69e031233641a3e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
use {bytes::BytesMut, std::collections::HashMap};
pub struct Shared {
pub peers: HashMap<String, tokio::sync::mpsc::UnboundedSender<BytesMut>>,
}
impl Shared {
pub fn new() -> Self { Self { peers: HashMap::new() } }
#[allow(clippy::unused_async)]
pub async fn broadcast(&mut self, message: &[u8]) {
for peer in &mut self.peers {
peer.1.send(BytesMut::from(message)).unwrap();
}
}
}
impl Default for Shared {
fn default() -> Self { Self::new() }
}
|