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