Skip to content

Commit

Permalink
Remove unused code and clean up some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
spb committed Apr 15, 2024
1 parent cf43cad commit 293a871
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 90 deletions.
22 changes: 2 additions & 20 deletions sable_ircd/src/command/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,24 +49,6 @@ pub enum CommandError {
Numeric(messages::UntargetedNumeric),
}

impl From<ValidationError> 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<policy::PermissionError> for CommandError {
fn from(e: policy::PermissionError) -> Self {
/*
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/handlers/userhost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// -- <https://modern.ircdocs.horse/#userhost-message>
const MAX_TARGETS: usize = 5;

fn away_char(user: &wrapper::User) -> char {
Expand All @@ -14,7 +14,7 @@ fn away_char(user: &wrapper::User) -> char {
}

#[command_handler("USERHOST")]
/// Syntax: USERHOST <nickname>{ <nickname>}
/// Syntax: USERHOST &lt;nickname&gt;{ &lt;nickname&gt;}
fn userhost_handler(
response: &dyn CommandResponse,
network: &Network,
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/whois.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

#[command_handler("WHOIS")]
/// Syntax: WHOIS [<server|target>] <target>
/// Syntax: WHOIS [&lt;server|target&gt;] &lt;target&gt;
fn whois_handler(
response: &dyn CommandResponse,
source: UserSource,
Expand Down
10 changes: 0 additions & 10 deletions sable_ircd/src/connection_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Arc<ClientConnection>> + '_ {
self.flooded_connections.drain(..)
Expand Down Expand Up @@ -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<Arc<ClientConnection>>;
fn len(&self) -> usize;
}

impl ConnectionCollectionLockHelper for parking_lot::RwLock<ConnectionCollection> {
fn get(&self, id: ConnectionId) -> LookupResult<Arc<ClientConnection>> {
self.read().get(id)
}

fn len(&self) -> usize {
self.read().len()
}
}
2 changes: 2 additions & 0 deletions sable_macros/src/define_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
44 changes: 0 additions & 44 deletions sable_network/src/network/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions sable_network/src/network/network/user_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sable_network/src/validated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ define_validated! {
impl AwayReason {
/// Maximum length, in bytes
///
/// It is small enough to ensure ":n!u@h AWAY :<reason>" can't overflow LINELEN
/// It is small enough to ensure ":n!u@h AWAY :&lt;reason&gt;" can't overflow LINELEN
pub const LENGTH: usize = 300;
}

Expand Down

0 comments on commit 293a871

Please sign in to comment.