aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-06-14 13:44:08 +0200
committerEskil Queseth <eskilq@kth.se>2021-06-14 13:44:08 +0200
commitf24f23faa240053b7ac8f65b69ff8d1ae0ad3ea1 (patch)
treeb3c6406951d9e09836336290b63ceaa9d7efc04b /mumd/src
parentf4beab72096060f513d6b22c0ee891688595dcbd (diff)
downloadmum-f24f23faa240053b7ac8f65b69ff8d1ae0ad3ea1.tar.gz
clippy
Diffstat (limited to 'mumd/src')
-rw-r--r--mumd/src/audio/input.rs4
-rw-r--r--mumd/src/audio/output.rs4
-rw-r--r--mumd/src/client.rs2
-rw-r--r--mumd/src/main.rs13
-rw-r--r--mumd/src/network.rs4
-rw-r--r--mumd/src/network/tcp.rs21
-rw-r--r--mumd/src/network/udp.rs19
-rw-r--r--mumd/src/state.rs23
-rw-r--r--mumd/src/state/server.rs2
9 files changed, 42 insertions, 50 deletions
diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs
index 2a904d9..88efa62 100644
--- a/mumd/src/audio/input.rs
+++ b/mumd/src/audio/input.rs
@@ -161,12 +161,12 @@ impl AudioInputDevice for DefaultAudioInputDevice {
fn play(&self) -> Result<(), AudioError> {
self.stream
.play()
- .map_err(|e| AudioError::InputPlayError(e))
+ .map_err(AudioError::InputPlayError)
}
fn pause(&self) -> Result<(), AudioError> {
self.stream
.pause()
- .map_err(|e| AudioError::InputPauseError(e))
+ .map_err(AudioError::InputPauseError)
}
fn set_volume(&self, volume: f32) {
self.volume_sender.send(volume).unwrap();
diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs
index cdbe336..7487af2 100644
--- a/mumd/src/audio/output.rs
+++ b/mumd/src/audio/output.rs
@@ -191,13 +191,13 @@ impl AudioOutputDevice for DefaultAudioOutputDevice {
fn play(&self) -> Result<(), AudioError> {
self.stream
.play()
- .map_err(|e| AudioError::OutputPlayError(e))
+ .map_err(AudioError::OutputPlayError)
}
fn pause(&self) -> Result<(), AudioError> {
self.stream
.pause()
- .map_err(|e| AudioError::OutputPauseError(e))
+ .map_err(AudioError::OutputPauseError)
}
fn set_volume(&self, volume: f32) {
diff --git a/mumd/src/client.rs b/mumd/src/client.rs
index 9e8ca18..753583f 100644
--- a/mumd/src/client.rs
+++ b/mumd/src/client.rs
@@ -33,7 +33,7 @@ pub async fn handle(
packet_sender.clone(),
packet_receiver,
event_queue.clone(),
- ).fuse() => r.map_err(|e| ClientError::TcpError(e)),
+ ).fuse() => r.map_err(ClientError::TcpError),
_ = udp::handle(
Arc::clone(&state),
connection_info_receiver.clone(),
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index 8d278c0..6a70586 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -37,9 +37,7 @@ use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
#[tokio::main]
async fn main() {
- if std::env::args()
- .find(|s| s.as_str() == "--version")
- .is_some()
+ if std::env::args().any(|s| s.as_str() == "--version")
{
println!("mumd {}", env!("VERSION"));
return;
@@ -94,12 +92,9 @@ async fn main() {
_ = receive_commands(command_sender).fuse() => Ok(()),
};
- match run {
- Err(e) => {
- error!("mumd: {}", e);
- std::process::exit(1);
- }
- _ => {}
+ if let Err(e) = run {
+ error!("mumd: {}", e);
+ std::process::exit(1);
}
}
diff --git a/mumd/src/network.rs b/mumd/src/network.rs
index 2b803c0..1066fef 100644
--- a/mumd/src/network.rs
+++ b/mumd/src/network.rs
@@ -30,8 +30,8 @@ impl ConnectionInfo {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum VoiceStreamType {
- TCP,
- UDP,
+ Tcp,
+ Udp,
}
async fn run_until<F, R>(
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs
index f68dd31..0fdc4c5 100644
--- a/mumd/src/network/tcp.rs
+++ b/mumd/src/network/tcp.rs
@@ -75,7 +75,7 @@ impl From<&TcpEventData<'_>> for TcpEvent {
}
}
-#[derive(Clone)]
+#[derive(Clone, Default)]
pub struct TcpEventQueue {
callbacks: Arc<RwLock<HashMap<TcpEvent, Vec<TcpEventCallback>>>>,
subscribers: Arc<RwLock<HashMap<TcpEvent, Vec<TcpEventSubscriber>>>>,
@@ -156,13 +156,14 @@ pub async fn handle(
event_queue: TcpEventQueue,
) -> Result<(), TcpError> {
loop {
- let connection_info = 'data: loop {
- while connection_info_receiver.changed().await.is_ok() {
+ let connection_info = loop {
+ if connection_info_receiver.changed().await.is_ok() {
if let Some(data) = connection_info_receiver.borrow().clone() {
- break 'data data;
+ break data;
}
+ } else {
+ return Err(TcpError::NoConnectionInfoReceived);
}
- return Err(TcpError::NoConnectionInfoReceived);
};
let connect_result = connect(
connection_info.socket_addr,
@@ -250,12 +251,12 @@ async fn connect(
builder.danger_accept_invalid_certs(accept_invalid_cert);
let connector: TlsConnector = builder
.build()
- .map_err(|e| TcpError::TlsConnectorBuilderError(e))?
+ .map_err(TcpError::TlsConnectorBuilderError)?
.into();
let tls_stream = connector
.connect(&server_host, stream)
.await
- .map_err(|e| TcpError::TlsConnectError(e))?;
+ .map_err(TcpError::TlsConnectError)?;
debug!("TLS connected");
// Wrap the TLS stream with Mumble's client-side control-channel codec
@@ -312,13 +313,13 @@ async fn send_voice(
inner_phase_watcher.changed().await.unwrap();
if matches!(
*inner_phase_watcher.borrow(),
- StatePhase::Connected(VoiceStreamType::TCP)
+ StatePhase::Connected(VoiceStreamType::Tcp)
) {
break;
}
}
run_until(
- |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::TCP)),
+ |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::Tcp)),
async {
loop {
packet_sender.send(
@@ -473,7 +474,7 @@ async fn listen(
..
} => {
state.read().unwrap().audio_output().decode_packet_payload(
- VoiceStreamType::TCP,
+ VoiceStreamType::Tcp,
session_id,
payload,
);
diff --git a/mumd/src/network/udp.rs b/mumd/src/network/udp.rs
index 95dcf33..0f78638 100644
--- a/mumd/src/network/udp.rs
+++ b/mumd/src/network/udp.rs
@@ -37,13 +37,14 @@ pub async fn handle(
let receiver = state.read().unwrap().audio_input().receiver();
loop {
- let connection_info = 'data: loop {
- while connection_info_receiver.changed().await.is_ok() {
+ let connection_info = loop {
+ if connection_info_receiver.changed().await.is_ok() {
if let Some(data) = connection_info_receiver.borrow().clone() {
- break 'data data;
+ break data;
}
+ } else {
+ return Err(UdpError::NoConnectionInfoReceived);
}
- return Err(UdpError::NoConnectionInfoReceived);
};
let (sink, source) = connect(&mut crypt_state_receiver).await?;
@@ -136,7 +137,7 @@ async fn listen(
state
.read()
.unwrap()
- .broadcast_phase(StatePhase::Connected(VoiceStreamType::UDP));
+ .broadcast_phase(StatePhase::Connected(VoiceStreamType::Udp));
last_ping_recv.store(timestamp, Ordering::Relaxed);
}
VoicePacket::Audio {
@@ -147,7 +148,7 @@ async fn listen(
..
} => {
state.read().unwrap().audio_output().decode_packet_payload(
- VoiceStreamType::UDP,
+ VoiceStreamType::Udp,
session_id,
payload,
);
@@ -173,7 +174,7 @@ async fn send_pings(
state
.read()
.unwrap()
- .broadcast_phase(StatePhase::Connected(VoiceStreamType::TCP));
+ .broadcast_phase(StatePhase::Connected(VoiceStreamType::Tcp));
}
match sink
.lock()
@@ -208,13 +209,13 @@ async fn send_voice(
inner_phase_watcher.changed().await.unwrap();
if matches!(
*inner_phase_watcher.borrow(),
- StatePhase::Connected(VoiceStreamType::UDP)
+ StatePhase::Connected(VoiceStreamType::Udp)
) {
break;
}
}
run_until(
- |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::UDP)),
+ |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::Udp)),
async {
let mut receiver = receiver.lock().await;
loop {
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index 82810de..a1344a1 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -43,18 +43,13 @@ macro_rules! now {
type Responses = Box<dyn Iterator<Item = mumlib::error::Result<Option<CommandResponse>>>>;
+type TcpEventCallback = Box<dyn FnOnce(TcpEventData<'_>) -> Responses>;
+type TcpEventSubscriberCallback = Box<dyn FnMut(TcpEventData<'_>,&mut mpsc::UnboundedSender<mumlib::error::Result<Option<CommandResponse>>>,) -> bool>;
+
//TODO give me a better name
pub enum ExecutionContext {
- TcpEventCallback(Vec<(TcpEvent, Box<dyn FnOnce(TcpEventData<'_>) -> Responses>)>),
- TcpEventSubscriber(
- TcpEvent,
- Box<
- dyn FnMut(
- TcpEventData<'_>,
- &mut mpsc::UnboundedSender<mumlib::error::Result<Option<CommandResponse>>>,
- ) -> bool,
- >,
- ),
+ TcpEventCallback(Vec<(TcpEvent, TcpEventCallback)>),
+ TcpEventSubscriber(TcpEvent, TcpEventSubscriberCallback),
Now(Box<dyn FnOnce() -> Responses>),
Ping(
Box<dyn FnOnce() -> mumlib::error::Result<SocketAddr>>,
@@ -103,9 +98,9 @@ impl State {
config.audio.input_volume.unwrap_or(1.0),
phase_watcher.1.clone(),
)
- .map_err(|e| StateError::AudioError(e))?;
+ .map_err(StateError::AudioError)?;
let audio_output = AudioOutput::new(config.audio.output_volume.unwrap_or(1.0))
- .map_err(|e| StateError::AudioError(e))?;
+ .map_err(StateError::AudioError)?;
let mut state = Self {
config,
server: None,
@@ -321,7 +316,7 @@ impl State {
}
pub fn initialized(&self) {
- self.broadcast_phase(StatePhase::Connected(VoiceStreamType::TCP));
+ self.broadcast_phase(StatePhase::Connected(VoiceStreamType::Tcp));
self.audio_output
.play_effect(NotificationEvents::ServerConnect);
}
@@ -786,7 +781,7 @@ pub fn handle_command(
.unwrap()
.users()
.iter()
- .find(|(_, user)| user.name() == &name)
+ .find(|(_, user)| user.name() == name)
.map(|(e, _)| *e);
let id = match id {
diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs
index 4abde49..5d49457 100644
--- a/mumd/src/state/server.rs
+++ b/mumd/src/state/server.rs
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
-#[derive(Clone, Debug, Deserialize, Serialize)]
+#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Server {
channels: HashMap<u32, Channel>,
users: HashMap<u32, User>,