run cargo fix for rust 2024 changes and rustfmt
Signed-off-by: June Clementine Strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
e97952b7f6
commit
a1e1f40ded
320 changed files with 2212 additions and 2039 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{
|
||||
cell::OnceCell,
|
||||
ffi::{c_char, c_void, CStr},
|
||||
ffi::{CStr, c_char, c_void},
|
||||
fmt::Debug,
|
||||
sync::RwLock,
|
||||
};
|
||||
|
@ -14,9 +14,8 @@ use tikv_jemalloc_sys as ffi;
|
|||
use tikv_jemallocator as jemalloc;
|
||||
|
||||
use crate::{
|
||||
err, is_equal_to, is_nonzero,
|
||||
Result, err, is_equal_to, is_nonzero,
|
||||
utils::{math, math::Tried},
|
||||
Result,
|
||||
};
|
||||
|
||||
#[cfg(feature = "jemalloc_conf")]
|
||||
|
@ -128,7 +127,7 @@ unsafe extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) {
|
|||
}
|
||||
|
||||
macro_rules! mallctl {
|
||||
($name:expr) => {{
|
||||
($name:expr_2021) => {{
|
||||
thread_local! {
|
||||
static KEY: OnceCell<Key> = OnceCell::default();
|
||||
};
|
||||
|
@ -141,7 +140,7 @@ macro_rules! mallctl {
|
|||
}
|
||||
|
||||
pub mod this_thread {
|
||||
use super::{is_nonzero, key, math, Debug, Key, OnceCell, Result};
|
||||
use super::{Debug, Key, OnceCell, Result, is_nonzero, key, math};
|
||||
|
||||
thread_local! {
|
||||
static ALLOCATED_BYTES: OnceCell<&'static u64> = const { OnceCell::new() };
|
||||
|
@ -261,18 +260,18 @@ pub fn decay<I: Into<Option<usize>>>(arena: I) -> Result {
|
|||
}
|
||||
|
||||
pub fn set_muzzy_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
|
||||
if let Some(arena) = arena.into() {
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.muzzy_decay_ms"), decay_ms)
|
||||
} else {
|
||||
set(&mallctl!("arenas.muzzy_decay_ms"), decay_ms)
|
||||
match arena.into() {
|
||||
| Some(arena) =>
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.muzzy_decay_ms"), decay_ms),
|
||||
| _ => set(&mallctl!("arenas.muzzy_decay_ms"), decay_ms),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_dirty_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
|
||||
if let Some(arena) = arena.into() {
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.dirty_decay_ms"), decay_ms)
|
||||
} else {
|
||||
set(&mallctl!("arenas.dirty_decay_ms"), decay_ms)
|
||||
match arena.into() {
|
||||
| Some(arena) =>
|
||||
set_by_arena(Some(arena), mallctl!("arena.4096.dirty_decay_ms"), decay_ms),
|
||||
| _ => set(&mallctl!("arenas.dirty_decay_ms"), decay_ms),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use either::Either;
|
|||
use figment::Figment;
|
||||
|
||||
use super::DEPRECATED_KEYS;
|
||||
use crate::{debug, debug_info, debug_warn, error, warn, Config, Err, Result, Server};
|
||||
use crate::{Config, Err, Result, Server, debug, debug_info, debug_warn, error, warn};
|
||||
|
||||
/// Performs check() with additional checks specific to reloading old config
|
||||
/// with new config.
|
||||
|
|
|
@ -4,13 +4,13 @@ use std::{
|
|||
ptr,
|
||||
ptr::null_mut,
|
||||
sync::{
|
||||
atomic::{AtomicPtr, Ordering},
|
||||
Arc,
|
||||
atomic::{AtomicPtr, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use super::Config;
|
||||
use crate::{implement, Result};
|
||||
use crate::{Result, implement};
|
||||
|
||||
/// The configuration manager is an indirection to reload the configuration for
|
||||
/// the server while it is running. In order to not burden or clutter the many
|
||||
|
|
|
@ -14,18 +14,18 @@ use either::{
|
|||
Either::{Left, Right},
|
||||
};
|
||||
use figment::providers::{Env, Format, Toml};
|
||||
pub use figment::{value::Value as FigmentValue, Figment};
|
||||
pub use figment::{Figment, value::Value as FigmentValue};
|
||||
use regex::RegexSet;
|
||||
use ruma::{
|
||||
api::client::discovery::discover_support::ContactRole, OwnedRoomOrAliasId, OwnedServerName,
|
||||
OwnedUserId, RoomVersionId,
|
||||
OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomVersionId,
|
||||
api::client::discovery::discover_support::ContactRole,
|
||||
};
|
||||
use serde::{de::IgnoredAny, Deserialize};
|
||||
use serde::{Deserialize, de::IgnoredAny};
|
||||
use url::Url;
|
||||
|
||||
use self::proxy::ProxyConfig;
|
||||
pub use self::{check::check, manager::Manager};
|
||||
use crate::{err, error::Error, utils::sys, Result};
|
||||
use crate::{Result, err, error::Error, utils::sys};
|
||||
|
||||
/// All the config options for conduwuit.
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
|
|
|
@ -13,7 +13,7 @@ pub use crate::{result::DebugInspect, utils::debug::*};
|
|||
/// In release-mode it becomes DEBUG level, and possibly subject to elision.
|
||||
#[macro_export]
|
||||
macro_rules! debug_event {
|
||||
( $level:expr, $($x:tt)+ ) => {
|
||||
( $level:expr_2021, $($x:tt)+ ) => {
|
||||
if $crate::debug::logging() {
|
||||
::tracing::event!( $level, _debug = true, $($x)+ )
|
||||
} else {
|
||||
|
|
|
@ -165,10 +165,10 @@ macro_rules! err_lev {
|
|||
use std::{fmt, fmt::Write};
|
||||
|
||||
use tracing::{
|
||||
level_enabled, Callsite, Event, __macro_support, __tracing_log,
|
||||
__macro_support, __tracing_log, Callsite, Event, Level,
|
||||
callsite::DefaultCallsite,
|
||||
field::{Field, ValueSet, Visit},
|
||||
Level,
|
||||
level_enabled,
|
||||
};
|
||||
|
||||
struct Visitor<'a>(&'a mut String);
|
||||
|
|
|
@ -152,8 +152,8 @@ impl Error {
|
|||
/// Generate the error message string.
|
||||
pub fn message(&self) -> String {
|
||||
match self {
|
||||
| Self::Federation(ref origin, ref error) => format!("Answer from {origin}: {error}"),
|
||||
| Self::Ruma(ref error) => response::ruma_error_message(error),
|
||||
| Self::Federation(origin, error) => format!("Answer from {origin}: {error}"),
|
||||
| Self::Ruma(error) => response::ruma_error_message(error),
|
||||
| _ => format!("{self}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
any::Any,
|
||||
panic::{panic_any, RefUnwindSafe, UnwindSafe},
|
||||
panic::{RefUnwindSafe, UnwindSafe, panic_any},
|
||||
};
|
||||
|
||||
use super::Error;
|
||||
|
|
|
@ -2,11 +2,11 @@ use bytes::BytesMut;
|
|||
use http::StatusCode;
|
||||
use http_body_util::Full;
|
||||
use ruma::api::{
|
||||
OutgoingResponse,
|
||||
client::{
|
||||
error::{ErrorBody, ErrorKind},
|
||||
uiaa::UiaaResponse,
|
||||
},
|
||||
OutgoingResponse,
|
||||
};
|
||||
|
||||
use super::Error;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::iter::once;
|
||||
|
||||
use ruma::{api::client::discovery::get_capabilities::RoomVersionStability, RoomVersionId};
|
||||
use ruma::{RoomVersionId, api::client::discovery::get_capabilities::RoomVersionStability};
|
||||
|
||||
use crate::{at, is_equal_to};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use tracing::Level;
|
||||
use tracing_core::{span::Current, Event};
|
||||
use tracing_core::{Event, span::Current};
|
||||
|
||||
use super::{layer::Value, Layer};
|
||||
use super::{Layer, layer::Value};
|
||||
use crate::{info, utils::string::EMPTY};
|
||||
|
||||
pub struct Data<'a> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::{
|
||||
super::{fmt, Level},
|
||||
super::{Level, fmt},
|
||||
Closure, Data,
|
||||
};
|
||||
use crate::Result;
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use std::{env, io, sync::LazyLock};
|
||||
|
||||
use tracing::{
|
||||
field::{Field, Visit},
|
||||
Event, Level, Subscriber,
|
||||
field::{Field, Visit},
|
||||
};
|
||||
use tracing_subscriber::{
|
||||
field::RecordFields,
|
||||
fmt,
|
||||
fmt::{
|
||||
format::{Compact, DefaultVisitor, Format, Full, Pretty, Writer},
|
||||
FmtContext, FormatEvent, FormatFields, MakeWriter,
|
||||
format::{Compact, DefaultVisitor, Format, Full, Pretty, Writer},
|
||||
},
|
||||
registry::LookupSpan,
|
||||
};
|
||||
|
||||
use crate::{apply, Config, Result};
|
||||
use crate::{Config, Result, apply};
|
||||
|
||||
static SYSTEMD_MODE: LazyLock<bool> =
|
||||
LazyLock::new(|| env::var("SYSTEMD_EXEC_PID").is_ok() && env::var("JOURNAL_STREAM").is_ok());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use super::{color, Level};
|
||||
use super::{Level, color};
|
||||
use crate::Result;
|
||||
|
||||
pub fn html<S>(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()>
|
||||
|
|
|
@ -9,7 +9,7 @@ mod reload;
|
|||
mod suppress;
|
||||
|
||||
pub use capture::Capture;
|
||||
pub use console::{is_systemd_mode, ConsoleFormat, ConsoleWriter};
|
||||
pub use console::{ConsoleFormat, ConsoleWriter, is_systemd_mode};
|
||||
pub use reload::{LogLevelReloadHandles, ReloadHandle};
|
||||
pub use suppress::Suppress;
|
||||
pub use tracing::Level;
|
||||
|
@ -34,7 +34,7 @@ pub struct Log {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! event {
|
||||
( $level:expr, $($x:tt)+ ) => { ::tracing::event!( $level, $($x)+ ) }
|
||||
( $level:expr_2021, $($x:tt)+ ) => { ::tracing::event!( $level, $($x)+ ) }
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use tracing_subscriber::{reload, EnvFilter};
|
||||
use tracing_subscriber::{EnvFilter, reload};
|
||||
|
||||
use crate::{error, Result};
|
||||
use crate::{Result, error};
|
||||
|
||||
/// We need to store a reload::Handle value, but can't name it's type explicitly
|
||||
/// because the S type parameter depends on the subscriber's previous layers. In
|
||||
|
|
|
@ -3,8 +3,8 @@ use std::{
|
|||
time::SystemTime,
|
||||
};
|
||||
|
||||
use super::{canary, new, path, Library, Symbol};
|
||||
use crate::{error, Result};
|
||||
use super::{Library, Symbol, canary, new, path};
|
||||
use crate::{Result, error};
|
||||
|
||||
pub struct Module {
|
||||
handle: Option<Library>,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::ffi::OsStr;
|
||||
|
||||
use super::{path, Library};
|
||||
use super::{Library, path};
|
||||
use crate::{Err, Result};
|
||||
|
||||
const OPEN_FLAGS: i32 = libloading::os::unix::RTLD_LAZY | libloading::os::unix::RTLD_GLOBAL;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
events::{EventContent, MessageLikeEventType, StateEventType, TimelineEventType},
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId,
|
||||
events::{EventContent, MessageLikeEventType, StateEventType, TimelineEventType},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||
use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
|
||||
|
||||
use super::StateKey;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::value::Value as JsonValue;
|
||||
|
||||
use crate::{err, implement, Result};
|
||||
use crate::{Result, err, implement};
|
||||
|
||||
#[must_use]
|
||||
#[implement(super::Pdu)]
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{cmp::Ordering, fmt, fmt::Display, str::FromStr};
|
|||
|
||||
use ruma::api::Direction;
|
||||
|
||||
use crate::{err, Error, Result};
|
||||
use crate::{Error, Result, err};
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub enum Count {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruma::{events::TimelineEventType, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId};
|
||||
use ruma::{MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, events::TimelineEventType};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use super::Pdu;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruma::{CanonicalJsonObject, OwnedEventId, RoomVersionId};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::{err, Result};
|
||||
use crate::{Result, err};
|
||||
|
||||
/// Generates a correct eventId for the incoming pdu.
|
||||
///
|
||||
|
|
|
@ -17,13 +17,14 @@ mod unsigned;
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use ruma::{
|
||||
events::TimelineEventType, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId,
|
||||
OwnedRoomId, OwnedServerName, OwnedUserId, UInt,
|
||||
CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||
OwnedUserId, UInt, events::TimelineEventType,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
pub use self::{
|
||||
Count as PduCount, Id as PduId, Pdu as PduEvent, RawId as RawPduId,
|
||||
builder::{Builder, Builder as PduBuilder},
|
||||
count::Count,
|
||||
event::Event,
|
||||
|
@ -31,7 +32,6 @@ pub use self::{
|
|||
id::*,
|
||||
raw_id::*,
|
||||
state_key::{ShortStateKey, StateKey},
|
||||
Count as PduCount, Id as PduId, Pdu as PduEvent, RawId as RawPduId,
|
||||
};
|
||||
use crate::Result;
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ impl RawId {
|
|||
#[must_use]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
match self {
|
||||
| Self::Normal(ref raw) => raw,
|
||||
| Self::Backfilled(ref raw) => raw,
|
||||
| Self::Normal(raw) => raw,
|
||||
| Self::Backfilled(raw) => raw,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use ruma::{
|
||||
canonical_json::redact_content_in_place,
|
||||
events::{room::redaction::RoomRedactionEventContent, TimelineEventType},
|
||||
OwnedEventId, RoomVersionId,
|
||||
canonical_json::redact_content_in_place,
|
||||
events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{
|
||||
json,
|
||||
value::{to_raw_value, RawValue as RawJsonValue},
|
||||
value::{RawValue as RawJsonValue, to_raw_value},
|
||||
};
|
||||
|
||||
use crate::{implement, Error, Result};
|
||||
use crate::{Error, Result, implement};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ExtractRedactedBecause {
|
||||
|
@ -76,14 +76,21 @@ pub fn copy_redacts(&self) -> (Option<OwnedEventId>, Box<RawJsonValue>) {
|
|||
if let Ok(mut content) =
|
||||
serde_json::from_str::<RoomRedactionEventContent>(self.content.get())
|
||||
{
|
||||
if let Some(redacts) = content.redacts {
|
||||
return (Some(redacts), self.content.clone());
|
||||
} else if let Some(redacts) = self.redacts.clone() {
|
||||
content.redacts = Some(redacts);
|
||||
return (
|
||||
self.redacts.clone(),
|
||||
to_raw_value(&content).expect("Must be valid, we only added redacts field"),
|
||||
);
|
||||
match content.redacts {
|
||||
| Some(redacts) => {
|
||||
return (Some(redacts), self.content.clone());
|
||||
},
|
||||
| _ => match self.redacts.clone() {
|
||||
| Some(redacts) => {
|
||||
content.redacts = Some(redacts);
|
||||
return (
|
||||
self.redacts.clone(),
|
||||
to_raw_value(&content)
|
||||
.expect("Must be valid, we only added redacts field"),
|
||||
);
|
||||
},
|
||||
| _ => {},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use ruma::{
|
||||
events::{
|
||||
room::member::RoomMemberEventContent, space::child::HierarchySpaceChildEvent,
|
||||
AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
|
||||
AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, StateEvent,
|
||||
room::member::RoomMemberEventContent, space::child::HierarchySpaceChildEvent,
|
||||
},
|
||||
serde::Raw,
|
||||
};
|
||||
|
|
|
@ -2,10 +2,10 @@ use std::collections::BTreeMap;
|
|||
|
||||
use ruma::MilliSecondsSinceUnixEpoch;
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue, Value as JsonValue};
|
||||
use serde_json::value::{RawValue as RawJsonValue, Value as JsonValue, to_raw_value};
|
||||
|
||||
use super::Pdu;
|
||||
use crate::{err, implement, is_true, Result};
|
||||
use crate::{Result, err, implement, is_true};
|
||||
|
||||
#[implement(Pdu)]
|
||||
pub fn remove_transaction_id(&mut self) -> Result {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ use std::{
|
|||
use ruma::OwnedServerName;
|
||||
use tokio::{runtime, sync::broadcast};
|
||||
|
||||
use crate::{config, config::Config, log::Log, metrics::Metrics, Err, Result};
|
||||
use crate::{Err, Result, config, config::Config, log::Log, metrics::Metrics};
|
||||
|
||||
/// Server runtime state; public portion
|
||||
pub struct Server {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use std::{borrow::Borrow, collections::BTreeSet};
|
||||
|
||||
use futures::{
|
||||
future::{join3, OptionFuture},
|
||||
Future,
|
||||
future::{OptionFuture, join3},
|
||||
};
|
||||
use ruma::{
|
||||
Int, OwnedUserId, RoomVersionId, UserId,
|
||||
events::room::{
|
||||
create::RoomCreateEventContent,
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
|
@ -14,21 +15,20 @@ use ruma::{
|
|||
},
|
||||
int,
|
||||
serde::{Base64, Raw},
|
||||
Int, OwnedUserId, RoomVersionId, UserId,
|
||||
};
|
||||
use serde::{
|
||||
de::{Error as _, IgnoredAny},
|
||||
Deserialize,
|
||||
de::{Error as _, IgnoredAny},
|
||||
};
|
||||
use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue};
|
||||
|
||||
use super::{
|
||||
Error, Event, Result, StateEventType, StateKey, TimelineEventType,
|
||||
power_levels::{
|
||||
deserialize_power_levels, deserialize_power_levels_content_fields,
|
||||
deserialize_power_levels_content_invite, deserialize_power_levels_content_redact,
|
||||
},
|
||||
room_version::RoomVersion,
|
||||
Error, Event, Result, StateEventType, StateKey, TimelineEventType,
|
||||
};
|
||||
use crate::{debug, error, trace, warn};
|
||||
|
||||
|
@ -394,28 +394,27 @@ where
|
|||
}
|
||||
|
||||
// If type is m.room.third_party_invite
|
||||
let sender_power_level = if let Some(pl) = &power_levels_event {
|
||||
let content = deserialize_power_levels_content_fields(pl.content().get(), room_version)?;
|
||||
if let Some(level) = content.get_user_power(sender) {
|
||||
*level
|
||||
} else {
|
||||
content.users_default
|
||||
}
|
||||
} else {
|
||||
// If no power level event found the creator gets 100 everyone else gets 0
|
||||
let is_creator = if room_version.use_room_create_sender {
|
||||
room_create_event.sender() == sender
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
from_json_str::<RoomCreateEventContent>(room_create_event.content().get())
|
||||
.is_ok_and(|create| create.creator.unwrap() == *sender)
|
||||
};
|
||||
let sender_power_level = match &power_levels_event {
|
||||
| Some(pl) => {
|
||||
let content =
|
||||
deserialize_power_levels_content_fields(pl.content().get(), room_version)?;
|
||||
match content.get_user_power(sender) {
|
||||
| Some(level) => *level,
|
||||
| _ => content.users_default,
|
||||
}
|
||||
},
|
||||
| _ => {
|
||||
// If no power level event found the creator gets 100 everyone else gets 0
|
||||
let is_creator = if room_version.use_room_create_sender {
|
||||
room_create_event.sender() == sender
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
from_json_str::<RoomCreateEventContent>(room_create_event.content().get())
|
||||
.is_ok_and(|create| create.creator.unwrap() == *sender)
|
||||
};
|
||||
|
||||
if is_creator {
|
||||
int!(100)
|
||||
} else {
|
||||
int!(0)
|
||||
}
|
||||
if is_creator { int!(100) } else { int!(0) }
|
||||
},
|
||||
};
|
||||
|
||||
// Allow if and only if sender's current power level is greater than
|
||||
|
@ -452,19 +451,21 @@ where
|
|||
if *incoming_event.event_type() == TimelineEventType::RoomPowerLevels {
|
||||
debug!("starting m.room.power_levels check");
|
||||
|
||||
if let Some(required_pwr_lvl) = check_power_levels(
|
||||
match check_power_levels(
|
||||
room_version,
|
||||
incoming_event,
|
||||
power_levels_event.as_ref(),
|
||||
sender_power_level,
|
||||
) {
|
||||
if !required_pwr_lvl {
|
||||
| Some(required_pwr_lvl) =>
|
||||
if !required_pwr_lvl {
|
||||
warn!("m.room.power_levels was not allowed");
|
||||
return Ok(false);
|
||||
},
|
||||
| _ => {
|
||||
warn!("m.room.power_levels was not allowed");
|
||||
return Ok(false);
|
||||
}
|
||||
} else {
|
||||
warn!("m.room.power_levels was not allowed");
|
||||
return Ok(false);
|
||||
},
|
||||
}
|
||||
debug!("m.room.power_levels event allowed");
|
||||
}
|
||||
|
@ -576,10 +577,9 @@ fn valid_membership_change(
|
|||
|
||||
let content =
|
||||
deserialize_power_levels_content_fields(pl.content().get(), room_version)?;
|
||||
let user_pl = if let Some(level) = content.get_user_power(user_for_join_auth) {
|
||||
*level
|
||||
} else {
|
||||
content.users_default
|
||||
let user_pl = match content.get_user_power(user_for_join_auth) {
|
||||
| Some(level) => *level,
|
||||
| _ => content.users_default,
|
||||
};
|
||||
|
||||
(user_pl, invite)
|
||||
|
@ -665,45 +665,48 @@ fn valid_membership_change(
|
|||
},
|
||||
| MembershipState::Invite => {
|
||||
// If content has third_party_invite key
|
||||
if let Some(tp_id) = third_party_invite.and_then(|i| i.deserialize().ok()) {
|
||||
if target_user_current_membership == MembershipState::Ban {
|
||||
warn!(?target_user_membership_event_id, "Can't invite banned user");
|
||||
false
|
||||
} else {
|
||||
let allow = verify_third_party_invite(
|
||||
Some(target_user),
|
||||
sender,
|
||||
&tp_id,
|
||||
current_third_party_invite,
|
||||
);
|
||||
if !allow {
|
||||
warn!("Third party invite invalid");
|
||||
}
|
||||
allow
|
||||
}
|
||||
} else if !sender_is_joined
|
||||
|| target_user_current_membership == MembershipState::Join
|
||||
|| target_user_current_membership == MembershipState::Ban
|
||||
{
|
||||
warn!(
|
||||
?target_user_membership_event_id,
|
||||
?sender_membership_event_id,
|
||||
"Can't invite user if sender not joined or the user is currently joined or \
|
||||
banned",
|
||||
);
|
||||
false
|
||||
} else {
|
||||
let allow = sender_power
|
||||
.filter(|&p| p >= &power_levels.invite)
|
||||
.is_some();
|
||||
if !allow {
|
||||
warn!(
|
||||
?target_user_membership_event_id,
|
||||
?power_levels_event_id,
|
||||
"User does not have enough power to invite",
|
||||
);
|
||||
}
|
||||
allow
|
||||
match third_party_invite.and_then(|i| i.deserialize().ok()) {
|
||||
| Some(tp_id) =>
|
||||
if target_user_current_membership == MembershipState::Ban {
|
||||
warn!(?target_user_membership_event_id, "Can't invite banned user");
|
||||
false
|
||||
} else {
|
||||
let allow = verify_third_party_invite(
|
||||
Some(target_user),
|
||||
sender,
|
||||
&tp_id,
|
||||
current_third_party_invite,
|
||||
);
|
||||
if !allow {
|
||||
warn!("Third party invite invalid");
|
||||
}
|
||||
allow
|
||||
},
|
||||
| _ =>
|
||||
if !sender_is_joined
|
||||
|| target_user_current_membership == MembershipState::Join
|
||||
|| target_user_current_membership == MembershipState::Ban
|
||||
{
|
||||
warn!(
|
||||
?target_user_membership_event_id,
|
||||
?sender_membership_event_id,
|
||||
"Can't invite user if sender not joined or the user is currently \
|
||||
joined or banned",
|
||||
);
|
||||
false
|
||||
} else {
|
||||
let allow = sender_power
|
||||
.filter(|&p| p >= &power_levels.invite)
|
||||
.is_some();
|
||||
if !allow {
|
||||
warn!(
|
||||
?target_user_membership_event_id,
|
||||
?power_levels_event_id,
|
||||
"User does not have enough power to invite",
|
||||
);
|
||||
}
|
||||
allow
|
||||
},
|
||||
}
|
||||
},
|
||||
| MembershipState::Leave =>
|
||||
|
@ -1111,23 +1114,23 @@ mod tests {
|
|||
use std::sync::Arc;
|
||||
|
||||
use ruma::events::{
|
||||
StateEventType, TimelineEventType,
|
||||
room::{
|
||||
join_rules::{
|
||||
AllowRule, JoinRule, Restricted, RoomJoinRulesEventContent, RoomMembership,
|
||||
},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
StateEventType, TimelineEventType,
|
||||
};
|
||||
use serde_json::value::to_raw_value as to_raw_json_value;
|
||||
|
||||
use crate::state_res::{
|
||||
Event, EventTypeExt, RoomVersion, StateMap,
|
||||
event_auth::valid_membership_change,
|
||||
test_utils::{
|
||||
alice, charlie, ella, event_id, member_content_ban, member_content_join, room_id,
|
||||
to_pdu_event, PduEvent, INITIAL_EVENTS, INITIAL_EVENTS_CREATE_ROOM,
|
||||
INITIAL_EVENTS, INITIAL_EVENTS_CREATE_ROOM, PduEvent, alice, charlie, ella, event_id,
|
||||
member_content_ban, member_content_join, room_id, to_pdu_event,
|
||||
},
|
||||
Event, EventTypeExt, RoomVersion, StateMap,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -1156,21 +1159,23 @@ mod tests {
|
|||
let target_user = charlie();
|
||||
let sender = alice();
|
||||
|
||||
assert!(valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1199,21 +1204,23 @@ mod tests {
|
|||
let target_user = charlie();
|
||||
let sender = charlie();
|
||||
|
||||
assert!(!valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
!valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1242,21 +1249,23 @@ mod tests {
|
|||
let target_user = alice();
|
||||
let sender = alice();
|
||||
|
||||
assert!(valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1285,21 +1294,23 @@ mod tests {
|
|||
let target_user = alice();
|
||||
let sender = charlie();
|
||||
|
||||
assert!(!valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
!valid_membership_change(
|
||||
&RoomVersion::V6,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1345,37 +1356,41 @@ mod tests {
|
|||
let target_user = ella();
|
||||
let sender = ella();
|
||||
|
||||
assert!(valid_membership_change(
|
||||
&RoomVersion::V9,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
Some(alice()),
|
||||
&MembershipState::Join,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
valid_membership_change(
|
||||
&RoomVersion::V9,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
Some(alice()),
|
||||
&MembershipState::Join,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
assert!(!valid_membership_change(
|
||||
&RoomVersion::V9,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
Some(ella()),
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
!valid_membership_change(
|
||||
&RoomVersion::V9,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
Some(ella()),
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1413,20 +1428,22 @@ mod tests {
|
|||
let target_user = ella();
|
||||
let sender = ella();
|
||||
|
||||
assert!(valid_membership_change(
|
||||
&RoomVersion::V7,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap());
|
||||
assert!(
|
||||
valid_membership_change(
|
||||
&RoomVersion::V7,
|
||||
target_user,
|
||||
fetch_state(StateEventType::RoomMember, target_user.as_str().into()).as_ref(),
|
||||
sender,
|
||||
fetch_state(StateEventType::RoomMember, sender.as_str().into()).as_ref(),
|
||||
&requester,
|
||||
None::<&PduEvent>,
|
||||
fetch_state(StateEventType::RoomPowerLevels, "".into()).as_ref(),
|
||||
fetch_state(StateEventType::RoomJoinRules, "".into()).as_ref(),
|
||||
None,
|
||||
&MembershipState::Leave,
|
||||
&fetch_state(StateEventType::RoomCreate, "".into()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@ use std::{
|
|||
hash::{BuildHasher, Hash},
|
||||
};
|
||||
|
||||
use futures::{future, stream, Future, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
|
||||
use futures::{Future, FutureExt, StreamExt, TryFutureExt, TryStreamExt, future, stream};
|
||||
use ruma::{
|
||||
EventId, Int, MilliSecondsSinceUnixEpoch, RoomVersionId,
|
||||
events::{
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
StateEventType, TimelineEventType,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
int, EventId, Int, MilliSecondsSinceUnixEpoch, RoomVersionId,
|
||||
int,
|
||||
};
|
||||
use serde_json::from_str as from_json_str;
|
||||
|
||||
|
@ -263,7 +264,7 @@ where
|
|||
#[allow(clippy::arithmetic_side_effects)]
|
||||
fn get_auth_chain_diff<Id, Hasher>(
|
||||
auth_chain_sets: &[HashSet<Id, Hasher>],
|
||||
) -> impl Iterator<Item = Id> + Send
|
||||
) -> impl Iterator<Item = Id> + Send + use<Id, Hasher>
|
||||
where
|
||||
Id: Clone + Eq + Hash + Send,
|
||||
Hasher: BuildHasher + Send + Sync,
|
||||
|
@ -864,23 +865,23 @@ mod tests {
|
|||
use maplit::{hashmap, hashset};
|
||||
use rand::seq::SliceRandom;
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomVersionId,
|
||||
events::{
|
||||
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
StateEventType, TimelineEventType,
|
||||
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
},
|
||||
int, uint, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomVersionId,
|
||||
int, uint,
|
||||
};
|
||||
use serde_json::{json, value::to_raw_value as to_raw_json_value};
|
||||
|
||||
use super::{
|
||||
is_power_event,
|
||||
Event, EventTypeExt, StateMap, is_power_event,
|
||||
room_version::RoomVersion,
|
||||
test_utils::{
|
||||
alice, bob, charlie, do_check, ella, event_id, member_content_ban,
|
||||
member_content_join, room_id, to_init_pdu_event, to_pdu_event, zara, PduEvent,
|
||||
TestStore, INITIAL_EVENTS,
|
||||
INITIAL_EVENTS, PduEvent, TestStore, alice, bob, charlie, do_check, ella, event_id,
|
||||
member_content_ban, member_content_join, room_id, to_init_pdu_event, to_pdu_event,
|
||||
zara,
|
||||
},
|
||||
Event, EventTypeExt, StateMap,
|
||||
};
|
||||
use crate::debug;
|
||||
|
||||
|
@ -1557,7 +1558,7 @@ mod tests {
|
|||
}
|
||||
|
||||
macro_rules! state_set {
|
||||
($($kind:expr => $key:expr => $id:expr),* $(,)?) => {{
|
||||
($($kind:expr_2021 => $key:expr_2021 => $id:expr_2021),* $(,)?) => {{
|
||||
#[allow(unused_mut)]
|
||||
let mut x = StateMap::new();
|
||||
$(
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
events::{room::power_levels::RoomPowerLevelsEventContent, TimelineEventType},
|
||||
power_levels::{default_power_level, NotificationPowerLevels},
|
||||
Int, OwnedUserId, UserId,
|
||||
events::{TimelineEventType, room::power_levels::RoomPowerLevelsEventContent},
|
||||
power_levels::{NotificationPowerLevels, default_power_level},
|
||||
serde::{
|
||||
deserialize_v1_powerlevel, vec_deserialize_int_powerlevel_values,
|
||||
vec_deserialize_v1_powerlevel_values,
|
||||
},
|
||||
Int, OwnedUserId, UserId,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{from_str as from_json_str, Error};
|
||||
use serde_json::{Error, from_str as from_json_str};
|
||||
use tracing::error;
|
||||
|
||||
use super::{Result, RoomVersion};
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use ruma::{events::TimelineEventType, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId};
|
||||
use ruma::{EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, events::TimelineEventType};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
/// Abstraction of a PDU so users can have their own PDU types.
|
||||
|
|
|
@ -2,33 +2,33 @@ use std::{
|
|||
borrow::Borrow,
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering::SeqCst},
|
||||
Arc,
|
||||
atomic::{AtomicU64, Ordering::SeqCst},
|
||||
},
|
||||
};
|
||||
|
||||
use futures::future::ready;
|
||||
use ruma::{
|
||||
event_id,
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, ServerSignatures,
|
||||
UserId, event_id,
|
||||
events::{
|
||||
TimelineEventType,
|
||||
pdu::{EventHash, Pdu, RoomV3Pdu},
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
TimelineEventType,
|
||||
},
|
||||
int, room_id, uint, user_id, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId,
|
||||
RoomVersionId, ServerSignatures, UserId,
|
||||
int, room_id, uint, user_id,
|
||||
};
|
||||
use serde_json::{
|
||||
json,
|
||||
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},
|
||||
value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value},
|
||||
};
|
||||
|
||||
pub(crate) use self::event::PduEvent;
|
||||
use super::auth_types_for_event;
|
||||
use crate::{info, Event, EventTypeExt, Result, StateMap};
|
||||
use crate::{Event, EventTypeExt, Result, StateMap, info};
|
||||
|
||||
static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
|
@ -584,8 +584,8 @@ pub(crate) fn INITIAL_EDGES() -> Vec<OwnedEventId> {
|
|||
|
||||
pub(crate) mod event {
|
||||
use ruma::{
|
||||
events::{pdu::Pdu, TimelineEventType},
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId,
|
||||
events::{TimelineEventType, pdu::Pdu},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bytesize::ByteSize;
|
||||
|
||||
use crate::{err, Result};
|
||||
use crate::{Result, err};
|
||||
|
||||
/// Parse a human-writable size string w/ si-unit suffix into integer
|
||||
#[inline]
|
||||
|
|
|
@ -12,14 +12,14 @@ macro_rules! defer {
|
|||
let _defer_ = _Defer_ { closure: || $body };
|
||||
};
|
||||
|
||||
($body:expr) => {
|
||||
($body:expr_2021) => {
|
||||
$crate::defer! {{ $body }}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! scope_restore {
|
||||
($val:ident, $ours:expr) => {
|
||||
($val:ident, $ours:expr_2021) => {
|
||||
let theirs = $crate::utils::exchange($val, $ours);
|
||||
$crate::defer! {{ *$val = theirs; }};
|
||||
};
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
use std::marker::Unpin;
|
||||
|
||||
use futures::{
|
||||
future::{select_ok, try_join, try_join_all, try_select},
|
||||
Future, FutureExt,
|
||||
future::{select_ok, try_join, try_join_all, try_select},
|
||||
};
|
||||
|
||||
pub trait BoolExt
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::marker::Unpin;
|
||||
|
||||
use futures::{future, future::Select, Future};
|
||||
use futures::{Future, future, future::Select};
|
||||
|
||||
/// This interface is not necessarily complete; feel free to add as-needed.
|
||||
pub trait ExtExt<T>
|
||||
|
|
|
@ -3,7 +3,7 @@ mod ext_ext;
|
|||
mod option_ext;
|
||||
mod try_ext_ext;
|
||||
|
||||
pub use bool_ext::{and, or, BoolExt};
|
||||
pub use bool_ext::{BoolExt, and, or};
|
||||
pub use ext_ext::ExtExt;
|
||||
pub use option_ext::OptionExt;
|
||||
pub use try_ext_ext::TryExtExt;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::wrong_self_convention)]
|
||||
|
||||
use futures::{future::OptionFuture, Future, FutureExt};
|
||||
use futures::{Future, FutureExt, future::OptionFuture};
|
||||
|
||||
pub trait OptionExt<T> {
|
||||
fn is_none_or(self, f: impl FnOnce(&T) -> bool + Send) -> impl Future<Output = bool> + Send;
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
use std::marker::Unpin;
|
||||
|
||||
use futures::{
|
||||
future,
|
||||
TryFuture, TryFutureExt, future,
|
||||
future::{MapOkOrElse, TrySelect, UnwrapOrElse},
|
||||
TryFuture, TryFutureExt,
|
||||
};
|
||||
|
||||
/// This interface is not necessarily complete; feel free to add as-needed.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::sync::OnceLock;
|
||||
|
||||
use argon2::{
|
||||
password_hash, password_hash::SaltString, Algorithm, Argon2, Params, PasswordHash,
|
||||
PasswordHasher, PasswordVerifier, Version,
|
||||
Algorithm, Argon2, Params, PasswordHash, PasswordHasher, PasswordVerifier, Version,
|
||||
password_hash, password_hash::SaltString,
|
||||
};
|
||||
|
||||
use crate::{err, Error, Result};
|
||||
use crate::{Error, Result, err};
|
||||
|
||||
const M_COST: u32 = Params::DEFAULT_M_COST; // memory size in 1 KiB blocks
|
||||
const T_COST: u32 = Params::DEFAULT_T_COST; // nr of iterations
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{fmt, str::FromStr};
|
||||
|
||||
use ruma::{canonical_json::try_from_json_map, CanonicalJsonError, CanonicalJsonObject};
|
||||
use ruma::{CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{cmp, convert::TryFrom};
|
|||
pub use checked_ops::checked_ops;
|
||||
|
||||
pub use self::{expected::Expected, tried::Tried};
|
||||
use crate::{debug::type_name, err, Err, Error, Result};
|
||||
use crate::{Err, Error, Result, debug::type_name, err};
|
||||
|
||||
/// Checked arithmetic expression. Returns a Result<R, Error::Arithmetic>
|
||||
#[macro_export]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use num_traits::ops::checked::{CheckedAdd, CheckedDiv, CheckedMul, CheckedRem, CheckedSub};
|
||||
|
||||
use crate::{checked, Result};
|
||||
use crate::{Result, checked};
|
||||
|
||||
pub trait Tried {
|
||||
#[inline]
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn exchange<T>(state: &mut T, source: T) -> T { std::mem::replace(state, sou
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! extract_variant {
|
||||
($e:expr, $variant:path) => {
|
||||
($e:expr_2021, $variant:path) => {
|
||||
match $e {
|
||||
| $variant(value) => Some(value),
|
||||
| _ => None,
|
||||
|
@ -90,7 +90,7 @@ macro_rules! pair_of {
|
|||
($decl, $decl)
|
||||
};
|
||||
|
||||
($init:expr) => {
|
||||
($init:expr_2021) => {
|
||||
($init, $init)
|
||||
};
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ macro_rules! is_equal_to {
|
|||
|x| x == $val
|
||||
};
|
||||
|
||||
($val:expr) => {
|
||||
($val:expr_2021) => {
|
||||
|x| x == $val
|
||||
};
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ macro_rules! is_less_than {
|
|||
|x| x < $val
|
||||
};
|
||||
|
||||
($val:expr) => {
|
||||
($val:expr_2021) => {
|
||||
|x| x < $val
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
|
||||
use tokio::sync::OwnedMutexGuard as Omg;
|
||||
|
||||
use crate::{err, Result};
|
||||
use crate::{Result, err};
|
||||
|
||||
/// Map of Mutexes
|
||||
pub struct MutexMap<Key, Val> {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
};
|
||||
|
||||
use arrayvec::ArrayString;
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng};
|
||||
use rand::{Rng, seq::SliceRandom, thread_rng};
|
||||
|
||||
pub fn shuffle<T>(vec: &mut [T]) {
|
||||
let mut rng = thread_rng();
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
use std::convert::identity;
|
||||
|
||||
use futures::{
|
||||
stream::{Stream, StreamExt},
|
||||
Future,
|
||||
stream::{Stream, StreamExt},
|
||||
};
|
||||
|
||||
use super::{automatic_width, ReadyExt};
|
||||
use super::{ReadyExt, automatic_width};
|
||||
|
||||
/// Concurrency extensions to augment futures::StreamExt. broad_ combinators
|
||||
/// produce out-of-order
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::clone::Clone;
|
||||
|
||||
use futures::{stream::Map, Stream, StreamExt};
|
||||
use futures::{Stream, StreamExt, stream::Map};
|
||||
|
||||
pub trait Cloned<'a, T, S>
|
||||
where
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use futures::{future::ready, Stream, StreamExt, TryStream};
|
||||
use futures::{Stream, StreamExt, TryStream, future::ready};
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use futures::{
|
||||
stream,
|
||||
StreamExt, stream,
|
||||
stream::{Stream, TryStream},
|
||||
StreamExt,
|
||||
};
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
|
|
@ -14,8 +14,8 @@ mod try_wideband;
|
|||
mod wideband;
|
||||
|
||||
pub use band::{
|
||||
automatic_amplification, automatic_width, set_amplification, set_width, AMPLIFICATION_LIMIT,
|
||||
WIDTH_LIMIT,
|
||||
AMPLIFICATION_LIMIT, WIDTH_LIMIT, automatic_amplification, automatic_width,
|
||||
set_amplification, set_width,
|
||||
};
|
||||
pub use broadband::BroadbandExt;
|
||||
pub use cloned::Cloned;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use futures::{
|
||||
future::{ready, Ready},
|
||||
future::{Ready, ready},
|
||||
stream::{
|
||||
All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
|
||||
},
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Parallelism stream combinator extensions to futures::Stream
|
||||
|
||||
use futures::{stream::TryStream, TryFutureExt};
|
||||
use futures::{TryFutureExt, stream::TryStream};
|
||||
use tokio::{runtime, task::JoinError};
|
||||
|
||||
use super::TryBroadbandExt;
|
||||
use crate::{utils::sys::available_parallelism, Error, Result};
|
||||
use crate::{Error, Result, utils::sys::available_parallelism};
|
||||
|
||||
/// Parallelism extensions to augment futures::StreamExt. These combinators are
|
||||
/// for computation-oriented workloads, unlike -band combinators for I/O
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use futures::{
|
||||
future::{ready, Ready},
|
||||
future::{Ready, ready},
|
||||
stream::{AndThen, TryFilterMap, TryFold, TryForEach, TryStream, TryStreamExt, TryTakeWhile},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! TryStreamTools for futures::TryStream
|
||||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use futures::{future, future::Ready, stream::TryTakeWhile, TryStream, TryStreamExt};
|
||||
use futures::{TryStream, TryStreamExt, future, future::Ready, stream::TryTakeWhile};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
use std::convert::identity;
|
||||
|
||||
use futures::{
|
||||
stream::{Stream, StreamExt},
|
||||
Future,
|
||||
stream::{Stream, StreamExt},
|
||||
};
|
||||
|
||||
use super::{automatic_width, ReadyExt};
|
||||
use super::{ReadyExt, automatic_width};
|
||||
|
||||
/// Concurrency extensions to augment futures::StreamExt. wideband_ combinators
|
||||
/// produce in-order.
|
||||
|
|
|
@ -5,7 +5,7 @@ mod unquote;
|
|||
mod unquoted;
|
||||
|
||||
pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::Unquoted};
|
||||
use crate::{utils::exchange, Result};
|
||||
use crate::{Result, utils::exchange};
|
||||
|
||||
pub const EMPTY: &str = "";
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use serde::{de, Deserialize, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, de};
|
||||
|
||||
use super::Unquote;
|
||||
use crate::{err, Result};
|
||||
use crate::{Result, err};
|
||||
|
||||
/// Unquoted string which deserialized from a quoted string. Construction from a
|
||||
/// &str is infallible such that the input can already be unquoted. Construction
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::path::PathBuf;
|
|||
|
||||
pub use compute::available_parallelism;
|
||||
|
||||
use crate::{debug, Result};
|
||||
use crate::{Result, debug};
|
||||
|
||||
/// This is needed for opening lots of file descriptors, which tends to
|
||||
/// happen more often when using RocksDB and making lots of federation
|
||||
|
@ -16,7 +16,7 @@ use crate::{debug, Result};
|
|||
/// * <https://github.com/systemd/systemd/commit/0abf94923b4a95a7d89bc526efc84e7ca2b71741>
|
||||
#[cfg(unix)]
|
||||
pub fn maximize_fd_limit() -> Result<(), nix::errno::Errno> {
|
||||
use nix::sys::resource::{getrlimit, setrlimit, Resource::RLIMIT_NOFILE as NOFILE};
|
||||
use nix::sys::resource::{Resource::RLIMIT_NOFILE as NOFILE, getrlimit, setrlimit};
|
||||
|
||||
let (soft_limit, hard_limit) = getrlimit(NOFILE)?;
|
||||
if soft_limit < hard_limit {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{cell::Cell, fmt::Debug, path::PathBuf, sync::LazyLock};
|
||||
|
||||
use crate::{is_equal_to, Result};
|
||||
use crate::{Result, is_equal_to};
|
||||
|
||||
type Id = usize;
|
||||
|
||||
|
@ -45,7 +45,7 @@ pub fn set_affinity<I>(mut ids: I)
|
|||
where
|
||||
I: Iterator<Item = Id> + Clone + Debug,
|
||||
{
|
||||
use core_affinity::{set_each_for_current, set_for_current, CoreId};
|
||||
use core_affinity::{CoreId, set_each_for_current, set_for_current};
|
||||
|
||||
let n = ids.clone().count();
|
||||
let mask: Mask = ids.clone().fold(0, |mask, id| {
|
||||
|
@ -118,7 +118,7 @@ pub fn cores_available() -> impl Iterator<Item = Id> { from_mask(*CORES_AVAILABL
|
|||
#[cfg(target_os = "linux")]
|
||||
#[inline]
|
||||
pub fn getcpu() -> Result<usize> {
|
||||
use crate::{utils::math, Error};
|
||||
use crate::{Error, utils::math};
|
||||
|
||||
// SAFETY: This is part of an interface with many low-level calls taking many
|
||||
// raw params, but it's unclear why this specific call is unsafe. Nevertheless
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::{
|
||||
ffi::OsStr,
|
||||
fs,
|
||||
fs::{read_to_string, FileType},
|
||||
fs::{FileType, read_to_string},
|
||||
iter::IntoIterator,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
@ -11,9 +11,9 @@ use std::{
|
|||
use libc::dev_t;
|
||||
|
||||
use crate::{
|
||||
Result,
|
||||
result::FlatOk,
|
||||
utils::{result::LogDebugErr, string::SplitInfallible},
|
||||
Result,
|
||||
};
|
||||
|
||||
/// Device characteristics useful for random access throughput
|
||||
|
|
|
@ -241,7 +241,7 @@ fn set_intersection_sorted_all() {
|
|||
#[tokio::test]
|
||||
async fn set_intersection_sorted_stream2() {
|
||||
use futures::StreamExt;
|
||||
use utils::{set::intersection_sorted_stream2, IterStream};
|
||||
use utils::{IterStream, set::intersection_sorted_stream2};
|
||||
|
||||
let a = ["bar"];
|
||||
let b = ["bar", "foo"];
|
||||
|
|
|
@ -2,7 +2,7 @@ pub mod exponential_backoff;
|
|||
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::{err, Result};
|
||||
use crate::{Result, err};
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue