fix: various improvements and fixes
This commit is contained in:
parent
363c629faf
commit
3ea7d162db
9 changed files with 67 additions and 57 deletions
|
@ -24,20 +24,25 @@ pub async fn get_context_route(
|
|||
));
|
||||
}
|
||||
|
||||
let base_pdu_id = db
|
||||
.rooms
|
||||
.get_pdu_id(&body.event_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Base event id not found.",
|
||||
))?;
|
||||
|
||||
let base_token = db.rooms.pdu_count(&base_pdu_id)?;
|
||||
|
||||
let base_event = db
|
||||
.rooms
|
||||
.get_pdu(&body.event_id)?
|
||||
.get_pdu_from_id(&base_pdu_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Base event not found.",
|
||||
))?
|
||||
.to_room_event();
|
||||
|
||||
let base_token = db
|
||||
.rooms
|
||||
.get_pdu_count(&body.event_id)?
|
||||
.expect("event still exists");
|
||||
|
||||
let events_before = db
|
||||
.rooms
|
||||
.pdus_until(&sender_user, &body.room_id, base_token)
|
||||
|
|
|
@ -120,7 +120,7 @@ impl Database {
|
|||
token_userdeviceid: db.open_tree("token_userdeviceid")?,
|
||||
onetimekeyid_onetimekeys: db.open_tree("onetimekeyid_onetimekeys")?,
|
||||
userid_lastonetimekeyupdate: db.open_tree("userid_lastonetimekeyupdate")?,
|
||||
keychangeid_userid: db.open_tree("devicekeychangeid_userid")?,
|
||||
keychangeid_userid: db.open_tree("keychangeid_userid")?,
|
||||
keyid_key: db.open_tree("keyid_key")?,
|
||||
userid_masterkeyid: db.open_tree("userid_masterkeyid")?,
|
||||
userid_selfsigningkeyid: db.open_tree("userid_selfsigningkeyid")?,
|
||||
|
@ -135,7 +135,7 @@ impl Database {
|
|||
readreceiptid_readreceipt: db.open_tree("readreceiptid_readreceipt")?,
|
||||
roomuserid_privateread: db.open_tree("roomuserid_privateread")?, // "Private" read receipt
|
||||
roomuserid_lastprivatereadupdate: db
|
||||
.open_tree("roomid_lastprivatereadupdate")?,
|
||||
.open_tree("roomuserid_lastprivatereadupdate")?,
|
||||
typingid_userid: db.open_tree("typingid_userid")?,
|
||||
roomid_lasttypingupdate: db.open_tree("roomid_lasttypingupdate")?,
|
||||
presenceid_presence: db.open_tree("presenceid_presence")?,
|
||||
|
@ -146,7 +146,7 @@ impl Database {
|
|||
roomid_pduleaves: db.open_tree("roomid_pduleaves")?,
|
||||
|
||||
alias_roomid: db.open_tree("alias_roomid")?,
|
||||
aliasid_alias: db.open_tree("alias_roomid")?,
|
||||
aliasid_alias: db.open_tree("aliasid_alias")?,
|
||||
publicroomids: db.open_tree("publicroomids")?,
|
||||
|
||||
tokenids: db.open_tree("tokenids")?,
|
||||
|
@ -163,11 +163,11 @@ impl Database {
|
|||
stateid_shorteventid: db.open_tree("stateid_shorteventid")?,
|
||||
eventid_shorteventid: db.open_tree("eventid_shorteventid")?,
|
||||
shorteventid_eventid: db.open_tree("shorteventid_eventid")?,
|
||||
shorteventid_shortstatehash: db.open_tree("eventid_shortstatehash")?,
|
||||
shorteventid_shortstatehash: db.open_tree("shorteventid_shortstatehash")?,
|
||||
roomid_shortstatehash: db.open_tree("roomid_shortstatehash")?,
|
||||
statehash_shortstatehash: db.open_tree("statehash_shortstatehash")?,
|
||||
|
||||
eventid_outlierpdu: db.open_tree("roomeventid_outlierpdu")?,
|
||||
eventid_outlierpdu: db.open_tree("eventid_outlierpdu")?,
|
||||
prevevent_parent: db.open_tree("prevevent_parent")?,
|
||||
},
|
||||
account_data: account_data::AccountData {
|
||||
|
@ -179,7 +179,7 @@ impl Database {
|
|||
key_backups: key_backups::KeyBackups {
|
||||
backupid_algorithm: db.open_tree("backupid_algorithm")?,
|
||||
backupid_etag: db.open_tree("backupid_etag")?,
|
||||
backupkeyid_backup: db.open_tree("backupkeyid_backupmetadata")?,
|
||||
backupkeyid_backup: db.open_tree("backupkeyid_backup")?,
|
||||
},
|
||||
transaction_ids: transaction_ids::TransactionIds {
|
||||
userdevicetxnid_response: db.open_tree("userdevicetxnid_response")?,
|
||||
|
|
|
@ -469,7 +469,7 @@ async fn send_notice(
|
|||
name: &str,
|
||||
) -> Result<()> {
|
||||
// TODO: email
|
||||
if pusher.kind == Some(PusherKind::Http) {
|
||||
if pusher.kind == Some(PusherKind::Email) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
|
@ -1524,7 +1524,7 @@ impl Rooms {
|
|||
let mut aliasid = room_id.as_bytes().to_vec();
|
||||
aliasid.push(0xff);
|
||||
aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
self.aliasid_alias.insert(aliasid, &*alias.alias())?;
|
||||
self.aliasid_alias.insert(aliasid, &*alias.as_bytes())?;
|
||||
} else {
|
||||
// room_id=None means remove alias
|
||||
let room_id = self
|
||||
|
|
|
@ -108,7 +108,6 @@ impl Sending {
|
|||
|
||||
let mut subscriber = servernamepduids.watch_prefix(b"");
|
||||
loop {
|
||||
println!(".");
|
||||
select! {
|
||||
Some(response) = futures.next() => {
|
||||
match response {
|
||||
|
@ -262,8 +261,6 @@ impl Sending {
|
|||
servercurrentpdus.insert(&key, &[]).unwrap();
|
||||
servernamepduids.remove(&key).unwrap();
|
||||
|
||||
dbg!("there is a future");
|
||||
|
||||
futures.push(
|
||||
Self::handle_event(
|
||||
outgoing_kind,
|
||||
|
@ -292,7 +289,6 @@ impl Sending {
|
|||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn send_pdu(&self, server: &ServerName, pdu_id: &[u8]) -> Result<()> {
|
||||
dbg!(&server);
|
||||
let mut key = server.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(pdu_id);
|
||||
|
@ -350,7 +346,6 @@ impl Sending {
|
|||
.collect::<Vec<_>>();
|
||||
let permit = db.sending.maximum_requests.acquire().await;
|
||||
|
||||
error!("sending pdus to {}: {:#?}", server, pdu_jsons);
|
||||
let response = appservice_server::send_request(
|
||||
&db.globals,
|
||||
db.appservice
|
||||
|
@ -458,7 +453,6 @@ impl Sending {
|
|||
|
||||
let permit = db.sending.maximum_requests.acquire().await;
|
||||
|
||||
error!("sending pdu to {}: {:#?}", userid, pdu);
|
||||
let _response = pusher::send_push_notice(
|
||||
&userid,
|
||||
unread,
|
||||
|
@ -506,7 +500,6 @@ impl Sending {
|
|||
|
||||
let permit = db.sending.maximum_requests.acquire().await;
|
||||
|
||||
error!("sending pdus to {}: {:#?}", server, pdu_jsons);
|
||||
let response = server_server::send_request(
|
||||
&db.globals,
|
||||
&*server,
|
||||
|
@ -523,7 +516,7 @@ impl Sending {
|
|||
)
|
||||
.await
|
||||
.map(|response| {
|
||||
error!("server response: {:?}", response);
|
||||
info!("server response: {:?}", response);
|
||||
kind.clone()
|
||||
})
|
||||
.map_err(|e| (kind, e));
|
||||
|
|
|
@ -219,6 +219,7 @@ where
|
|||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept, Authorization",
|
||||
);
|
||||
response.raw_header("Access-Control-Max-Age", "86400");
|
||||
response.ok()
|
||||
}
|
||||
Err(_) => Err(Status::InternalServerError),
|
||||
|
|
|
@ -863,8 +863,6 @@ pub async fn send_transaction_message_route<'a>(
|
|||
.map(|(_, pdu)| (pdu.event_id().clone(), pdu)),
|
||||
);
|
||||
|
||||
debug!("auth events: {:?}", auth_cache);
|
||||
|
||||
let res = match state_res::StateResolution::resolve(
|
||||
pdu.room_id(),
|
||||
&RoomVersionId::Version6,
|
||||
|
@ -952,7 +950,7 @@ type AsyncRecursiveResult<'a, T> = Pin<Box<dyn Future<Output = StdResult<T, Stri
|
|||
/// 5. reject "due to auth events" if the event doesn't pass auth based on the auth events
|
||||
/// 7. if not timeline event: stop
|
||||
/// 8. fetch any missing prev events doing all checks listed here starting at 1. These are timeline events
|
||||
#[tracing::instrument(skip(db))]
|
||||
#[tracing::instrument(skip(db, pub_key_map, auth_cache))]
|
||||
fn validate_event<'a>(
|
||||
db: &'a Database,
|
||||
value: CanonicalJsonObject,
|
||||
|
@ -998,29 +996,26 @@ fn validate_event<'a>(
|
|||
}
|
||||
};
|
||||
|
||||
pub_key_map.insert(dbg!(signature_server.clone()), dbg!(keys));
|
||||
pub_key_map.insert(signature_server.clone(), keys);
|
||||
}
|
||||
|
||||
let mut val = match ruma::signatures::verify_event(
|
||||
dbg!(&pub_key_map),
|
||||
&value,
|
||||
&RoomVersionId::Version5,
|
||||
) {
|
||||
Ok(ver) => {
|
||||
if let ruma::signatures::Verified::Signatures = ver {
|
||||
match ruma::signatures::redact(&value, &RoomVersionId::Version6) {
|
||||
Ok(obj) => obj,
|
||||
Err(_) => return Err("Redaction failed".to_string()),
|
||||
let mut val =
|
||||
match ruma::signatures::verify_event(&pub_key_map, &value, &RoomVersionId::Version5) {
|
||||
Ok(ver) => {
|
||||
if let ruma::signatures::Verified::Signatures = ver {
|
||||
match ruma::signatures::redact(&value, &RoomVersionId::Version6) {
|
||||
Ok(obj) => obj,
|
||||
Err(_) => return Err("Redaction failed".to_string()),
|
||||
}
|
||||
} else {
|
||||
value
|
||||
}
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
Err(_e) => {
|
||||
error!("{}", _e);
|
||||
return Err("Signature verification failed".to_string());
|
||||
}
|
||||
};
|
||||
Err(e) => {
|
||||
error!("{:?}: {}", value, e);
|
||||
return Err("Signature verification failed".to_string());
|
||||
}
|
||||
};
|
||||
|
||||
// Now that we have checked the signature and hashes we can add the eventID and convert
|
||||
// to our PduEvent type also finally verifying the first step listed above
|
||||
|
@ -1085,7 +1080,7 @@ fn validate_event<'a>(
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(db))]
|
||||
#[tracing::instrument(skip(db, key_map, auth_cache))]
|
||||
async fn fetch_check_auth_events(
|
||||
db: &Database,
|
||||
origin: &ServerName,
|
||||
|
@ -1108,7 +1103,7 @@ async fn fetch_check_auth_events(
|
|||
///
|
||||
/// If the event is unknown to the `auth_cache` it is added. This guarantees that any
|
||||
/// event we need to know of will be present.
|
||||
#[tracing::instrument(skip(db))]
|
||||
//#[tracing::instrument(skip(db, key_map, auth_cache))]
|
||||
pub(crate) async fn fetch_events(
|
||||
db: &Database,
|
||||
origin: &ServerName,
|
||||
|
@ -1175,11 +1170,8 @@ pub(crate) async fn fetch_signing_keys(
|
|||
origin: &ServerName,
|
||||
signature_ids: Vec<&String>,
|
||||
) -> Result<BTreeMap<String, String>> {
|
||||
let contains_all_ids = |keys: &BTreeMap<String, String>| {
|
||||
signature_ids
|
||||
.iter()
|
||||
.all(|&id| dbg!(dbg!(&keys).contains_key(dbg!(id))))
|
||||
};
|
||||
let contains_all_ids =
|
||||
|keys: &BTreeMap<String, String>| signature_ids.iter().all(|&id| keys.contains_key(id));
|
||||
|
||||
let mut result = db
|
||||
.globals
|
||||
|
@ -1273,7 +1265,7 @@ pub(crate) async fn calculate_forward_extremities(
|
|||
db: &Database,
|
||||
pdu: &PduEvent,
|
||||
) -> Result<Vec<EventId>> {
|
||||
let mut current_leaves = dbg!(db.rooms.get_pdu_leaves(pdu.room_id())?);
|
||||
let mut current_leaves = db.rooms.get_pdu_leaves(pdu.room_id())?;
|
||||
|
||||
let mut is_incoming_leaf = true;
|
||||
// Make sure the incoming event is not already a forward extremity
|
||||
|
@ -1344,7 +1336,7 @@ pub(crate) async fn build_forward_extremity_snapshots(
|
|||
Some(leave_pdu) => {
|
||||
let pdu_shortstatehash = db
|
||||
.rooms
|
||||
.pdu_shortstatehash(dbg!(&leave_pdu.event_id))?
|
||||
.pdu_shortstatehash(&leave_pdu.event_id)?
|
||||
.ok_or_else(|| Error::bad_database("Found pdu with no statehash in db."))?;
|
||||
|
||||
if current_shortstatehash.as_ref() == Some(&pdu_shortstatehash) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue