From 4a892894e2d597253de7778a1668b2d4822f00fc Mon Sep 17 00:00:00 2001 From: Divyanshu110011 Date: Tue, 27 Jan 2026 23:18:29 +0000 Subject: [PATCH 1/2] refactor: remove tashi-collections internal dependency --- Cargo.toml | 6 ++---- src/cli/address_book.rs | 2 +- src/cli/run.rs | 2 +- src/cli/user.rs | 2 +- src/collections.rs | 23 +++++++++++++++++++++++ src/config/permissions.rs | 2 +- src/config/users.rs | 2 +- src/lib.rs | 1 + src/mqtt/broker/connection.rs | 2 +- src/mqtt/broker/mod.rs | 2 +- src/mqtt/client_id.rs | 3 ++- src/mqtt/mailbox.rs | 2 +- src/mqtt/packets.rs | 2 +- src/mqtt/publish.rs | 2 +- src/mqtt/router.rs | 2 +- src/mqtt/session.rs | 2 +- 16 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 src/collections.rs diff --git a/Cargo.toml b/Cargo.toml index 635bff8..9722a45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,11 +20,9 @@ default-run = "foxmq" git = "ssh://git@github.com/tashigg/tashi-consensus-engine" rev = "aaf0206f2a71c710bafe6c5c89f172e5fae2b277" -[dependencies.tashi-collections] -git = "ssh://git@github.com/tashigg/tashi-consensus-engine" -rev = "aaf0206f2a71c710bafe6c5c89f172e5fae2b277" - [dependencies] +fnv = "1.0.7" +hashbrown = { version = "0.14.5", features = ["serde"] } argon2 = { version = "0.5.3", features = ["std"] } bytes = "1.5.0" color-eyre = "0.6.2" diff --git a/src/cli/address_book.rs b/src/cli/address_book.rs index cce97d6..1d2a3a1 100644 --- a/src/cli/address_book.rs +++ b/src/cli/address_book.rs @@ -6,7 +6,7 @@ use std::{fs, io}; use color_eyre::eyre; use color_eyre::eyre::{eyre, WrapErr}; use serde::Serialize; -use tashi_collections::HashSet; +use crate::collections::HashSet; use tashi_consensus_engine::SecretKey; use crate::cli::LogFormat; diff --git a/src/cli/run.rs b/src/cli/run.rs index 93486be..ccfb481 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::sync::Arc; -use tashi_collections::HashMap; +use crate::collections::HashMap; use crate::cli::LogFormat; use crate::config; diff --git a/src/cli/user.rs b/src/cli/user.rs index b08ccd1..1ae0327 100644 --- a/src/cli/user.rs +++ b/src/cli/user.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use color_eyre::eyre::WrapErr; use rand::distributions::Uniform; use rand::Rng; -use tashi_collections::HashMap; +use crate::collections::HashMap; use crate::cli::LogFormat; use crate::config::users::{AuthConfig, User, UsersConfig}; diff --git a/src/collections.rs b/src/collections.rs new file mode 100644 index 0000000..4f65db3 --- /dev/null +++ b/src/collections.rs @@ -0,0 +1,23 @@ +use std::collections::hash_map::RandomState; + +pub use hashbrown::hash_map; +pub use hashbrown::hash_set; +pub use hashbrown::Equivalent; + +/// Re-export of [`hashbrown::HashMap`] using [`RandomState`] ("DefaultHasher"). +pub type HashMap = hashbrown::HashMap; + +/// Re-export of [`hashbrown::HashSet`] using [`RandomState`] ("DefaultHasher"). +pub type HashSet = hashbrown::HashSet; + +/// Re-export of [`hashbrown::HashMap`] using [`fnv::FnvBuildHasher`]. +pub type FnvHashMap = hashbrown::HashMap; + +/// Re-export of [`hashbrown::HashSet`] using [`fnv::FnvBuildHasher`]. +pub type FnvHashSet = hashbrown::HashSet; + +/// Creates an empty [`HashMap`] with the specified capacity. +#[inline] +pub fn with_capacity(capacity: usize) -> HashMap { + HashMap::with_capacity_and_hasher(capacity, Default::default()) +} diff --git a/src/config/permissions.rs b/src/config/permissions.rs index caeba7c..15b9775 100644 --- a/src/config/permissions.rs +++ b/src/config/permissions.rs @@ -1,6 +1,6 @@ use std::{path::Path, str::FromStr}; -use tashi_collections::HashMap; +use crate::collections::HashMap; use crate::mqtt::trie::Filter; diff --git a/src/config/users.rs b/src/config/users.rs index 19f4cff..3c3b099 100644 --- a/src/config/users.rs +++ b/src/config/users.rs @@ -1,6 +1,6 @@ use std::path::Path; -use tashi_collections::HashMap; +use crate::collections::HashMap; #[derive(serde::Deserialize, serde::Serialize, Default)] pub struct UsersConfig { diff --git a/src/lib.rs b/src/lib.rs index 5da9bc2..cac7921 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub use tashi_consensus_engine::{flatten_task_result, map_join_error}; use crate::cli::LogFormat; pub mod cli; +pub mod collections; pub mod config; diff --git a/src/mqtt/broker/connection.rs b/src/mqtt/broker/connection.rs index 1e6819a..9871137 100644 --- a/src/mqtt/broker/connection.rs +++ b/src/mqtt/broker/connection.rs @@ -9,7 +9,7 @@ use bytes::BytesMut; use color_eyre::eyre; use der::Encode; use futures::future::OptionFuture; -use tashi_collections::FnvHashMap; +use crate::collections::FnvHashMap; use tokio::sync::oneshot; use tokio::time::{Instant, Sleep}; use tokio_util::sync::CancellationToken; diff --git a/src/mqtt/broker/mod.rs b/src/mqtt/broker/mod.rs index a917307..a59a53a 100644 --- a/src/mqtt/broker/mod.rs +++ b/src/mqtt/broker/mod.rs @@ -9,7 +9,7 @@ use futures::future::OptionFuture; use rand::RngCore; use rustls::pki_types::{CertificateDer, PrivateKeyDer}; use slotmap::SlotMap; -use tashi_collections::{hash_map, HashMap}; +use crate::collections::{hash_map, HashMap}; use tashi_consensus_engine::{Platform, TxnPermit, TxnTryReserveError}; use tokio::net::{TcpListener, TcpStream}; use tokio::sync::{mpsc, oneshot}; diff --git a/src/mqtt/client_id.rs b/src/mqtt/client_id.rs index ee62924..904e01c 100644 --- a/src/mqtt/client_id.rs +++ b/src/mqtt/client_id.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use rand::distributions::{Alphanumeric, Distribution}; use rand::Rng; -use tashi_collections::Equivalent; +use crate::collections::Equivalent; /// The maximum length a `ClientId` is allowed to be. /// @@ -193,6 +193,7 @@ impl PartialEq for str { } } + impl Equivalent for ClientId { fn equivalent(&self, key: &str) -> bool { self == key diff --git a/src/mqtt/mailbox.rs b/src/mqtt/mailbox.rs index 84caa89..da7d8ce 100644 --- a/src/mqtt/mailbox.rs +++ b/src/mqtt/mailbox.rs @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::task::Poll; use std::{cmp, future}; -use tashi_collections::HashSet; +use crate::collections::HashSet; use tokio::sync::mpsc; diff --git a/src/mqtt/packets.rs b/src/mqtt/packets.rs index 1d8d8db..9a743af 100644 --- a/src/mqtt/packets.rs +++ b/src/mqtt/packets.rs @@ -1,6 +1,6 @@ use std::num::NonZeroU16; -use tashi_collections::HashMap; +use crate::collections::HashMap; use rumqttd_protocol::{SubscribeReasonCode, UnsubAckReason}; diff --git a/src/mqtt/publish.rs b/src/mqtt/publish.rs index 50d028e..2615b29 100644 --- a/src/mqtt/publish.rs +++ b/src/mqtt/publish.rs @@ -3,7 +3,7 @@ use std::num::NonZeroU32; use std::ops::Not; use time::format_description::well_known::Rfc3339; -use tashi_collections::FnvHashMap; +use crate::collections::FnvHashMap; use protocol::{ ConnectReturnCode, DisconnectReasonCode, LastWill, LastWillProperties, Packet, PubAck, diff --git a/src/mqtt/router.rs b/src/mqtt/router.rs index b053aa3..f0d3e3b 100644 --- a/src/mqtt/router.rs +++ b/src/mqtt/router.rs @@ -10,7 +10,7 @@ use color_eyre::eyre::WrapErr; use color_eyre::eyre::{self}; use der::{Decode, Encode}; use slotmap::SecondaryMap; -use tashi_collections::{HashMap, HashSet}; +use crate::collections::{HashMap, HashSet}; use tashi_consensus_engine::{ CreatorId, Message, MessageStream, Platform, PlatformEvent, RootCertificates, }; diff --git a/src/mqtt/session.rs b/src/mqtt/session.rs index 4d1a0f7..95daa0c 100644 --- a/src/mqtt/session.rs +++ b/src/mqtt/session.rs @@ -4,7 +4,7 @@ use crate::transaction::PublishTrasaction; use futures::StreamExt; use std::num::NonZeroU32; use std::time::Duration; -use tashi_collections::HashMap; +use crate::collections::HashMap; use tokio_util::time::{delay_queue, DelayQueue}; /// Sessions of clients that have disconnected. They might eventually time out, or could be From 6dc82955101afa320b2988b6dfc73c70f40a4450 Mon Sep 17 00:00:00 2001 From: Divyanshu110011 Date: Wed, 28 Jan 2026 10:48:38 +0000 Subject: [PATCH 2/2] refactor: address PR feedback (remove hashbrown, organize imports) --- Cargo.lock | 2 +- Cargo.toml | 1 - src/cli/address_book.rs | 4 ++-- src/cli/run.rs | 5 ++--- src/cli/user.rs | 3 +-- src/collections.rs | 24 ++++++++---------------- src/mqtt/broker/connection.rs | 3 ++- src/mqtt/broker/mod.rs | 5 +++-- src/mqtt/client_id.rs | 6 ------ src/mqtt/mailbox.rs | 3 ++- src/mqtt/packets.rs | 4 ++-- src/mqtt/publish.rs | 3 ++- src/mqtt/router.rs | 9 +++++---- src/mqtt/session.rs | 12 +++++++----- 14 files changed, 37 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03ccbcf..c7b3ed8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -683,6 +683,7 @@ dependencies = [ "dialoguer", "dotenvy", "expect-test", + "fnv", "futures", "hex", "num_enum", @@ -691,7 +692,6 @@ dependencies = [ "rustls-pemfile", "serde", "slotmap", - "tashi-collections", "tashi-consensus-engine", "thiserror 1.0.69", "time", diff --git a/Cargo.toml b/Cargo.toml index 9722a45..6ea4de5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ rev = "aaf0206f2a71c710bafe6c5c89f172e5fae2b277" [dependencies] fnv = "1.0.7" -hashbrown = { version = "0.14.5", features = ["serde"] } argon2 = { version = "0.5.3", features = ["std"] } bytes = "1.5.0" color-eyre = "0.6.2" diff --git a/src/cli/address_book.rs b/src/cli/address_book.rs index 1d2a3a1..63ff7f7 100644 --- a/src/cli/address_book.rs +++ b/src/cli/address_book.rs @@ -6,10 +6,10 @@ use std::{fs, io}; use color_eyre::eyre; use color_eyre::eyre::{eyre, WrapErr}; use serde::Serialize; -use crate::collections::HashSet; use tashi_consensus_engine::SecretKey; use crate::cli::LogFormat; +use crate::collections::HashSet; use crate::config::addresses::Address; #[derive(clap::Args, Clone, Debug)] @@ -130,7 +130,7 @@ fn generate_address_book( let mut address_book = String::new(); - let mut address_set = HashSet::with_hasher(Default::default()); + let mut address_set = HashSet::::new(); let address_book_path = output_dir.join("address-book.toml"); diff --git a/src/cli/run.rs b/src/cli/run.rs index ccfb481..68c8ba7 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,9 +1,8 @@ use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::sync::Arc; -use crate::collections::HashMap; - use crate::cli::LogFormat; +use crate::collections::HashMap; use crate::config; use crate::config::addresses::Addresses; use crate::config::permissions::PermissionsConfig; @@ -349,7 +348,7 @@ fn create_tce_config( let mut tce_config = tashi_consensus_engine::Config::new(secret_key); tce_config - .initial_nodes(nodes) + .initial_nodes(nodes.into_iter().collect()) .enable_hole_punching(false) // TODO: we can dispatch messages before they come to consensus // but we need to make sure we don't duplicate PUBLISHes. diff --git a/src/cli/user.rs b/src/cli/user.rs index 1ae0327..83120bb 100644 --- a/src/cli/user.rs +++ b/src/cli/user.rs @@ -6,9 +6,8 @@ use std::path::{Path, PathBuf}; use color_eyre::eyre::WrapErr; use rand::distributions::Uniform; use rand::Rng; -use crate::collections::HashMap; - use crate::cli::LogFormat; +use crate::collections::HashMap; use crate::config::users::{AuthConfig, User, UsersConfig}; const DEFAULT_PASSWORD_LEN: usize = 12; diff --git a/src/collections.rs b/src/collections.rs index 4f65db3..b48dbd4 100644 --- a/src/collections.rs +++ b/src/collections.rs @@ -1,23 +1,15 @@ -use std::collections::hash_map::RandomState; +pub use std::collections::hash_map; +pub use std::collections::HashMap; +pub use std::collections::HashSet; -pub use hashbrown::hash_map; -pub use hashbrown::hash_set; -pub use hashbrown::Equivalent; +/// Re-export of [`std::collections::HashMap`] using [`fnv::FnvBuildHasher`]. +pub type FnvHashMap = std::collections::HashMap; -/// Re-export of [`hashbrown::HashMap`] using [`RandomState`] ("DefaultHasher"). -pub type HashMap = hashbrown::HashMap; - -/// Re-export of [`hashbrown::HashSet`] using [`RandomState`] ("DefaultHasher"). -pub type HashSet = hashbrown::HashSet; - -/// Re-export of [`hashbrown::HashMap`] using [`fnv::FnvBuildHasher`]. -pub type FnvHashMap = hashbrown::HashMap; - -/// Re-export of [`hashbrown::HashSet`] using [`fnv::FnvBuildHasher`]. -pub type FnvHashSet = hashbrown::HashSet; +/// Re-export of [`std::collections::HashSet`] using [`fnv::FnvBuildHasher`]. +pub type FnvHashSet = std::collections::HashSet; /// Creates an empty [`HashMap`] with the specified capacity. #[inline] pub fn with_capacity(capacity: usize) -> HashMap { - HashMap::with_capacity_and_hasher(capacity, Default::default()) + HashMap::with_capacity(capacity) } diff --git a/src/mqtt/broker/connection.rs b/src/mqtt/broker/connection.rs index 9871137..bb4cf70 100644 --- a/src/mqtt/broker/connection.rs +++ b/src/mqtt/broker/connection.rs @@ -9,11 +9,12 @@ use bytes::BytesMut; use color_eyre::eyre; use der::Encode; use futures::future::OptionFuture; -use crate::collections::FnvHashMap; use tokio::sync::oneshot; use tokio::time::{Instant, Sleep}; use tokio_util::sync::CancellationToken; +use crate::collections::FnvHashMap; + use protocol::{ ConnAck, ConnAckProperties, ConnectReturnCode, Disconnect, DisconnectProperties, DisconnectReasonCode, Packet, PingResp, Protocol, PubAck, PubAckReason, PubRec, PubRecReason, diff --git a/src/mqtt/broker/mod.rs b/src/mqtt/broker/mod.rs index a59a53a..8307154 100644 --- a/src/mqtt/broker/mod.rs +++ b/src/mqtt/broker/mod.rs @@ -9,14 +9,15 @@ use futures::future::OptionFuture; use rand::RngCore; use rustls::pki_types::{CertificateDer, PrivateKeyDer}; use slotmap::SlotMap; -use crate::collections::{hash_map, HashMap}; -use tashi_consensus_engine::{Platform, TxnPermit, TxnTryReserveError}; use tokio::net::{TcpListener, TcpStream}; use tokio::sync::{mpsc, oneshot}; use tokio::task::JoinSet; use tokio_rustls::rustls; use tokio_util::sync::CancellationToken; +use crate::collections::{hash_map, HashMap}; +use tashi_consensus_engine::{Platform, TxnPermit, TxnTryReserveError}; + use connection::Connection; use rumqttd_protocol::QoS; diff --git a/src/mqtt/client_id.rs b/src/mqtt/client_id.rs index 904e01c..62c607a 100644 --- a/src/mqtt/client_id.rs +++ b/src/mqtt/client_id.rs @@ -7,7 +7,6 @@ use std::str::FromStr; use rand::distributions::{Alphanumeric, Distribution}; use rand::Rng; -use crate::collections::Equivalent; /// The maximum length a `ClientId` is allowed to be. /// @@ -194,11 +193,6 @@ impl PartialEq for str { } -impl Equivalent for ClientId { - fn equivalent(&self, key: &str) -> bool { - self == key - } -} impl From for String { fn from(value: ClientId) -> Self { diff --git a/src/mqtt/mailbox.rs b/src/mqtt/mailbox.rs index da7d8ce..e307276 100644 --- a/src/mqtt/mailbox.rs +++ b/src/mqtt/mailbox.rs @@ -3,10 +3,11 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::task::Poll; use std::{cmp, future}; -use crate::collections::HashSet; use tokio::sync::mpsc; +use crate::collections::HashSet; + use rumqttd_protocol::QoS; use crate::mqtt::packets::PacketId; diff --git a/src/mqtt/packets.rs b/src/mqtt/packets.rs index 9a743af..9b54bd8 100644 --- a/src/mqtt/packets.rs +++ b/src/mqtt/packets.rs @@ -1,9 +1,9 @@ use std::num::NonZeroU16; -use crate::collections::HashMap; - use rumqttd_protocol::{SubscribeReasonCode, UnsubAckReason}; +use crate::collections::HashMap; + #[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Debug)] pub struct PacketId(NonZeroU16); diff --git a/src/mqtt/publish.rs b/src/mqtt/publish.rs index 2615b29..30f1f55 100644 --- a/src/mqtt/publish.rs +++ b/src/mqtt/publish.rs @@ -1,6 +1,7 @@ -use bytes::Bytes; use std::num::NonZeroU32; use std::ops::Not; + +use bytes::Bytes; use time::format_description::well_known::Rfc3339; use crate::collections::FnvHashMap; diff --git a/src/mqtt/router.rs b/src/mqtt/router.rs index f0d3e3b..bfeb17a 100644 --- a/src/mqtt/router.rs +++ b/src/mqtt/router.rs @@ -10,10 +10,6 @@ use color_eyre::eyre::WrapErr; use color_eyre::eyre::{self}; use der::{Decode, Encode}; use slotmap::SecondaryMap; -use crate::collections::{HashMap, HashSet}; -use tashi_consensus_engine::{ - CreatorId, Message, MessageStream, Platform, PlatformEvent, RootCertificates, -}; use tokio::sync::mpsc; use tokio::sync::mpsc::error::SendError; use tokio::task; @@ -21,6 +17,11 @@ use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use tracing::{Instrument, Span}; +use crate::collections::{HashMap, HashSet}; +use tashi_consensus_engine::{ + CreatorId, Message, MessageStream, Platform, PlatformEvent, RootCertificates, +}; + use rumqttd_protocol::{QoS, RetainForwardRule, SubscribeReasonCode, UnsubAckReason}; use crate::config::permissions::PermissionsConfig; diff --git a/src/mqtt/session.rs b/src/mqtt/session.rs index 95daa0c..4ced015 100644 --- a/src/mqtt/session.rs +++ b/src/mqtt/session.rs @@ -1,12 +1,14 @@ -use crate::mqtt::mailbox::Mailbox; -use crate::mqtt::ClientId; -use crate::transaction::PublishTrasaction; -use futures::StreamExt; use std::num::NonZeroU32; use std::time::Duration; -use crate::collections::HashMap; + +use futures::StreamExt; use tokio_util::time::{delay_queue, DelayQueue}; +use crate::collections::HashMap; +use crate::mqtt::mailbox::Mailbox; +use crate::mqtt::ClientId; +use crate::transaction::PublishTrasaction; + /// Sessions of clients that have disconnected. They might eventually time out, or could be /// reclaimed by a reconnecting client. ///