Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ 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"
argon2 = { version = "0.5.3", features = ["std"] }
bytes = "1.5.0"
color-eyre = "0.6.2"
Expand Down
4 changes: 2 additions & 2 deletions src/cli/address_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{fs, io};
use color_eyre::eyre;
use color_eyre::eyre::{eyre, WrapErr};
use serde::Serialize;
use tashi_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)]
Expand Down Expand Up @@ -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::<SocketAddr>::new();

let address_book_path = output_dir.join("address-book.toml");

Expand Down
5 changes: 2 additions & 3 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tashi_collections::HashMap;

use crate::cli::LogFormat;
use crate::collections::HashMap;
use crate::config;
use crate::config::addresses::Addresses;
use crate::config::permissions::PermissionsConfig;
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/cli/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::path::{Path, PathBuf};
use color_eyre::eyre::WrapErr;
use rand::distributions::Uniform;
use rand::Rng;
use tashi_collections::HashMap;

use crate::cli::LogFormat;
use crate::collections::HashMap;
use crate::config::users::{AuthConfig, User, UsersConfig};

const DEFAULT_PASSWORD_LEN: usize = 12;
Expand Down
15 changes: 15 additions & 0 deletions src/collections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub use std::collections::hash_map;
pub use std::collections::HashMap;
pub use std::collections::HashSet;

/// Re-export of [`std::collections::HashMap`] using [`fnv::FnvBuildHasher`].
pub type FnvHashMap<K, V> = std::collections::HashMap<K, V, fnv::FnvBuildHasher>;

/// Re-export of [`std::collections::HashSet`] using [`fnv::FnvBuildHasher`].
pub type FnvHashSet<T> = std::collections::HashSet<T, fnv::FnvBuildHasher>;

/// Creates an empty [`HashMap`] with the specified capacity.
#[inline]
pub fn with_capacity<K, V>(capacity: usize) -> HashMap<K, V> {
HashMap::with_capacity(capacity)
}
2 changes: 1 addition & 1 deletion src/config/permissions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{path::Path, str::FromStr};

use tashi_collections::HashMap;
use crate::collections::HashMap;

use crate::mqtt::trie::Filter;

Expand Down
2 changes: 1 addition & 1 deletion src/config/users.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/mqtt/broker/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ use bytes::BytesMut;
use color_eyre::eyre;
use der::Encode;
use futures::future::OptionFuture;
use tashi_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,
Expand Down
5 changes: 3 additions & 2 deletions src/mqtt/broker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use futures::future::OptionFuture;
use rand::RngCore;
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use slotmap::SlotMap;
use tashi_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;

Expand Down
7 changes: 1 addition & 6 deletions src/mqtt/client_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::str::FromStr;

use rand::distributions::{Alphanumeric, Distribution};
use rand::Rng;
use tashi_collections::Equivalent;

/// The maximum length a `ClientId` is allowed to be.
///
Expand Down Expand Up @@ -193,11 +192,7 @@ impl PartialEq<ClientId> for str {
}
}

impl Equivalent<str> for ClientId {
fn equivalent(&self, key: &str) -> bool {
self == key
}
}


impl From<ClientId> for String {
fn from(value: ClientId) -> Self {
Expand Down
3 changes: 2 additions & 1 deletion src/mqtt/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::task::Poll;
use std::{cmp, future};
use tashi_collections::HashSet;

use tokio::sync::mpsc;

use crate::collections::HashSet;

use rumqttd_protocol::QoS;

use crate::mqtt::packets::PacketId;
Expand Down
4 changes: 2 additions & 2 deletions src/mqtt/packets.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::num::NonZeroU16;

use tashi_collections::HashMap;

use rumqttd_protocol::{SubscribeReasonCode, UnsubAckReason};

use crate::collections::HashMap;

#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Debug)]
pub struct PacketId(NonZeroU16);

Expand Down
5 changes: 3 additions & 2 deletions src/mqtt/publish.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use bytes::Bytes;
use std::num::NonZeroU32;
use std::ops::Not;

use bytes::Bytes;
use time::format_description::well_known::Rfc3339;

use tashi_collections::FnvHashMap;
use crate::collections::FnvHashMap;

use protocol::{
ConnectReturnCode, DisconnectReasonCode, LastWill, LastWillProperties, Packet, PubAck,
Expand Down
9 changes: 5 additions & 4 deletions src/mqtt/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ use color_eyre::eyre::WrapErr;
use color_eyre::eyre::{self};
use der::{Decode, Encode};
use slotmap::SecondaryMap;
use tashi_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;
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;
Expand Down
12 changes: 7 additions & 5 deletions src/mqtt/session.rs
Original file line number Diff line number Diff line change
@@ -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 tashi_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.
///
Expand Down
Loading