Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement msgid (based on UUID7) #131

Merged
merged 3 commits into from
Aug 10, 2024
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions sable_ircd/src/capability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -66,6 +67,7 @@ define_capabilities! (
ClientCapability
{
// Stable caps
MessageTags: 0x01 => ("message-tags", true),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cap got removed earlier (#54) because the spec includes TAGMSG and client-only tags if this is negotiated. Do we want to put it back without those things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you're right, I should advertise CLIENTTAGDENY=*

ServerTime: 0x02 => ("server-time", true),
EchoMessage: 0x04 => ("echo-message", true),
Sasl: 0x08 => ("sasl", false),
Expand Down
15 changes: 15 additions & 0 deletions sable_ircd/src/capability/msgid.rs
Original file line number Diff line number Diff line change
@@ -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<OutboundMessageTag> {
match from_update.change() {
NetworkStateChange::NewMessage(detail) => Some(OutboundMessageTag::new(
"msgid",
Some(detail.message.to_string()),
ClientCapability::MessageTags,
)),
_ => None,
}
}
4 changes: 4 additions & 0 deletions sable_ircd/src/capability/with_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/notice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/privmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
10 changes: 10 additions & 0 deletions sable_ircd/src/command/handlers/tagmsg.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
1 change: 1 addition & 0 deletions sable_ircd/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
mod quit;
pub mod register;
mod rename;
mod tagmsg;
mod topic;
mod user;
mod userhost;
Expand All @@ -77,7 +78,7 @@

// Dev/test tools
#[cfg(debug)]
mod async_wait;

Check warning on line 81 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`

Check warning on line 81 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`
#[cfg(debug)]
mod sping;

Check warning on line 83 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`

Check warning on line 83 in sable_ircd/src/command/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unexpected `cfg` condition name: `debug`
}
5 changes: 5 additions & 0 deletions sable_ircd/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions sable_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 29 additions & 1 deletion sable_network/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +42,7 @@ object_ids!(ObjectId (ObjectIdGenerator) {
ChannelTopic: sequential;
ListMode: (ChannelId,ListModeType);
ListModeEntry: sequential;
Message: sequential;
Message: (Uuid7,);

NetworkBan: sequential;

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sable_network/tests/data/sample_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
Loading