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 event ids) #107

Closed
wants to merge 1 commit into from
Closed
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: 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),
ServerTime: 0x02 => ("server-time", true),
EchoMessage: 0x04 => ("echo-message", true),
Sasl: 0x08 => ("sasl", false),
Expand Down
17 changes: 17 additions & 0 deletions sable_ircd/src/capability/msgid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use base64::prelude::*;

use super::*;
use crate::messages::OutboundMessageTag;
use sable_network::id::EventId;

pub fn msgid_tag(event_id: EventId) -> OutboundMessageTag {
let mut buf = [0u8; 24];
buf[0..8].copy_from_slice(&event_id.server().local().to_le_bytes());
buf[8..16].copy_from_slice(&event_id.epoch().local().to_le_bytes());
buf[16..24].copy_from_slice(&event_id.local().to_le_bytes());
OutboundMessageTag::new(
"msgid",
Some(BASE64_URL_SAFE_NO_PAD.encode(&buf[..])),
ClientCapability::MessageTags,
)
}
3 changes: 2 additions & 1 deletion sable_ircd/src/capability/with_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ pub(crate) trait WithSupportedTags {
impl WithSupportedTags for OutboundClientMessage {
fn with_tags_from(self, history_entry: &HistoryLogEntry) -> Self {
let server_time_tag = server_time::server_time_tag(history_entry.timestamp);
let msgid_tag = msgid::msgid_tag(history_entry.source_event);
let mut result = self.with_tag(server_time_tag).with_tag(msgid_tag);

let mut result = self.with_tag(server_time_tag);
if let Some(account_tag) = account_tag::account_tag(&history_entry.details) {
result = result.with_tag(account_tag);
}
Expand Down
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::*;

#[command_handler("TAGMSG")]
async fn handle_tagmsg(_target: TargetParameter<'_>) -> CommandResult {
// Ignore, no client tag is supported yet.
//
// We send CLIENTTAGDENY=* in ISUPPORT, so well-behaved clients should never send
// TAGMSGs anyway.
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 @@ -60,6 +60,7 @@ mod handlers {
mod quit;
pub mod register;
mod rename;
mod tagmsg;
mod topic;
mod user;
mod who;
Expand Down
4 changes: 4 additions & 0 deletions sable_ircd/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ impl ClientServer {

ret.add(ISupportEntry::string("CASEMAPPING", "ascii"));

// https://ircv3.net/specs/extensions/message-tags#rpl_isupport-tokens
// Ignore all client tags, for now.
ret.add(ISupportEntry::string("CLIENTTAGDENY", "*"));

ret.add(ISupportEntry::int(
"HOSTLEN",
Hostname::LENGTH.try_into().unwrap(),
Expand Down
12 changes: 12 additions & 0 deletions sable_network/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ object_ids!(ObjectId (ObjectIdGenerator) {
SaslSession: sequential;
});

impl ServerId {
pub fn local(&self) -> LocalId {
self.0
}
}

impl EpochId {
pub fn local(&self) -> LocalId {
self.0
}
}

impl NicknameId {
pub fn nick(&self) -> &Nickname {
&self.0
Expand Down
Loading