aboutsummaryrefslogtreecommitdiff
path: root/src/server/interaction
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-17 10:16:42 +0000
committerFuwn <[email protected]>2021-05-17 10:16:42 +0000
commit1b482ab22031ab9a895b2567ba10a2e553752303 (patch)
treedb4874c46b25655ba7c94b0ab435fdb0d681af55 /src/server/interaction
parentrefactor(global): whirl_config modulized (diff)
downloadwhirl-1b482ab22031ab9a895b2567ba10a2e553752303.tar.xz
whirl-1b482ab22031ab9a895b2567ba10a2e553752303.zip
refactor(global): even more modules becoming crates
I did multiple checks and **yes**, everything still works perfectly fine.
Diffstat (limited to 'src/server/interaction')
-rw-r--r--src/server/interaction/mod.rs5
-rw-r--r--src/server/interaction/peer.rs49
-rw-r--r--src/server/interaction/shared.rs28
3 files changed, 0 insertions, 82 deletions
diff --git a/src/server/interaction/mod.rs b/src/server/interaction/mod.rs
deleted file mode 100644
index c85e09d..0000000
--- a/src/server/interaction/mod.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-pub mod peer;
-pub mod shared;
diff --git a/src/server/interaction/peer.rs b/src/server/interaction/peer.rs
deleted file mode 100644
index 1d5ed9f..0000000
--- a/src/server/interaction/peer.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use std::sync::Arc;
-
-use tokio::{
- net::TcpStream,
- sync::{mpsc, Mutex},
-};
-use tokio_util::codec::{BytesCodec, Framed};
-
-use crate::server::{interaction::shared::Shared, types::Rx};
-
-pub struct Peer {
- pub bytes: Framed<TcpStream, BytesCodec>,
- pub rx: Rx,
-}
-impl Peer {
- pub async fn new(
- state: Arc<Mutex<Shared>>,
- bytes: Framed<TcpStream, BytesCodec>,
- username: String,
- ) -> std::io::Result<Peer> {
- let (tx, rx) = mpsc::unbounded_channel();
- state.lock().await.peers.insert(username, tx);
-
- Ok(Peer {
- bytes,
- rx,
- })
- }
-
- pub async fn _change_username(
- self,
- state: Arc<Mutex<Shared>>,
- username: &str,
- new_username: &str,
- ) {
- // Remove peer from peers
- {
- state.lock().await.peers.remove(username);
- }
-
- // Add the peer back with the new username
- Self::new(state, self.bytes, new_username.to_string())
- .await
- .unwrap();
- }
-}
diff --git a/src/server/interaction/shared.rs b/src/server/interaction/shared.rs
deleted file mode 100644
index c9eebbc..0000000
--- a/src/server/interaction/shared.rs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use std::collections::HashMap;
-
-use bytes::BytesMut;
-
-use crate::server::types::Tx;
-
-pub struct Shared {
- pub peers: HashMap<String, Tx>,
-}
-impl Shared {
- pub fn new() -> Self {
- Shared {
- peers: HashMap::new(),
- }
- }
-
- pub async fn broadcast(&mut self, message: &[u8]) {
- for peer in self.peers.iter_mut() {
- peer.1.send(BytesMut::from(message)).unwrap();
- }
- }
-}
-impl Default for Shared {
- fn default() -> Self { Self::new() }
-}