diff --git a/sable_ircd/src/command/error.rs b/sable_ircd/src/command/error.rs index 2d40fc8c..7b22a7e4 100644 --- a/sable_ircd/src/command/error.rs +++ b/sable_ircd/src/command/error.rs @@ -12,9 +12,9 @@ use crate::errors::HandlerError; #[derive(Debug)] pub enum CommandError { /// Something returned an `Error` that we don't know how to handle - UnderlyingError(anyhow::Error), + UnderlyingError(#[allow(unused)] anyhow::Error), /// Something went wrong but we don't have an `Error` impl for it - UnknownError(String), + UnknownError(#[allow(unused)] String), /* /// The command couldn't be processed successfully, and the client has already been /// notified @@ -49,24 +49,6 @@ pub enum CommandError { Numeric(messages::UntargetedNumeric), } -impl From for CommandError { - fn from(e: ValidationError) -> Self { - match e { - ValidationError::NickInUse(n) => numeric::NicknameInUse::new(&n).into(), - ValidationError::ObjectNotFound(le) => match le { - LookupError::NoSuchNick(n) => numeric::NoSuchTarget::new(&n).into(), - LookupError::NoSuchChannelName(n) => numeric::NoSuchTarget::new(n.as_ref()).into(), - _ => CommandError::UnknownError(le.to_string()), - }, - ValidationError::InvalidNickname(e) => numeric::ErroneousNickname::new(&e.0).into(), - ValidationError::InvalidChannelName(e) => numeric::InvalidChannelName::new(&e.0).into(), - ValidationError::InvalidUsername(e) => CommandError::UnknownError(e.0), - ValidationError::InvalidHostname(e) => CommandError::UnknownError(e.0), - ValidationError::WrongTypeId(e) => CommandError::UnknownError(e.to_string()), - } - } -} - impl From for CommandError { fn from(e: policy::PermissionError) -> Self { /* diff --git a/sable_ircd/src/command/handlers/userhost.rs b/sable_ircd/src/command/handlers/userhost.rs index 77f4d976..77a8b74b 100644 --- a/sable_ircd/src/command/handlers/userhost.rs +++ b/sable_ircd/src/command/handlers/userhost.rs @@ -2,7 +2,7 @@ use super::*; use itertools::Itertools; /// "The USERHOST command takes up to five nicknames, each a separate parameters." -/// -- https://modern.ircdocs.horse/#userhost-message +/// -- const MAX_TARGETS: usize = 5; fn away_char(user: &wrapper::User) -> char { @@ -14,7 +14,7 @@ fn away_char(user: &wrapper::User) -> char { } #[command_handler("USERHOST")] -/// Syntax: USERHOST { } +/// Syntax: USERHOST <nickname>{ <nickname>} fn userhost_handler( response: &dyn CommandResponse, network: &Network, diff --git a/sable_ircd/src/command/handlers/whois.rs b/sable_ircd/src/command/handlers/whois.rs index 2a26fcae..e55da044 100644 --- a/sable_ircd/src/command/handlers/whois.rs +++ b/sable_ircd/src/command/handlers/whois.rs @@ -1,7 +1,7 @@ use super::*; #[command_handler("WHOIS")] -/// Syntax: WHOIS [] +/// Syntax: WHOIS [<server|target>] <target> fn whois_handler( response: &dyn CommandResponse, source: UserSource, diff --git a/sable_ircd/src/connection_collection.rs b/sable_ircd/src/connection_collection.rs index 78ba56d4..203a1122 100644 --- a/sable_ircd/src/connection_collection.rs +++ b/sable_ircd/src/connection_collection.rs @@ -153,11 +153,6 @@ impl ConnectionCollection { self.client_connections.values() } - /// Get the number of managed connections - pub fn len(&self) -> usize { - self.client_connections.len() - } - /// Drain the list of flooded-off connections for processing pub fn flooded_connections(&mut self) -> impl Iterator> + '_ { self.flooded_connections.drain(..) @@ -233,15 +228,10 @@ impl<'a> Iterator for UserConnectionIter<'a> { /// Helper trait to allow calling read methods of [`ConnectionCollection`] directly on an RwLock pub trait ConnectionCollectionLockHelper { fn get(&self, id: ConnectionId) -> LookupResult>; - fn len(&self) -> usize; } impl ConnectionCollectionLockHelper for parking_lot::RwLock { fn get(&self, id: ConnectionId) -> LookupResult> { self.read().get(id) } - - fn len(&self) -> usize { - self.read().len() - } } diff --git a/sable_macros/src/define_messages.rs b/sable_macros/src/define_messages.rs index 77bd71ab..068cdbc7 100644 --- a/sable_macros/src/define_messages.rs +++ b/sable_macros/src/define_messages.rs @@ -12,6 +12,8 @@ mod kw { syn::custom_keyword!(target); } +// the keyword fields are never read but need to be present in order to parse properly +#[allow(unused)] enum MessageArg { Source(kw::source), Target(kw::target), diff --git a/sable_network/src/network/network/mod.rs b/sable_network/src/network/network/mod.rs index b27cf91d..acfddde3 100644 --- a/sable_network/src/network/network/mod.rs +++ b/sable_network/src/network/network/mod.rs @@ -8,36 +8,11 @@ use sable_macros::dispatch_event; use serde::{Deserialize, Serialize}; use serde_with::serde_as; -use thiserror::Error; use std::collections::HashMap; -use std::convert::TryInto; use std::sync::OnceLock; -/// Error enumeration defining possible problems to be returned from -/// the [Network::validate] method. -#[derive(Error, Debug)] -pub enum ValidationError { - #[error("Nickname {0} already in use")] - NickInUse(Nickname), - #[error("Object not found: {0}")] - ObjectNotFound(#[from] LookupError), - #[error("Wrong object ID type: {0}")] - WrongTypeId(#[from] WrongIdTypeError), - #[error("{0}")] - InvalidNickname(#[from] InvalidNicknameError), - #[error("{0}")] - InvalidUsername(#[from] InvalidUsernameError), - #[error("{0}")] - InvalidHostname(#[from] InvalidHostnameError), - #[error("{0}")] - InvalidChannelName(#[from] InvalidChannelNameError), -} - -/// Convenience definition for a Result whose Error type is ValidationError -pub type ValidationResult = Result<(), ValidationError>; - /// Stores the current network state. /// /// ## General Principles @@ -243,25 +218,6 @@ impl Network { Ok(()) } - /// Validate a proposed event against the current network state. - /// - /// This method can be used to identify problems which would occur if the - /// provided event details were transformed and applied to the current - /// state. This is provided as a convenience for consumers, and does not - /// give any guarantee of behaviour if other events are processed between - /// the validation and eventual application of a given event. - /// - /// Note also that this is not related to whether [`apply`](Self::apply) - /// will succeed - `apply` always succeeds provided the event is well- - /// formed. `validate` provides advance warning of potentially undesirable - /// effects, such as nickname collisions. - pub fn validate(&self, id: ObjectId, detail: &EventDetails) -> ValidationResult { - match detail { - EventDetails::NewUser(newuser) => self.validate_new_user(id.try_into()?, newuser), - _ => Ok(()), - } - } - /// Translate an object ID into a [`update::HistoricMessageSource`] pub(crate) fn translate_state_change_source( &self, diff --git a/sable_network/src/network/network/user_state.rs b/sable_network/src/network/network/user_state.rs index 2b1276f9..69e5f0d9 100644 --- a/sable_network/src/network/network/user_state.rs +++ b/sable_network/src/network/network/user_state.rs @@ -237,18 +237,6 @@ impl Network { } } - pub(super) fn validate_new_user( - &self, - _target: UserId, - user: &details::NewUser, - ) -> ValidationResult { - if self.nick_bindings.contains_key(&user.nickname) { - Err(ValidationError::NickInUse(user.nickname)) - } else { - Ok(()) - } - } - pub(super) fn user_away( &mut self, target: UserId, diff --git a/sable_network/src/validated.rs b/sable_network/src/validated.rs index 661dc341..60473802 100644 --- a/sable_network/src/validated.rs +++ b/sable_network/src/validated.rs @@ -134,7 +134,7 @@ define_validated! { impl AwayReason { /// Maximum length, in bytes /// - /// It is small enough to ensure ":n!u@h AWAY :" can't overflow LINELEN + /// It is small enough to ensure ":n!u@h AWAY :<reason>" can't overflow LINELEN pub const LENGTH: usize = 300; }