aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-06-19 20:07:17 +0200
committerEskil Queseth <eskilq@kth.se>2021-06-19 20:07:17 +0200
commit9002462953e7cba70d5aafee7ed2a87087252f49 (patch)
tree88c51f4f6cda71647ec5ed69cb3700d9bb7f4d5f
parentb2e9021341794ab52edcf4598c8d454515f758c4 (diff)
parent9aca7a8c930b179b6ae539234296f529928a3f3a (diff)
downloadmum-9002462953e7cba70d5aafee7ed2a87087252f49.tar.gz
Merge branch 'lints'
-rw-r--r--Cargo.lock49
-rw-r--r--mumctl/src/main.rs37
-rw-r--r--mumd/Cargo.toml4
-rw-r--r--mumd/src/audio.rs10
-rw-r--r--mumd/src/audio/input.rs16
-rw-r--r--mumd/src/audio/output.rs18
-rw-r--r--mumd/src/audio/transformers.rs1
-rw-r--r--mumd/src/client.rs2
-rw-r--r--mumd/src/error.rs6
-rw-r--r--mumd/src/main.rs43
-rw-r--r--mumd/src/network.rs4
-rw-r--r--mumd/src/network/tcp.rs41
-rw-r--r--mumd/src/network/udp.rs19
-rw-r--r--mumd/src/state.rs43
-rw-r--r--mumd/src/state/server.rs2
-rw-r--r--mumd/src/state/user.rs2
-rw-r--r--mumlib/src/config.rs2
-rw-r--r--mumlib/src/lib.rs16
-rw-r--r--mumlib/src/state.rs2
19 files changed, 203 insertions, 114 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2f4bb07..1161c63 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "alsa"
version = "0.5.0"
@@ -686,9 +688,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
-version = "0.2.95"
+version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36"
+checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "libloading"
@@ -817,10 +819,8 @@ dependencies = [
"bytes",
"chrono",
"cpal",
- "dasp_frame",
"dasp_interpolate",
"dasp_ring_buffer",
- "dasp_sample",
"dasp_signal",
"futures-channel",
"futures-util",
@@ -830,14 +830,12 @@ dependencies = [
"mumble-protocol",
"mumlib",
"native-tls",
- "openssl",
"opus",
"serde",
"strum",
"strum_macros",
"tokio",
"tokio-native-tls",
- "tokio-stream",
"tokio-util",
]
@@ -1035,9 +1033,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.7.2"
+version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
+checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]]
name = "openssl"
@@ -1203,24 +1201,24 @@ dependencies = [
[[package]]
name = "protobuf"
-version = "2.23.0"
+version = "2.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "45604fc7a88158e7d514d8e22e14ac746081e7a70d7690074dd0029ee37458d6"
+checksum = "db50e77ae196458ccd3dc58a31ea1a90b0698ab1b7928d89f644c25d72070267"
[[package]]
name = "protobuf-codegen"
-version = "2.23.0"
+version = "2.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb87f342b585958c1c086313dbc468dcac3edf5e90362111c26d7a58127ac095"
+checksum = "09321cef9bee9ddd36884f97b7f7cc92a586cdc74205c4b3aeba65b5fc9c6f90"
dependencies = [
"protobuf",
]
[[package]]
name = "protobuf-codegen-pure"
-version = "2.23.0"
+version = "2.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ca6e0e2f898f7856a6328650abc9b2df71b7c1a5f39be0800d19051ad0214b2"
+checksum = "1afb68a6d768571da3db86ce55f0f62966e0fc25eaf96acd070ea548a91b0d23"
dependencies = [
"protobuf",
"protobuf-codegen",
@@ -1249,9 +1247,9 @@ dependencies = [
[[package]]
name = "rand_chacha"
-version = "0.3.0"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
@@ -1351,9 +1349,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "security-framework"
-version = "2.3.0"
+version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b239a3d5db51252f6f48f42172c65317f37202f4a21021bf5f9d40a408f4592c"
+checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467"
dependencies = [
"bitflags",
"core-foundation",
@@ -1472,9 +1470,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.72"
+version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
+checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [
"proc-macro2",
"quote",
@@ -1570,17 +1568,6 @@ dependencies = [
]
[[package]]
-name = "tokio-stream"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8864d706fdb3cc0843a49647ac892720dac98a6eeb818b77190592cf4994066"
-dependencies = [
- "futures-core",
- "pin-project-lite",
- "tokio",
-]
-
-[[package]]
name = "tokio-util"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs
index 5b2bc05..adb449d 100644
--- a/mumctl/src/main.rs
+++ b/mumctl/src/main.rs
@@ -1,5 +1,20 @@
+#![warn(elided_lifetimes_in_paths)]
+#![warn(meta_variable_misuse)]
+#![warn(missing_debug_implementations)]
+#![warn(single_use_lifetimes)]
+#![warn(unreachable_pub)]
+#![warn(unused_crate_dependencies)]
+#![warn(unused_import_braces)]
+#![warn(unused_lifetimes)]
+#![warn(unused_qualifications)]
+#![deny(macro_use_extern_crate)]
+#![deny(missing_abi)]
+#![deny(future_incompatible)]
+#![forbid(unsafe_code)]
+#![forbid(non_ascii_idents)]
+
use colored::Colorize;
-use log::*;
+use log::{Level, LevelFilter, Metadata, Record, error, warn};
use mumlib::command::{ChannelTarget, Command as MumCommand, CommandResponse, MessageTarget};
use mumlib::config::{self, Config, ServerConfig};
use mumlib::state::Channel as MumChannel;
@@ -17,11 +32,11 @@ const INDENTATION: &str = " ";
struct SimpleLogger;
impl log::Log for SimpleLogger {
- fn enabled(&self, metadata: &Metadata) -> bool {
+ fn enabled(&self, metadata: &Metadata<'_>) -> bool {
metadata.level() <= Level::Info
}
- fn log(&self, record: &Record) {
+ fn log(&self, record: &Record<'_>) {
if self.enabled(record.metadata()) {
println!(
"{}{}",
@@ -252,9 +267,9 @@ fn match_opt() -> Result<(), Error> {
server
.username
.as_ref()
- .or(username.as_ref())
+ .or_else(|| username.as_ref())
.ok_or(CliError::NoUsername)?,
- server.password.as_ref().or(password.as_ref()),
+ server.password.as_ref().or_else(|| password.as_ref()),
server.port.unwrap_or(port),
server.accept_invalid_cert,
),
@@ -521,7 +536,7 @@ fn match_server_command(server_command: Server, config: &mut Config) -> Result<(
(Some("port"), None) => {
println!(
"{}",
- server.port.ok_or(CliError::NotSet("port".to_string()))?
+ server.port.ok_or_else(|| CliError::NotSet("port".to_string()))?
);
}
(Some("username"), None) => {
@@ -530,7 +545,7 @@ fn match_server_command(server_command: Server, config: &mut Config) -> Result<(
server
.username
.as_ref()
- .ok_or(CliError::NotSet("username".to_string()))?
+ .ok_or_else(|| CliError::NotSet("username".to_string()))?
);
}
(Some("password"), None) => {
@@ -539,7 +554,7 @@ fn match_server_command(server_command: Server, config: &mut Config) -> Result<(
server
.password
.as_ref()
- .ok_or(CliError::NotSet("password".to_string()))?
+ .ok_or_else(|| CliError::NotSet("password".to_string()))?
);
}
(Some("accept_invalid_cert"), None) => {
@@ -548,11 +563,11 @@ fn match_server_command(server_command: Server, config: &mut Config) -> Result<(
server
.accept_invalid_cert
.map(|b| b.to_string())
- .ok_or(CliError::NotSet("accept_invalid_cert".to_string()))?
+ .ok_or_else(|| CliError::NotSet("accept_invalid_cert".to_string()))?
);
}
(Some("name"), Some(_)) => {
- return Err(CliError::UseServerRename)?;
+ return Err(CliError::UseServerRename.into());
}
(Some("host"), Some(value)) => {
server.host = value;
@@ -574,7 +589,7 @@ fn match_server_command(server_command: Server, config: &mut Config) -> Result<(
}
}
(Some(_), _) => {
- return Err(CliError::ConfigKeyNotFound(key.unwrap()))?;
+ return Err(CliError::ConfigKeyNotFound(key.unwrap()).into());
}
}
}
diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml
index 1e8e63f..28ff2ce 100644
--- a/mumd/Cargo.toml
+++ b/mumd/Cargo.toml
@@ -23,8 +23,6 @@ cpal = "0.13"
bytes = "1.0"
dasp_interpolate = { version = "0.11", features = ["linear"] }
dasp_signal = "0.11"
-dasp_frame = "0.11"
-dasp_sample = "0.11"
dasp_ring_buffer = "0.11"
futures-util = { version = "0.3", features = ["sink"]}
futures-channel = "0.3"
@@ -32,13 +30,11 @@ hound = "3.4"
log = "0.4"
mumble-protocol = "0.4.1"
native-tls = "0.2"
-openssl = { version = "0.10" }
opus = "0.2"
serde = { version = "1.0", features = ["derive"] }
strum = "0.20"
strum_macros = "0.20"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "fs"] }
-tokio-stream = "0.1.0"
tokio-native-tls = "0.3"
tokio-util = { version = "0.6", features = ["codec", "net"] }
bincode = "1.3.2"
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index 0424033..6860741 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -122,6 +122,16 @@ impl AudioInput {
}
}
+impl Debug for AudioInput {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("AudioInput")
+ .field("device", &self.device)
+ .field("channel_receiver", &"receiver")
+ .finish()
+ }
+}
+
+#[derive(Debug)]
/// Audio output state. The audio is received from each client over the network,
/// decoded, merged and finally played to an [AudioOutputDevice] (e.g. speaker,
/// headphones, ...).
diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs
index 37ea60a..4dfc465 100644
--- a/mumd/src/audio/input.rs
+++ b/mumd/src/audio/input.rs
@@ -2,6 +2,7 @@
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{InputCallbackInfo, Sample, SampleFormat, SampleRate, StreamConfig};
use log::*;
+use std::fmt::Debug;
use tokio::sync::watch;
use crate::audio::SAMPLE_RATE;
@@ -171,13 +172,13 @@ 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) {
@@ -192,3 +193,14 @@ impl AudioInputDevice for DefaultAudioInputDevice {
self.channels as usize
}
}
+
+impl Debug for DefaultAudioInputDevice {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DefaultAudioInputDevice")
+ .field("sample_receiver", &self.sample_receiver)
+ .field("channels", &self.channels)
+ .field("volume_sender", &self.volume_sender)
+ .field("stream", &"cpal::Stream")
+ .finish()
+ }
+}
diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs
index b945710..6cec6fc 100644
--- a/mumd/src/audio/output.rs
+++ b/mumd/src/audio/output.rs
@@ -11,6 +11,7 @@ use dasp_ring_buffer::Bounded;
use log::*;
use mumble_protocol::voice::VoicePacketPayload;
use std::collections::{HashMap, VecDeque};
+use std::fmt::Debug;
use std::iter;
use std::ops::AddAssign;
use std::sync::{Arc, Mutex};
@@ -19,6 +20,7 @@ use tokio::sync::watch;
type ClientStreamKey = (VoiceStreamType, u32);
/// State for decoding audio received from another user.
+#[derive(Debug)]
pub struct ClientAudioData {
buf: Bounded<Vec<f32>>,
output_channels: opus::Channels,
@@ -66,6 +68,7 @@ impl ClientAudioData {
}
/// Collected state for client opus decoders and sound effects.
+#[derive(Debug)]
pub struct ClientStream {
buffer_clients: HashMap<ClientStreamKey, ClientAudioData>,
buffer_effects: VecDeque<f32>,
@@ -243,13 +246,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) {
@@ -298,3 +301,14 @@ pub fn callback<T: Sample + AddAssign + SaturatingAdd + std::fmt::Display>(
}
}
}
+
+impl Debug for DefaultAudioOutputDevice {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DefaultAudioInputDevice")
+ .field("client_streams", &self.client_streams)
+ .field("config", &self.config)
+ .field("volume_sender", &self.volume_sender)
+ .field("stream", &"cpal::Stream")
+ .finish()
+ }
+}
diff --git a/mumd/src/audio/transformers.rs b/mumd/src/audio/transformers.rs
index 91cf3ac..21a71b5 100644
--- a/mumd/src/audio/transformers.rs
+++ b/mumd/src/audio/transformers.rs
@@ -6,6 +6,7 @@ pub trait Transformer {
}
/// A struct representing a noise gate transform.
+#[derive(Debug)]
pub struct NoiseGate {
alltime_high: f32,
open: usize,
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/error.rs b/mumd/src/error.rs
index da1bdd3..4277d7f 100644
--- a/mumd/src/error.rs
+++ b/mumd/src/error.rs
@@ -5,6 +5,7 @@ use tokio::sync::mpsc;
pub type ServerSendError = mpsc::error::SendError<ControlPacket<Serverbound>>;
+#[derive(Debug)]
pub enum TcpError {
NoConnectionInfoReceived,
TlsConnectorBuilderError(native_tls::Error),
@@ -40,6 +41,7 @@ impl From<ServerSendError> for TcpError {
}
}
+#[derive(Debug)]
pub enum UdpError {
NoConnectionInfoReceived,
DisconnectBeforeCryptSetup,
@@ -53,6 +55,7 @@ impl From<std::io::Error> for UdpError {
}
}
+#[derive(Debug)]
pub enum ClientError {
TcpError(TcpError),
}
@@ -65,6 +68,7 @@ impl fmt::Display for ClientError {
}
}
+#[derive(Debug)]
pub enum AudioStream {
Input,
Output,
@@ -79,6 +83,7 @@ impl fmt::Display for AudioStream {
}
}
+#[derive(Debug)]
pub enum AudioError {
NoDevice(AudioStream),
NoConfigs(AudioStream, cpal::SupportedStreamConfigsError),
@@ -105,6 +110,7 @@ impl fmt::Display for AudioError {
}
}
+#[derive(Debug)]
pub enum StateError {
AudioError(AudioError),
ConfigError(ConfigError),
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index bc72779..479c568 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -1,10 +1,25 @@
-mod audio;
-mod client;
-mod command;
-mod error;
-mod network;
-mod notifications;
-mod state;
+#![warn(elided_lifetimes_in_paths)]
+#![warn(meta_variable_misuse)]
+#![warn(missing_debug_implementations)]
+#![warn(single_use_lifetimes)]
+#![warn(unreachable_pub)]
+#![warn(unused_crate_dependencies)]
+#![warn(unused_import_braces)]
+#![warn(unused_lifetimes)]
+#![warn(unused_qualifications)]
+#![deny(macro_use_extern_crate)]
+#![deny(missing_abi)]
+#![deny(future_incompatible)]
+#![forbid(unsafe_code)]
+#![forbid(non_ascii_idents)]
+
+pub mod audio;
+pub mod client;
+pub mod command;
+pub mod error;
+pub mod network;
+pub mod notifications;
+pub mod state;
use crate::state::State;
@@ -22,10 +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;
}
@@ -79,12 +91,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 f620a32..0fdc4c5 100644
--- a/mumd/src/network/tcp.rs
+++ b/mumd/src/network/tcp.rs
@@ -14,6 +14,7 @@ use mumble_protocol::{Clientbound, Serverbound};
use mumlib::command::MumbleEventKind;
use std::collections::HashMap;
use std::convert::{Into, TryInto};
+use std::fmt::Debug;
use std::net::SocketAddr;
use std::sync::{Arc, RwLock};
use tokio::net::TcpStream;
@@ -31,8 +32,8 @@ type TcpSender = SplitSink<
type TcpReceiver =
SplitStream<Framed<TlsStream<TcpStream>, ControlCodec<Serverbound, Clientbound>>>;
-pub(crate) type TcpEventCallback = Box<dyn FnOnce(TcpEventData)>;
-pub(crate) type TcpEventSubscriber = Box<dyn FnMut(TcpEventData) -> bool>; //the bool indicates if it should be kept or not
+pub(crate) type TcpEventCallback = Box<dyn FnOnce(TcpEventData<'_>)>;
+pub(crate) type TcpEventSubscriber = Box<dyn FnMut(TcpEventData<'_>) -> bool>; //the bool indicates if it should be kept or not
/// Why the TCP was disconnected.
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
@@ -57,15 +58,15 @@ pub enum TcpEvent {
/// Having two different types might feel a bit confusing. Essentially, a
/// callback _registers_ to a [TcpEvent] but _takes_ a [TcpEventData] as
/// parameter.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub enum TcpEventData<'a> {
Connected(Result<&'a msgs::ServerSync, mumlib::Error>),
Disconnected(DisconnectedReason),
TextMessage(&'a msgs::TextMessage),
}
-impl<'a> From<&TcpEventData<'a>> for TcpEvent {
- fn from(t: &TcpEventData) -> Self {
+impl From<&TcpEventData<'_>> for TcpEvent {
+ fn from(t: &TcpEventData<'_>) -> Self {
match t {
TcpEventData::Connected(_) => TcpEvent::Connected,
TcpEventData::Disconnected(reason) => TcpEvent::Disconnected(*reason),
@@ -74,7 +75,7 @@ impl<'a> From<&TcpEventData<'a>> for TcpEvent {
}
}
-#[derive(Clone)]
+#[derive(Clone, Default)]
pub struct TcpEventQueue {
callbacks: Arc<RwLock<HashMap<TcpEvent, Vec<TcpEventCallback>>>>,
subscribers: Arc<RwLock<HashMap<TcpEvent, Vec<TcpEventSubscriber>>>>,
@@ -111,7 +112,7 @@ impl TcpEventQueue {
/// Fires all callbacks related to a specific TCP event and removes them from the event queue.
/// Also calls all event subscribers, but keeps them in the queue
- pub fn resolve<'a>(&self, data: TcpEventData<'a>) {
+ pub fn resolve(&self, data: TcpEventData<'_>) {
if let Some(vec) = self
.callbacks
.write()
@@ -139,6 +140,13 @@ impl TcpEventQueue {
}
}
+impl Debug for TcpEventQueue {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("TcpEventQueue")
+ .finish()
+ }
+}
+
pub async fn handle(
state: Arc<RwLock<State>>,
mut connection_info_receiver: watch::Receiver<Option<ConnectionInfo>>,
@@ -148,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,
@@ -242,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
@@ -304,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(
@@ -465,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 d2d77b1..1992884 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -20,6 +20,7 @@ use mumlib::command::{ChannelTarget, Command, CommandResponse, MessageTarget, Mu
use mumlib::config::Config;
use mumlib::Error;
use std::{
+ fmt::Debug,
iter,
net::{SocketAddr, ToSocketAddrs},
sync::{Arc, RwLock},
@@ -29,7 +30,7 @@ use tokio::sync::{mpsc, watch};
macro_rules! at {
( $( $event:expr => $generator:expr ),+ $(,)? ) => {
ExecutionContext::TcpEventCallback(vec![
- $( ($event, Box::new($generator)), )*
+ $( ($event, Box::new($generator)), )+
])
};
}
@@ -42,18 +43,18 @@ 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>>,
@@ -63,6 +64,17 @@ pub enum ExecutionContext {
),
}
+impl Debug for ExecutionContext {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_tuple(match self {
+ ExecutionContext::TcpEventCallback(_) => "TcpEventCallback",
+ ExecutionContext::TcpEventSubscriber(_, _) => "TcpEventSubscriber",
+ ExecutionContext::Now(_) => "Now",
+ ExecutionContext::Ping(_, _) => "Ping",
+ }).finish()
+ }
+}
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StatePhase {
Disconnected,
@@ -70,6 +82,7 @@ pub enum StatePhase {
Connected(VoiceStreamType),
}
+#[derive(Debug)]
pub struct State {
config: Config,
server: Option<Server>,
@@ -90,9 +103,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,
@@ -308,7 +321,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);
}
@@ -773,7 +786,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>,
diff --git a/mumd/src/state/user.rs b/mumd/src/state/user.rs
index 5770bca..0ffde90 100644
--- a/mumd/src/state/user.rs
+++ b/mumd/src/state/user.rs
@@ -78,7 +78,7 @@ impl User {
}
}
- pub fn apply_user_diff(&mut self, diff: &crate::state::user::UserDiff) {
+ pub fn apply_user_diff(&mut self, diff: &UserDiff) {
if let Some(comment) = diff.comment.clone() {
self.comment = Some(comment);
}
diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs
index 932e013..c2544e8 100644
--- a/mumlib/src/config.rs
+++ b/mumlib/src/config.rs
@@ -197,7 +197,7 @@ pub fn read_cfg(path: &Path) -> Result<Config, ConfigError> {
} else {
error!("Error reading config file: {}", e);
}
- return Ok(Config::default());
+ Ok(Config::default())
}
}
}
diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs
index 679db8d..2282df5 100644
--- a/mumlib/src/lib.rs
+++ b/mumlib/src/lib.rs
@@ -1,6 +1,20 @@
+#![warn(elided_lifetimes_in_paths)]
+#![warn(meta_variable_misuse)]
+#![warn(missing_debug_implementations)]
+#![warn(single_use_lifetimes)]
+#![warn(unreachable_pub)]
+#![warn(unused_crate_dependencies)]
+#![warn(unused_import_braces)]
+#![warn(unused_lifetimes)]
+#![warn(unused_qualifications)]
+// #![warn(missing_docs)] may be enabled later when more is documented
+#![deny(macro_use_extern_crate)]
+#![deny(missing_abi)]
+#![deny(future_incompatible)]
+#![forbid(unsafe_code)]
+#![forbid(non_ascii_idents)]
//! Shared items for crates that want to communicate with mumd and/or mumctl.
-// #![warn(missing_docs)]
pub mod command;
pub mod config;
diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs
index 72c01a6..5008465 100644
--- a/mumlib/src/state.rs
+++ b/mumlib/src/state.rs
@@ -82,6 +82,7 @@ impl Channel {
}
/// An iterator over channels. Created by [Channel::iter].
+#[derive(Debug)]
pub struct Iter<'a> {
me: Option<&'a Channel>,
channel: Option<usize>,
@@ -113,6 +114,7 @@ impl<'a> Iterator for Iter<'a> {
}
/// An iterator over users. Created by [Channel::users_iter].
+#[derive(Debug)]
pub struct UsersIter<'a> {
channel: Option<usize>,
channels: Vec<UsersIter<'a>>,