mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
move userdevicesessionid_uiaarequest to service
This commit is contained in:
parent
a1fe0f3fff
commit
fb534d8140
5 changed files with 42 additions and 70 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
collections::{HashMap, HashSet},
|
||||
fs,
|
||||
io::Write,
|
||||
mem::size_of,
|
||||
|
|
@ -13,8 +13,7 @@ use ruma::{
|
|||
push_rules::PushRulesEvent, GlobalAccountDataEventType, StateEventType,
|
||||
},
|
||||
push::Ruleset,
|
||||
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedRoomId,
|
||||
OwnedUserId, RoomId, UserId,
|
||||
EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
||||
};
|
||||
use tracing::{debug, error, info, info_span, warn, Instrument};
|
||||
|
||||
|
|
@ -81,9 +80,6 @@ pub(crate) struct KeyValueDatabase {
|
|||
// Trees "owned" by `self::key_value::uiaa`
|
||||
// User-interactive authentication
|
||||
pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>,
|
||||
pub(super) userdevicesessionid_uiaarequest: RwLock<
|
||||
BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>,
|
||||
>,
|
||||
|
||||
// Trees "owned" by `self::key_value::rooms::edus`
|
||||
// ReadReceiptId = RoomId + Count + UserId
|
||||
|
|
@ -376,7 +372,6 @@ impl KeyValueDatabase {
|
|||
|
||||
userdevicesessionid_uiaainfo: builder
|
||||
.open_tree("userdevicesessionid_uiaainfo")?,
|
||||
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
|
||||
readreceiptid_readreceipt: builder
|
||||
.open_tree("readreceiptid_readreceipt")?,
|
||||
// "Private" read receipt
|
||||
|
|
|
|||
|
|
@ -1,43 +1,11 @@
|
|||
use ruma::{
|
||||
api::client::{error::ErrorKind, uiaa::UiaaInfo},
|
||||
CanonicalJsonValue, DeviceId, UserId,
|
||||
DeviceId, UserId,
|
||||
};
|
||||
|
||||
use crate::{database::KeyValueDatabase, service, Error, Result};
|
||||
|
||||
impl service::uiaa::Data for KeyValueDatabase {
|
||||
fn set_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
request: &CanonicalJsonValue,
|
||||
) -> Result<()> {
|
||||
self.userdevicesessionid_uiaarequest.write().unwrap().insert(
|
||||
(user_id.to_owned(), device_id.to_owned(), session.to_owned()),
|
||||
request.to_owned(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Option<CanonicalJsonValue> {
|
||||
self.userdevicesessionid_uiaarequest
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&(
|
||||
user_id.to_owned(),
|
||||
device_id.to_owned(),
|
||||
session.to_owned(),
|
||||
))
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
fn update_uiaa_session(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
|
|||
|
|
@ -142,9 +142,7 @@ impl Services {
|
|||
user: db,
|
||||
},
|
||||
transaction_ids: db,
|
||||
uiaa: uiaa::Service {
|
||||
db,
|
||||
},
|
||||
uiaa: uiaa::Service::new(db),
|
||||
users: users::Service {
|
||||
db,
|
||||
connections: StdMutex::new(BTreeMap::new()),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
use std::{collections::BTreeMap, sync::RwLock};
|
||||
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
uiaa::{AuthData, AuthType, Password, UiaaInfo, UserIdentifier},
|
||||
},
|
||||
CanonicalJsonValue, DeviceId, UserId,
|
||||
CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedUserId, UserId,
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
|
|
@ -16,10 +18,20 @@ mod data;
|
|||
pub(crate) use data::Data;
|
||||
|
||||
pub(crate) struct Service {
|
||||
pub(crate) db: &'static dyn Data,
|
||||
db: &'static dyn Data,
|
||||
userdevicesessionid_uiaarequest: RwLock<
|
||||
BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
pub(crate) fn new(db: &'static dyn Data) -> Self {
|
||||
Self {
|
||||
db,
|
||||
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new Uiaa session. Make sure the session token is unique.
|
||||
pub(crate) fn create(
|
||||
&self,
|
||||
|
|
@ -28,14 +40,20 @@ impl Service {
|
|||
uiaainfo: &UiaaInfo,
|
||||
json_body: &CanonicalJsonValue,
|
||||
) -> Result<()> {
|
||||
self.db.set_uiaa_request(
|
||||
user_id,
|
||||
device_id,
|
||||
// TODO: better session error handling (why is it optional in
|
||||
// ruma?)
|
||||
uiaainfo.session.as_ref().expect("session should be set"),
|
||||
json_body,
|
||||
)?;
|
||||
self.userdevicesessionid_uiaarequest.write().unwrap().insert(
|
||||
(
|
||||
user_id.to_owned(),
|
||||
device_id.to_owned(),
|
||||
// TODO: better session error handling (why is it optional in
|
||||
// ruma?)
|
||||
uiaainfo
|
||||
.session
|
||||
.as_ref()
|
||||
.expect("session should be set")
|
||||
.to_owned(),
|
||||
),
|
||||
json_body.to_owned(),
|
||||
);
|
||||
self.db.update_uiaa_session(
|
||||
user_id,
|
||||
device_id,
|
||||
|
|
@ -160,6 +178,14 @@ impl Service {
|
|||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Option<CanonicalJsonValue> {
|
||||
self.db.get_uiaa_request(user_id, device_id, session)
|
||||
self.userdevicesessionid_uiaarequest
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&(
|
||||
user_id.to_owned(),
|
||||
device_id.to_owned(),
|
||||
session.to_owned(),
|
||||
))
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,8 @@
|
|||
use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId};
|
||||
use ruma::{api::client::uiaa::UiaaInfo, DeviceId, UserId};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
pub(crate) trait Data: Send + Sync {
|
||||
fn set_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
request: &CanonicalJsonValue,
|
||||
) -> Result<()>;
|
||||
|
||||
fn get_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Option<CanonicalJsonValue>;
|
||||
|
||||
fn update_uiaa_session(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue