From b4e142bb75446f7f6fd7271bb336a070332160c2 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Fri, 28 Jun 2024 10:15:43 +0200 Subject: [PATCH 1/3] Implement msgid --- Cargo.lock | 12 +++++++++ sable_ircd/src/capability/mod.rs | 2 ++ sable_ircd/src/capability/msgid.rs | 15 +++++++++++ sable_ircd/src/capability/with_tags.rs | 4 +++ sable_ircd/src/command/handlers/notice.rs | 2 +- sable_ircd/src/command/handlers/privmsg.rs | 2 +- sable_network/Cargo.toml | 1 + sable_network/src/id.rs | 30 +++++++++++++++++++++- sable_network/tests/data/sample_events.rs | 4 +-- 9 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 sable_ircd/src/capability/msgid.rs diff --git a/Cargo.lock b/Cargo.lock index fd3892e0..61dbe2a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2171,6 +2171,7 @@ dependencies = [ "tokio-rustls", "tracing", "tracing-subscriber", + "uuid", "wildmatch", "x509-parser", ] @@ -3020,6 +3021,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "uuid" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" +dependencies = [ + "getrandom", + "rand", + "serde", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/sable_ircd/src/capability/mod.rs b/sable_ircd/src/capability/mod.rs index 885c8b28..9a25a8d3 100644 --- a/sable_ircd/src/capability/mod.rs +++ b/sable_ircd/src/capability/mod.rs @@ -12,6 +12,7 @@ mod capability_condition; pub use capability_condition::*; pub mod account_tag; +pub mod msgid; pub mod server_time; macro_rules! define_capabilities { @@ -66,6 +67,7 @@ define_capabilities! ( ClientCapability { // Stable caps + MessageTags: 0x01 => ("message-tags", true), ServerTime: 0x02 => ("server-time", true), EchoMessage: 0x04 => ("echo-message", true), Sasl: 0x08 => ("sasl", false), diff --git a/sable_ircd/src/capability/msgid.rs b/sable_ircd/src/capability/msgid.rs new file mode 100644 index 00000000..bb7ba416 --- /dev/null +++ b/sable_ircd/src/capability/msgid.rs @@ -0,0 +1,15 @@ +use super::*; +use crate::messages::OutboundMessageTag; +use sable_network::history::HistoryItem; +use sable_network::network::NetworkStateChange; + +pub fn msgid_tag(from_update: &impl HistoryItem) -> Option { + match from_update.change() { + NetworkStateChange::NewMessage(detail) => Some(OutboundMessageTag::new( + "msgid", + Some(detail.message.to_string()), + ClientCapability::MessageTags, + )), + _ => None, + } +} diff --git a/sable_ircd/src/capability/with_tags.rs b/sable_ircd/src/capability/with_tags.rs index c1c1485d..e1f83f3c 100644 --- a/sable_ircd/src/capability/with_tags.rs +++ b/sable_ircd/src/capability/with_tags.rs @@ -12,6 +12,10 @@ impl WithSupportedTags for OutboundClientMessage { let server_time_tag = server_time::server_time_tag(from_update.timestamp()); let mut result = self.with_tag(server_time_tag); + + if let Some(msgid_tag) = msgid::msgid_tag(from_update) { + result = result.with_tag(msgid_tag); + } if let Some(account_tag) = account_tag::account_tag(from_update.change(), net) { result = result.with_tag(account_tag); } diff --git a/sable_ircd/src/command/handlers/notice.rs b/sable_ircd/src/command/handlers/notice.rs index b90948fd..32958b9f 100644 --- a/sable_ircd/src/command/handlers/notice.rs +++ b/sable_ircd/src/command/handlers/notice.rs @@ -57,7 +57,7 @@ async fn handle_notice( message_type: state::MessageType::Notice, text: msg.to_owned(), }; - cmd.new_event_with_response(server.ids().next_message(), details) + cmd.new_event_with_response(MessageId::new(Uuid7::new_now()), details) .await; Ok(()) } diff --git a/sable_ircd/src/command/handlers/privmsg.rs b/sable_ircd/src/command/handlers/privmsg.rs index 85664508..803b71f1 100644 --- a/sable_ircd/src/command/handlers/privmsg.rs +++ b/sable_ircd/src/command/handlers/privmsg.rs @@ -36,7 +36,7 @@ async fn handle_privmsg( message_type: state::MessageType::Privmsg, text: msg.to_owned(), }; - cmd.new_event_with_response(server.ids().next_message(), details) + cmd.new_event_with_response(MessageId::new(Uuid7::new_now()), details) .await; Ok(()) } diff --git a/sable_network/Cargo.toml b/sable_network/Cargo.toml index 83c1083a..3c8c8376 100644 --- a/sable_network/Cargo.toml +++ b/sable_network/Cargo.toml @@ -47,6 +47,7 @@ ipnet = { version = "2", features = [ "serde" ] } anyhow = "1.0" backoff = { version = "0.4.0", features = ["tokio"] } chert = { git = "https://github.com/jesopo/chert" } +uuid = { version = "1.9.1", features = ["v7", "fast-rng", "serde"] } [dependencies.serde] version = "1" diff --git a/sable_network/src/id.rs b/sable_network/src/id.rs index cea45a75..b2865356 100644 --- a/sable_network/src/id.rs +++ b/sable_network/src/id.rs @@ -3,10 +3,30 @@ use super::modes::ListModeType; use super::validated::*; use sable_macros::object_ids; +use serde::{Deserialize, Serialize}; +use std::ops::Deref; use thiserror::Error; +use uuid::Uuid; pub type LocalId = i64; +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Serialize, Deserialize)] +pub struct Uuid7(Uuid); + +impl Deref for Uuid7 { + type Target = Uuid; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Uuid7 { + pub fn new_now() -> Self { + Self(Uuid::now_v7()) + } +} + #[derive(Debug, Error)] #[error("Mismatched object ID type for event")] pub struct WrongIdTypeError; @@ -22,7 +42,7 @@ object_ids!(ObjectId (ObjectIdGenerator) { ChannelTopic: sequential; ListMode: (ChannelId,ListModeType); ListModeEntry: sequential; - Message: sequential; + Message: (Uuid7,); NetworkBan: sequential; @@ -55,6 +75,14 @@ impl HistoricUserId { } } +impl Deref for MessageId { + type Target = Uuid7; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl NicknameId { pub fn nick(&self) -> &Nickname { &self.0 diff --git a/sable_network/tests/data/sample_events.rs b/sable_network/tests/data/sample_events.rs index b51c878d..f5014fdf 100644 --- a/sable_network/tests/data/sample_events.rs +++ b/sable_network/tests/data/sample_events.rs @@ -81,7 +81,7 @@ const EVENT_JSON: &str = r###" "1": [1,1707606926,4] }, "target": { - "Message": [1,1707606926,1] + "Message": "018d954d-e2b0-73be-8f43-337709fa3429" }, "details": { "NewMessage": { @@ -174,7 +174,7 @@ const EVENT_JSON: &str = r###" "1": [1,1707606926,5] }, "target": { - "Message": [2,1707606928,1] + "Message": "018d954d-ea80-7461-b32a-f6d9880e1c44" }, "details": { "NewMessage": { From 83e96997cfb7e0f3b6335b0fe06ad42ef8192756 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Fri, 26 Jul 2024 14:11:08 +0200 Subject: [PATCH 2/3] Add ISUPPORT CLIENTTAGDENY=* --- sable_ircd/src/server/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sable_ircd/src/server/mod.rs b/sable_ircd/src/server/mod.rs index 1c983dd1..0dd4ec23 100644 --- a/sable_ircd/src/server/mod.rs +++ b/sable_ircd/src/server/mod.rs @@ -188,6 +188,11 @@ impl ClientServer { ret.add(ISupportEntry::string("CASEMAPPING", "ascii")); + // https://ircv3.net/specs/extensions/message-tags#rpl_isupport-tokens + // Tell clients all client tags are rejected, so conforming clients won't + // even try to send TAGMSG (which we don't support yet). + ret.add(ISupportEntry::string("CLIENTTAGDENY", "*")); + ret.add(ISupportEntry::int( "HOSTLEN", Hostname::LENGTH.try_into().unwrap(), From a94a0f2122147f64eb7bd50cf10c3ef753dd4dd6 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Sat, 10 Aug 2024 14:59:02 +0200 Subject: [PATCH 3/3] Add dummy TAGMSG command handler --- sable_ircd/src/command/handlers/tagmsg.rs | 10 ++++++++++ sable_ircd/src/command/mod.rs | 1 + 2 files changed, 11 insertions(+) create mode 100644 sable_ircd/src/command/handlers/tagmsg.rs diff --git a/sable_ircd/src/command/handlers/tagmsg.rs b/sable_ircd/src/command/handlers/tagmsg.rs new file mode 100644 index 00000000..15929ce9 --- /dev/null +++ b/sable_ircd/src/command/handlers/tagmsg.rs @@ -0,0 +1,10 @@ +use super::*; + +/// Minimal implementation of TAGMSG that just drops everything, so we can safely +/// implement https://ircv3.net/specs/extensions/message-tags +/// +/// `CLIENTTAGDENY=*` tells clients we would drop all tags, anyway. +#[command_handler("TAGMSG")] +fn handle_tagmsg() -> CommandResult { + Ok(()) +} diff --git a/sable_ircd/src/command/mod.rs b/sable_ircd/src/command/mod.rs index eb63bcce..852e505c 100644 --- a/sable_ircd/src/command/mod.rs +++ b/sable_ircd/src/command/mod.rs @@ -61,6 +61,7 @@ mod handlers { mod quit; pub mod register; mod rename; + mod tagmsg; mod topic; mod user; mod userhost;