mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-27 20:45:30 +00:00
cargo fmt
This commit is contained in:
parent
d5b4754cf4
commit
7822a385bb
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{api::client_server, services, utils, Error, Result, Ruma};
|
use crate::{api::client_server, services, utils, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
|
@ -11,12 +9,7 @@ use ruma::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
uiaa::{AuthFlow, AuthType, UiaaInfo},
|
uiaa::{AuthFlow, AuthType, UiaaInfo},
|
||||||
},
|
},
|
||||||
events::{
|
events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType},
|
||||||
room::{
|
|
||||||
message::RoomMessageEventContent,
|
|
||||||
},
|
|
||||||
GlobalAccountDataEventType,
|
|
||||||
},
|
|
||||||
push, UserId,
|
push, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,11 @@ use ruma::{
|
||||||
federation::{self, membership::create_invite},
|
federation::{self, membership::create_invite},
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
room::{
|
room::member::{MembershipState, RoomMemberEventContent},
|
||||||
member::{MembershipState, RoomMemberEventContent},
|
|
||||||
},
|
|
||||||
RoomEventType, StateEventType,
|
RoomEventType, StateEventType,
|
||||||
},
|
},
|
||||||
serde::{to_canonical_value, Base64, CanonicalJsonObject, CanonicalJsonValue}, EventId, RoomId, RoomVersionId, ServerName, UserId,
|
serde::{to_canonical_value, Base64, CanonicalJsonObject, CanonicalJsonValue},
|
||||||
|
EventId, RoomId, RoomVersionId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||||
use std::{
|
use std::{
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
services, utils, Error, PduEvent, Result, Ruma,
|
services, utils, Error, PduEvent, Result, Ruma,
|
||||||
};
|
};
|
||||||
use axum::{response::IntoResponse, Json};
|
use axum::{response::IntoResponse, Json};
|
||||||
use futures_util::{StreamExt};
|
use futures_util::StreamExt;
|
||||||
use get_profile_information::v1::ProfileField;
|
use get_profile_information::v1::ProfileField;
|
||||||
use http::header::{HeaderValue, AUTHORIZATION};
|
use http::header::{HeaderValue, AUTHORIZATION};
|
||||||
|
|
||||||
|
@ -15,10 +15,7 @@ use ruma::{
|
||||||
authorization::get_event_authorization,
|
authorization::get_event_authorization,
|
||||||
device::get_devices::{self, v1::UserDevice},
|
device::get_devices::{self, v1::UserDevice},
|
||||||
directory::{get_public_rooms, get_public_rooms_filtered},
|
directory::{get_public_rooms, get_public_rooms_filtered},
|
||||||
discovery::{
|
discovery::{get_server_keys, get_server_version, ServerSigningKeys, VerifyKey},
|
||||||
get_server_keys,
|
|
||||||
get_server_version, ServerSigningKeys, VerifyKey,
|
|
||||||
},
|
|
||||||
event::{get_event, get_missing_events, get_room_state, get_room_state_ids},
|
event::{get_event, get_missing_events, get_room_state, get_room_state_ids},
|
||||||
keys::{claim_keys, get_keys},
|
keys::{claim_keys, get_keys},
|
||||||
membership::{
|
membership::{
|
||||||
|
@ -46,13 +43,13 @@ use ruma::{
|
||||||
},
|
},
|
||||||
receipt::ReceiptType,
|
receipt::ReceiptType,
|
||||||
serde::{Base64, JsonObject, Raw},
|
serde::{Base64, JsonObject, Raw},
|
||||||
signatures::{CanonicalJsonValue},
|
signatures::CanonicalJsonValue,
|
||||||
to_device::DeviceIdOrAllDevices, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName,
|
to_device::DeviceIdOrAllDevices,
|
||||||
ServerSigningKeyId,
|
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId,
|
||||||
};
|
};
|
||||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap},
|
collections::BTreeMap,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
mem,
|
mem,
|
||||||
net::{IpAddr, SocketAddr},
|
net::{IpAddr, SocketAddr},
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{error::ErrorKind},
|
api::client::error::ErrorKind,
|
||||||
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
||||||
serde::Raw, RoomId, UserId,
|
serde::Raw,
|
||||||
|
RoomId, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
||||||
|
|
||||||
impl service::account_data::Data for KeyValueDatabase {
|
impl service::account_data::Data for KeyValueDatabase {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use ruma::{
|
||||||
UserId,
|
UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{database::KeyValueDatabase, service, Error, Result, utils};
|
use crate::{database::KeyValueDatabase, service, utils, Error, Result};
|
||||||
|
|
||||||
impl service::pusher::Data for KeyValueDatabase {
|
impl service::pusher::Data for KeyValueDatabase {
|
||||||
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::Pusher) -> Result<()> {
|
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::Pusher) -> Result<()> {
|
||||||
|
@ -28,7 +28,11 @@ impl service::pusher::Data for KeyValueDatabase {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<get_pushers::v3::Pusher>> {
|
fn get_pusher(
|
||||||
|
&self,
|
||||||
|
sender: &UserId,
|
||||||
|
pushkey: &str,
|
||||||
|
) -> Result<Option<get_pushers::v3::Pusher>> {
|
||||||
let mut senderkey = sender.as_bytes().to_vec();
|
let mut senderkey = sender.as_bytes().to_vec();
|
||||||
senderkey.push(0xff);
|
senderkey.push(0xff);
|
||||||
senderkey.extend_from_slice(pushkey.as_bytes());
|
senderkey.extend_from_slice(pushkey.as_bytes());
|
||||||
|
@ -55,15 +59,21 @@ impl service::pusher::Data for KeyValueDatabase {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pushkeys<'a>(&'a self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>> + 'a> {
|
fn get_pushkeys<'a>(
|
||||||
|
&'a self,
|
||||||
|
sender: &UserId,
|
||||||
|
) -> Box<dyn Iterator<Item = Result<String>> + 'a> {
|
||||||
let mut prefix = sender.as_bytes().to_vec();
|
let mut prefix = sender.as_bytes().to_vec();
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
|
|
||||||
Box::new(self.senderkey_pusher.scan_prefix(prefix).map(|(k, _)| {
|
Box::new(self.senderkey_pusher.scan_prefix(prefix).map(|(k, _)| {
|
||||||
let mut parts = k.splitn(2, |&b| b == 0xff);
|
let mut parts = k.splitn(2, |&b| b == 0xff);
|
||||||
let _senderkey = parts.next();
|
let _senderkey = parts.next();
|
||||||
let push_key = parts.next().ok_or_else(|| Error::bad_database("Invalid senderkey_pusher in db"))?;
|
let push_key = parts
|
||||||
let push_key_string = utils::string_from_bytes(push_key).map_err(|_| Error::bad_database("Invalid pusher bytes in senderkey_pusher"))?;
|
.next()
|
||||||
|
.ok_or_else(|| Error::bad_database("Invalid senderkey_pusher in db"))?;
|
||||||
|
let push_key_string = utils::string_from_bytes(push_key)
|
||||||
|
.map_err(|_| Error::bad_database("Invalid pusher bytes in senderkey_pusher"))?;
|
||||||
|
|
||||||
Ok(push_key_string)
|
Ok(push_key_string)
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -54,12 +54,12 @@ impl service::rooms::edus::read_receipt::Data for KeyValueDatabase {
|
||||||
since: u64,
|
since: u64,
|
||||||
) -> Box<
|
) -> Box<
|
||||||
dyn Iterator<
|
dyn Iterator<
|
||||||
Item = Result<(
|
Item = Result<(
|
||||||
Box<UserId>,
|
Box<UserId>,
|
||||||
u64,
|
u64,
|
||||||
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
|
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
|
||||||
)>,
|
)>,
|
||||||
> + 'a,
|
> + 'a,
|
||||||
> {
|
> {
|
||||||
let mut prefix = room_id.as_bytes().to_vec();
|
let mut prefix = room_id.as_bytes().to_vec();
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use ruma::RoomId;
|
use ruma::RoomId;
|
||||||
|
|
||||||
use crate::{database::KeyValueDatabase, service, services, Result, utils, Error};
|
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result};
|
||||||
|
|
||||||
impl service::rooms::metadata::Data for KeyValueDatabase {
|
impl service::rooms::metadata::Data for KeyValueDatabase {
|
||||||
fn exists(&self, room_id: &RoomId) -> Result<bool> {
|
fn exists(&self, room_id: &RoomId) -> Result<bool> {
|
||||||
|
@ -27,7 +27,6 @@ impl service::rooms::metadata::Data for KeyValueDatabase {
|
||||||
)
|
)
|
||||||
.map_err(|_| Error::bad_database("Room ID in roomid_shortroomid is invalid."))
|
.map_err(|_| Error::bad_database("Room ID in roomid_shortroomid is invalid."))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
|
fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl service::rooms::search::Data for KeyValueDatabase {
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
search_string: &str,
|
search_string: &str,
|
||||||
) -> Result<Option<(Box<dyn Iterator<Item = Vec<u8>>+ 'a>, Vec<String>)>> {
|
) -> Result<Option<(Box<dyn Iterator<Item = Vec<u8>> + 'a>, Vec<String>)>> {
|
||||||
let prefix = services()
|
let prefix = services()
|
||||||
.rooms
|
.rooms
|
||||||
.short
|
.short
|
||||||
|
|
|
@ -5,8 +5,7 @@ use ruma::{
|
||||||
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
|
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
|
||||||
events::{AnyToDeviceEvent, StateEventType},
|
events::{AnyToDeviceEvent, StateEventType},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, MxcUri,
|
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, MxcUri, UInt, UserId,
|
||||||
UInt, UserId,
|
|
||||||
};
|
};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
|
@ -956,4 +955,3 @@ fn get_username_with_valid_password(username: &[u8], password: &[u8]) -> Option<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,13 @@ pub mod abstraction;
|
||||||
pub mod key_value;
|
pub mod key_value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
service::{
|
service::rooms::state_compressor::CompressedStateEvent, services, utils, Config, Error,
|
||||||
rooms::{state_compressor::CompressedStateEvent},
|
PduEvent, Result, Services, SERVICES,
|
||||||
},
|
|
||||||
services, utils, Config, Error, PduEvent, Result, Services, SERVICES,
|
|
||||||
};
|
};
|
||||||
use abstraction::KeyValueDatabaseEngine;
|
use abstraction::KeyValueDatabaseEngine;
|
||||||
use abstraction::KvTree;
|
use abstraction::KvTree;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use futures_util::{StreamExt};
|
use futures_util::StreamExt;
|
||||||
use lru_cache::LruCache;
|
use lru_cache::LruCache;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{
|
events::{
|
||||||
|
@ -29,7 +27,7 @@ use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{Arc, Mutex, RwLock},
|
sync::{Arc, Mutex, RwLock},
|
||||||
};
|
};
|
||||||
use tokio::sync::{mpsc};
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
|
|
||||||
pub struct KeyValueDatabase {
|
pub struct KeyValueDatabase {
|
||||||
|
|
|
@ -13,15 +13,13 @@ mod database;
|
||||||
mod service;
|
mod service;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use std::{
|
use std::sync::RwLock;
|
||||||
sync::{RwLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use api::ruma_wrapper::{Ruma, RumaResponse};
|
pub use api::ruma_wrapper::{Ruma, RumaResponse};
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
|
pub use database::KeyValueDatabase;
|
||||||
pub use service::{pdu::PduEvent, Services};
|
pub use service::{pdu::PduEvent, Services};
|
||||||
pub use utils::error::{Error, Result};
|
pub use utils::error::{Error, Result};
|
||||||
pub use database::KeyValueDatabase;
|
|
||||||
|
|
||||||
pub static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None);
|
pub static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ use tower_http::{
|
||||||
trace::TraceLayer,
|
trace::TraceLayer,
|
||||||
ServiceBuilderExt as _,
|
ServiceBuilderExt as _,
|
||||||
};
|
};
|
||||||
use tracing::{warn, info};
|
use tracing::{info, warn};
|
||||||
use tracing_subscriber::{prelude::*, EnvFilter};
|
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||||
|
|
||||||
pub use conduit::*; // Re-export everything from the library crate
|
pub use conduit::*; // Re-export everything from the library crate
|
||||||
|
|
|
@ -4,13 +4,13 @@ pub use data::Data;
|
||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
||||||
serde::Raw, RoomId, UserId,
|
serde::Raw,
|
||||||
|
RoomId, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
|
use crate::Result;
|
||||||
use crate::{Result};
|
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub db: &'static dyn Data,
|
pub db: &'static dyn Data,
|
||||||
|
|
|
@ -29,9 +29,7 @@ use serde_json::value::to_raw_value;
|
||||||
use tokio::sync::{mpsc, MutexGuard};
|
use tokio::sync::{mpsc, MutexGuard};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
||||||
client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
|
||||||
},
|
|
||||||
services,
|
services,
|
||||||
utils::{self, HtmlEscape},
|
utils::{self, HtmlEscape},
|
||||||
Error, PduEvent, Result,
|
Error, PduEvent, Result,
|
||||||
|
@ -177,7 +175,9 @@ impl Service {
|
||||||
let self1 = Arc::new(Self { sender });
|
let self1 = Arc::new(Self { sender });
|
||||||
let self2 = Arc::clone(&self1);
|
let self2 = Arc::clone(&self1);
|
||||||
|
|
||||||
tokio::spawn(async move { self2.start_handler(receiver).await; });
|
tokio::spawn(async move {
|
||||||
|
self2.start_handler(receiver).await;
|
||||||
|
});
|
||||||
|
|
||||||
self1
|
self1
|
||||||
}
|
}
|
||||||
|
@ -186,9 +186,8 @@ impl Service {
|
||||||
// TODO: Use futures when we have long admin commands
|
// TODO: Use futures when we have long admin commands
|
||||||
//let mut futures = FuturesUnordered::new();
|
//let mut futures = FuturesUnordered::new();
|
||||||
|
|
||||||
let conduit_user =
|
let conduit_user = UserId::parse(format!("@conduit:{}", services().globals.server_name()))
|
||||||
UserId::parse(format!("@conduit:{}", services().globals.server_name()))
|
.expect("@conduit:server_name is valid");
|
||||||
.expect("@conduit:server_name is valid");
|
|
||||||
|
|
||||||
let conduit_room = services()
|
let conduit_room = services()
|
||||||
.rooms
|
.rooms
|
||||||
|
@ -202,8 +201,7 @@ impl Service {
|
||||||
.expect("Database data for admin room alias must be valid")
|
.expect("Database data for admin room alias must be valid")
|
||||||
.expect("Admin room must exist");
|
.expect("Admin room must exist");
|
||||||
|
|
||||||
let send_message = |message: RoomMessageEventContent,
|
let send_message = |message: RoomMessageEventContent, mutex_lock: &MutexGuard<'_, ()>| {
|
||||||
mutex_lock: &MutexGuard<'_, ()>| {
|
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
|
|
|
@ -3,15 +3,13 @@ pub use data::Data;
|
||||||
|
|
||||||
use crate::api::server_server::FedDest;
|
use crate::api::server_server::FedDest;
|
||||||
|
|
||||||
|
|
||||||
use crate::{Config, Error, Result};
|
use crate::{Config, Error, Result};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::sync::sync_events,
|
client::sync::sync_events,
|
||||||
federation::discovery::{ServerSigningKeys, VerifyKey},
|
federation::discovery::{ServerSigningKeys, VerifyKey},
|
||||||
},
|
},
|
||||||
DeviceId, EventId, RoomId, RoomVersionId, ServerName,
|
DeviceId, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
|
||||||
ServerSigningKeyId, UserId,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
mod data;
|
mod data;
|
||||||
pub use data::Data;
|
pub use data::Data;
|
||||||
|
|
||||||
use crate::{Result};
|
use crate::Result;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
|
||||||
backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
|
|
||||||
},
|
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
RoomId, UserId,
|
RoomId, UserId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ pub use data::Data;
|
||||||
|
|
||||||
use crate::{services, Result};
|
use crate::{services, Result};
|
||||||
use image::{imageops::FilterType, GenericImageView};
|
use image::{imageops::FilterType, GenericImageView};
|
||||||
use std::{sync::Arc};
|
use std::sync::Arc;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap},
|
collections::HashMap,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ impl Services {
|
||||||
+ key_backups::Data
|
+ key_backups::Data
|
||||||
+ media::Data
|
+ media::Data
|
||||||
+ sending::Data
|
+ sending::Data
|
||||||
+ 'static
|
+ 'static,
|
||||||
>(
|
>(
|
||||||
db: &'static D,
|
db: &'static D,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
|
|
@ -7,9 +7,11 @@ use ruma::{
|
||||||
pub trait Data: Send + Sync {
|
pub trait Data: Send + Sync {
|
||||||
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::Pusher) -> Result<()>;
|
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::Pusher) -> Result<()>;
|
||||||
|
|
||||||
fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<get_pushers::v3::Pusher>>;
|
fn get_pusher(&self, sender: &UserId, pushkey: &str)
|
||||||
|
-> Result<Option<get_pushers::v3::Pusher>>;
|
||||||
|
|
||||||
fn get_pushers(&self, sender: &UserId) -> Result<Vec<get_pushers::v3::Pusher>>;
|
fn get_pushers(&self, sender: &UserId) -> Result<Vec<get_pushers::v3::Pusher>>;
|
||||||
|
|
||||||
fn get_pushkeys<'a>(&'a self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>> + 'a>;
|
fn get_pushkeys<'a>(&'a self, sender: &UserId)
|
||||||
|
-> Box<dyn Iterator<Item = Result<String>> + 'a>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,11 @@ impl Service {
|
||||||
self.db.set_pusher(sender, pusher)
|
self.db.set_pusher(sender, pusher)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<get_pushers::v3::Pusher>> {
|
pub fn get_pusher(
|
||||||
|
&self,
|
||||||
|
sender: &UserId,
|
||||||
|
pushkey: &str,
|
||||||
|
) -> Result<Option<get_pushers::v3::Pusher>> {
|
||||||
self.db.get_pusher(sender, pushkey)
|
self.db.get_pusher(sender, pushkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +46,7 @@ impl Service {
|
||||||
self.db.get_pushers(sender)
|
self.db.get_pushers(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pushkeys<'a>(
|
pub fn get_pushkeys<'a>(&'a self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>>> {
|
||||||
&'a self,
|
|
||||||
sender: &UserId,
|
|
||||||
) -> Box<dyn Iterator<Item = Result<String>>> {
|
|
||||||
self.db.get_pushkeys(sender)
|
self.db.get_pushkeys(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@ pub trait Data: Send + Sync {
|
||||||
since: u64,
|
since: u64,
|
||||||
) -> Box<
|
) -> Box<
|
||||||
dyn Iterator<
|
dyn Iterator<
|
||||||
Item = Result<(
|
Item = Result<(
|
||||||
Box<UserId>,
|
Box<UserId>,
|
||||||
u64,
|
u64,
|
||||||
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
|
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
|
||||||
)>,
|
)>,
|
||||||
> + 'a,
|
> + 'a,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Sets a private read marker at `count`.
|
/// Sets a private read marker at `count`.
|
||||||
|
|
|
@ -34,7 +34,7 @@ use ruma::{
|
||||||
state_res::{self, RoomVersion, StateMap},
|
state_res::{self, RoomVersion, StateMap},
|
||||||
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId,
|
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId,
|
||||||
};
|
};
|
||||||
use serde_json::value::{RawValue as RawJsonValue};
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
use crate::{service::*, services, Error, PduEvent, Result};
|
use crate::{service::*, services, Error, PduEvent, Result};
|
||||||
|
|
|
@ -8,5 +8,5 @@ pub trait Data: Send + Sync {
|
||||||
&'a self,
|
&'a self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
search_string: &str,
|
search_string: &str,
|
||||||
) -> Result<Option<(Box<dyn Iterator<Item = Vec<u8>>+ 'a>, Vec<String>)>>;
|
) -> Result<Option<(Box<dyn Iterator<Item = Vec<u8>> + 'a>, Vec<String>)>>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,7 @@ pub struct Service {
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn index_pdu<'a>(
|
pub fn index_pdu<'a>(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> {
|
||||||
&self,
|
|
||||||
shortroomid: u64,
|
|
||||||
pdu_id: &[u8],
|
|
||||||
message_body: &str,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.db.index_pdu(shortroomid, pdu_id, message_body)
|
self.db.index_pdu(shortroomid, pdu_id, message_body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||||
pub use data::Data;
|
pub use data::Data;
|
||||||
use ruma::{events::StateEventType, EventId, RoomId};
|
use ruma::{events::StateEventType, EventId, RoomId};
|
||||||
|
|
||||||
use crate::{Result};
|
use crate::Result;
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub db: &'static dyn Data,
|
pub db: &'static dyn Data,
|
||||||
|
|
|
@ -102,7 +102,8 @@ impl Service {
|
||||||
|
|
||||||
services().rooms.state_cache.update_joined_count(room_id)?;
|
services().rooms.state_cache.update_joined_count(room_id)?;
|
||||||
|
|
||||||
self.db.set_room_state(room_id, shortstatehash, &state_lock)?;
|
self.db
|
||||||
|
.set_room_state(room_id, shortstatehash, &state_lock)?;
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,11 @@ pub use data::Data;
|
||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{
|
events::{
|
||||||
direct::{DirectEvent},
|
direct::DirectEvent,
|
||||||
ignored_user_list::IgnoredUserListEvent,
|
ignored_user_list::IgnoredUserListEvent,
|
||||||
room::{create::RoomCreateEventContent, member::MembershipState},
|
room::{create::RoomCreateEventContent, member::MembershipState},
|
||||||
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
|
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||||
|
RoomAccountDataEventType, StateEventType,
|
||||||
},
|
},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
RoomId, ServerName, UserId,
|
RoomId, ServerName, UserId,
|
||||||
|
|
|
@ -2,8 +2,8 @@ mod data;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::{collections::HashSet};
|
|
||||||
|
|
||||||
pub use data::Data;
|
pub use data::Data;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -305,7 +305,9 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
for push_key in services().pusher.get_pushkeys(&user) {
|
for push_key in services().pusher.get_pushkeys(&user) {
|
||||||
services().sending.send_push_pdu(&*pdu_id, &user, push_key?)?;
|
services()
|
||||||
|
.sending
|
||||||
|
.send_push_pdu(&*pdu_id, &user, push_key?)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,16 @@ pub use data::Data;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{BTreeMap, HashMap, HashSet},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
|
iter,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant}, iter,
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{appservice_server, server_server},
|
api::{appservice_server, server_server},
|
||||||
services,
|
services,
|
||||||
utils::{self, calculate_hash},
|
utils::{self, calculate_hash},
|
||||||
Error, PduEvent, Result, Config,
|
Config, Error, PduEvent, Result,
|
||||||
};
|
};
|
||||||
use federation::transactions::send_transaction_message;
|
use federation::transactions::send_transaction_message;
|
||||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||||
|
@ -100,7 +101,11 @@ impl Service {
|
||||||
pub fn build(db: &'static dyn Data, config: &Config) -> Arc<Self> {
|
pub fn build(db: &'static dyn Data, config: &Config) -> Arc<Self> {
|
||||||
let (sender, receiver) = mpsc::unbounded_channel();
|
let (sender, receiver) = mpsc::unbounded_channel();
|
||||||
|
|
||||||
let self1 = Arc::new(Self { db, sender, maximum_requests: Arc::new(Semaphore::new(config.max_concurrent_requests as usize)) });
|
let self1 = Arc::new(Self {
|
||||||
|
db,
|
||||||
|
sender,
|
||||||
|
maximum_requests: Arc::new(Semaphore::new(config.max_concurrent_requests as usize)),
|
||||||
|
});
|
||||||
let self2 = Arc::clone(&self1);
|
let self2 = Arc::clone(&self1);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
@ -110,7 +115,10 @@ impl Service {
|
||||||
self1
|
self1
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_handler(&self, mut receiver: mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>) -> Result<()> {
|
async fn start_handler(
|
||||||
|
&self,
|
||||||
|
mut receiver: mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>,
|
||||||
|
) -> Result<()> {
|
||||||
let mut futures = FuturesUnordered::new();
|
let mut futures = FuturesUnordered::new();
|
||||||
|
|
||||||
let mut current_transaction_status = HashMap::<OutgoingKind, TransactionStatus>::new();
|
let mut current_transaction_status = HashMap::<OutgoingKind, TransactionStatus>::new();
|
||||||
|
@ -118,8 +126,7 @@ impl Service {
|
||||||
// Retry requests we could not finish yet
|
// Retry requests we could not finish yet
|
||||||
let mut initial_transactions = HashMap::<OutgoingKind, Vec<SendingEventType>>::new();
|
let mut initial_transactions = HashMap::<OutgoingKind, Vec<SendingEventType>>::new();
|
||||||
|
|
||||||
for (key, outgoing_kind, event) in self.db.active_requests().filter_map(|r| r.ok())
|
for (key, outgoing_kind, event) in self.db.active_requests().filter_map(|r| r.ok()) {
|
||||||
{
|
|
||||||
let entry = initial_transactions
|
let entry = initial_transactions
|
||||||
.entry(outgoing_kind.clone())
|
.entry(outgoing_kind.clone())
|
||||||
.or_insert_with(Vec::new);
|
.or_insert_with(Vec::new);
|
||||||
|
@ -137,8 +144,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (outgoing_kind, events) in initial_transactions {
|
for (outgoing_kind, events) in initial_transactions {
|
||||||
current_transaction_status
|
current_transaction_status.insert(outgoing_kind.clone(), TransactionStatus::Running);
|
||||||
.insert(outgoing_kind.clone(), TransactionStatus::Running);
|
|
||||||
futures.push(Self::handle_events(outgoing_kind.clone(), events));
|
futures.push(Self::handle_events(outgoing_kind.clone(), events));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +241,11 @@ impl Service {
|
||||||
|
|
||||||
if retry {
|
if retry {
|
||||||
// We retry the previous transaction
|
// We retry the previous transaction
|
||||||
for (_, e) in self.db.active_requests_for(outgoing_kind).filter_map(|r| r.ok()) {
|
for (_, e) in self
|
||||||
|
.db
|
||||||
|
.active_requests_for(outgoing_kind)
|
||||||
|
.filter_map(|r| r.ok())
|
||||||
|
{
|
||||||
events.push(e);
|
events.push(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,7 +286,12 @@ impl Service {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Look for read receipts in this room
|
// Look for read receipts in this room
|
||||||
for r in services().rooms.edus.read_receipt.readreceipts_since(&room_id, since) {
|
for r in services()
|
||||||
|
.rooms
|
||||||
|
.edus
|
||||||
|
.read_receipt
|
||||||
|
.readreceipts_since(&room_id, since)
|
||||||
|
{
|
||||||
let (user_id, count, read_receipt) = r?;
|
let (user_id, count, read_receipt) = r?;
|
||||||
|
|
||||||
if count > max_edu_count {
|
if count > max_edu_count {
|
||||||
|
@ -359,7 +374,9 @@ impl Service {
|
||||||
let outgoing_kind = OutgoingKind::Push(user.to_owned(), pushkey);
|
let outgoing_kind = OutgoingKind::Push(user.to_owned(), pushkey);
|
||||||
let event = SendingEventType::Pdu(pdu_id.to_owned());
|
let event = SendingEventType::Pdu(pdu_id.to_owned());
|
||||||
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
||||||
self.sender.send((outgoing_kind, event, keys.into_iter().next().unwrap())).unwrap();
|
self.sender
|
||||||
|
.send((outgoing_kind, event, keys.into_iter().next().unwrap()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -370,10 +387,25 @@ impl Service {
|
||||||
servers: I,
|
servers: I,
|
||||||
pdu_id: &[u8],
|
pdu_id: &[u8],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let requests = servers.into_iter().map(|server| (OutgoingKind::Normal(server), SendingEventType::Pdu(pdu_id.to_owned()))).collect::<Vec<_>>();
|
let requests = servers
|
||||||
let keys = self.db.queue_requests(&requests.iter().map(|(o, e)| (o, e.clone())).collect::<Vec<_>>())?;
|
.into_iter()
|
||||||
|
.map(|server| {
|
||||||
|
(
|
||||||
|
OutgoingKind::Normal(server),
|
||||||
|
SendingEventType::Pdu(pdu_id.to_owned()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let keys = self.db.queue_requests(
|
||||||
|
&requests
|
||||||
|
.iter()
|
||||||
|
.map(|(o, e)| (o, e.clone()))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
)?;
|
||||||
for ((outgoing_kind, event), key) in requests.into_iter().zip(keys) {
|
for ((outgoing_kind, event), key) in requests.into_iter().zip(keys) {
|
||||||
self.sender.send((outgoing_kind.to_owned(), event, key)).unwrap();
|
self.sender
|
||||||
|
.send((outgoing_kind.to_owned(), event, key))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -389,7 +421,9 @@ impl Service {
|
||||||
let outgoing_kind = OutgoingKind::Normal(server.to_owned());
|
let outgoing_kind = OutgoingKind::Normal(server.to_owned());
|
||||||
let event = SendingEventType::Edu(serialized);
|
let event = SendingEventType::Edu(serialized);
|
||||||
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
||||||
self.sender.send((outgoing_kind, event, keys.into_iter().next().unwrap())).unwrap();
|
self.sender
|
||||||
|
.send((outgoing_kind, event, keys.into_iter().next().unwrap()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -399,7 +433,9 @@ impl Service {
|
||||||
let outgoing_kind = OutgoingKind::Appservice(appservice_id);
|
let outgoing_kind = OutgoingKind::Appservice(appservice_id);
|
||||||
let event = SendingEventType::Pdu(pdu_id);
|
let event = SendingEventType::Pdu(pdu_id);
|
||||||
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?;
|
||||||
self.sender.send((outgoing_kind, event, keys.into_iter().next().unwrap())).unwrap();
|
self.sender
|
||||||
|
.send((outgoing_kind, event, keys.into_iter().next().unwrap()))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -409,7 +445,8 @@ impl Service {
|
||||||
///
|
///
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn cleanup_events(&self, appservice_id: String) -> Result<()> {
|
pub fn cleanup_events(&self, appservice_id: String) -> Result<()> {
|
||||||
self.db.delete_all_requests_for(&OutgoingKind::Appservice(appservice_id))?;
|
self.db
|
||||||
|
.delete_all_requests_for(&OutgoingKind::Appservice(appservice_id))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -638,7 +675,6 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, destination, request))]
|
#[tracing::instrument(skip(self, destination, request))]
|
||||||
pub async fn send_federation_request<T: OutgoingRequest>(
|
pub async fn send_federation_request<T: OutgoingRequest>(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in a new issue