Address some review issues fmt, errors, comments
parent
86bb93f8cf
commit
bb24f6ad90
|
@ -256,7 +256,7 @@ pub async fn get_backup_key_session_route(
|
||||||
let key_data = db
|
let key_data = db
|
||||||
.key_backups
|
.key_backups
|
||||||
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?
|
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?
|
||||||
.ok_or_else(|| Error::BadDatabase("Backup key not found for this user's session"))?;
|
.ok_or_else(|| Error::bad_database("Backup key not found for this user's session."))?;
|
||||||
|
|
||||||
Ok(get_backup_key_session::Response { key_data }.into())
|
Ok(get_backup_key_session::Response { key_data }.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub async fn create_content_route(
|
||||||
db.media.create(
|
db.media.create(
|
||||||
mxc.clone(),
|
mxc.clone(),
|
||||||
&body.filename.as_deref(),
|
&body.filename.as_deref(),
|
||||||
&body.content_type.as_deref(), // TODO this is now optional handle
|
&body.content_type.as_deref(),
|
||||||
&body.file,
|
&body.file,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -519,7 +519,6 @@ async fn join_room_by_id_helper(
|
||||||
canon_json_stub.remove("event_id");
|
canon_json_stub.remove("event_id");
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs to be present
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs to be present
|
||||||
// who the hell knew...
|
|
||||||
ruma::signatures::hash_and_sign_event(
|
ruma::signatures::hash_and_sign_event(
|
||||||
db.globals.server_name().as_str(),
|
db.globals.server_name().as_str(),
|
||||||
db.globals.keypair(),
|
db.globals.keypair(),
|
||||||
|
@ -602,7 +601,6 @@ async fn join_room_by_id_helper(
|
||||||
)))) // Add join event we just created
|
)))) // Add join event we just created
|
||||||
.map(|r| {
|
.map(|r| {
|
||||||
let (event_id, value) = r?;
|
let (event_id, value) = r?;
|
||||||
// TODO remove .clone when I remove debug logging
|
|
||||||
state_res::StateEvent::from_id_value(event_id.clone(), value.clone())
|
state_res::StateEvent::from_id_value(event_id.clone(), value.clone())
|
||||||
.map(|ev| (event_id, Arc::new(ev)))
|
.map(|ev| (event_id, Arc::new(ev)))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|
|
@ -35,6 +35,11 @@ use super::admin::AdminCommand;
|
||||||
/// hashing the entire state.
|
/// hashing the entire state.
|
||||||
pub type StateHashId = IVec;
|
pub type StateHashId = IVec;
|
||||||
|
|
||||||
|
/// An enum that represents the two valid states when searching
|
||||||
|
/// for an events "parent".
|
||||||
|
///
|
||||||
|
/// An events parent is any event we are aware of that is part of
|
||||||
|
/// the events `prev_events` array.
|
||||||
pub enum ClosestParent {
|
pub enum ClosestParent {
|
||||||
Append,
|
Append,
|
||||||
Insert(u64),
|
Insert(u64),
|
||||||
|
@ -80,7 +85,7 @@ impl StateStore for Rooms {
|
||||||
.map_err(StateError::custom)?
|
.map_err(StateError::custom)?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
StateError::NotFound(format!(
|
StateError::NotFound(format!(
|
||||||
"PDU via room_id and event_id not found in the db.\n{}",
|
"PDU via room_id and event_id not found in the db: {}",
|
||||||
event_id.as_str()
|
event_id.as_str()
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
@ -258,6 +263,8 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Force the creation of a new StateHash and insert it into the db.
|
/// Force the creation of a new StateHash and insert it into the db.
|
||||||
|
///
|
||||||
|
/// Whatever `state` is supplied to `force_state` __is__ the current room state snapshot.
|
||||||
pub fn force_state(
|
pub fn force_state(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
@ -403,6 +410,12 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recursively search for a PDU from our DB that is also in the
|
||||||
|
/// `prev_events` field of the incoming PDU.
|
||||||
|
///
|
||||||
|
/// First we check if the last PDU inserted to the given room is a parent
|
||||||
|
/// if not we recursively check older `prev_events` to insert the incoming
|
||||||
|
/// event after.
|
||||||
pub fn get_closest_parent(
|
pub fn get_closest_parent(
|
||||||
&self,
|
&self,
|
||||||
room: &RoomId,
|
room: &RoomId,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, convert::TryFrom, time::SystemTime};
|
||||||
|
|
||||||
use crate::{server_server, utils, Error, PduEvent, Result};
|
use crate::{server_server, utils, Error, PduEvent, Result};
|
||||||
use federation::transactions::send_transaction_message;
|
use federation::transactions::send_transaction_message;
|
||||||
use log::debug;
|
use log::{debug, error};
|
||||||
use rocket::futures::stream::{FuturesUnordered, StreamExt};
|
use rocket::futures::stream::{FuturesUnordered, StreamExt};
|
||||||
use ruma::{api::federation, ServerName};
|
use ruma::{api::federation, ServerName};
|
||||||
use sled::IVec;
|
use sled::IVec;
|
||||||
|
@ -115,8 +115,8 @@ impl Sending {
|
||||||
// servercurrentpdus with the prefix should be empty now
|
// servercurrentpdus with the prefix should be empty now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err((_server, _e)) => {
|
Err((server, e)) => {
|
||||||
log::error!("server: {}\nerror: {}", _server, _e)
|
error!("server: {}\nerror: {}", server, e)
|
||||||
// TODO: exponential backoff
|
// TODO: exponential backoff
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,7 +67,8 @@ where
|
||||||
|
|
||||||
let (sender_user, sender_device) =
|
let (sender_user, sender_device) =
|
||||||
// TODO: Do we need to matches! anything else here? ServerSignatures
|
// TODO: Do we need to matches! anything else here? ServerSignatures
|
||||||
if matches!(T::METADATA.authentication, AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken) {
|
match T::METADATA.authentication {
|
||||||
|
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
|
||||||
// Get token from header or query value
|
// Get token from header or query value
|
||||||
let token = match request
|
let token = match request
|
||||||
.headers()
|
.headers()
|
||||||
|
@ -86,8 +87,8 @@ where
|
||||||
None => return Failure((Status::Unauthorized, ())),
|
None => return Failure((Status::Unauthorized, ())),
|
||||||
Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())),
|
Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())),
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
(None, None)
|
_ => (None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut http_request = http::Request::builder()
|
let mut http_request = http::Request::builder()
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use get_profile_information::v1::ProfileField;
|
use get_profile_information::v1::ProfileField;
|
||||||
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
||||||
use log::warn;
|
use log::{error, warn};
|
||||||
use rocket::{get, post, put, response::content::Json, State};
|
use rocket::{get, post, put, response::content::Json, State};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
|
@ -26,7 +26,6 @@ use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
sync::Arc,
|
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
use trust_dns_resolver::AsyncResolver;
|
use trust_dns_resolver::AsyncResolver;
|
||||||
|
@ -99,7 +98,7 @@ where
|
||||||
let mut http_request = request
|
let mut http_request = request
|
||||||
.try_into_http_request(&actual_destination, Some(""))
|
.try_into_http_request(&actual_destination, Some(""))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("failed to find destination {}: {}", actual_destination, e);
|
warn!("Failed to find destination {}: {}", actual_destination, e);
|
||||||
Error::BadServerResponse("Invalid destination")
|
Error::BadServerResponse("Invalid destination")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -264,12 +263,14 @@ pub fn get_server_keys(db: State<'_, Database>) -> Json<String> {
|
||||||
.body(),
|
.body(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
ruma::signatures::sign_json(
|
ruma::signatures::sign_json(
|
||||||
db.globals.server_name().as_str(),
|
db.globals.server_name().as_str(),
|
||||||
db.globals.keypair(),
|
db.globals.keypair(),
|
||||||
&mut response,
|
&mut response,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Json(ruma::serde::to_canonical_json_string(&response).expect("JSON is canonical"))
|
Json(ruma::serde::to_canonical_json_string(&response).expect("JSON is canonical"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,8 +414,8 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
"m.receipt" => {}
|
"m.receipt" => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Err(_err) => {
|
Err(err) => {
|
||||||
log::error!("{}", _err);
|
error!("{}", err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,11 +435,9 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
.expect("all ruma pdus are conduit pdus");
|
.expect("all ruma pdus are conduit pdus");
|
||||||
let room_id = &pdu.room_id;
|
let room_id = &pdu.room_id;
|
||||||
|
|
||||||
// If we have no idea about this room
|
// If we have no idea about this room skip the PDU
|
||||||
// TODO: Does a server only send us events that we should know about or
|
|
||||||
// when everyone on this server leaves a room can we ignore those events?
|
|
||||||
if !db.rooms.exists(&pdu.room_id)? {
|
if !db.rooms.exists(&pdu.room_id)? {
|
||||||
log::error!("Room does not exist on this server");
|
error!("Room does not exist on this server.");
|
||||||
resolved_map.insert(event_id, Err("Room is unknown to this server".into()));
|
resolved_map.insert(event_id, Err("Room is unknown to this server".into()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -460,7 +459,7 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
// As an example a possible error
|
// As an example a possible error
|
||||||
// {"errcode":"M_FORBIDDEN","error":"Host not in room."}
|
// {"errcode":"M_FORBIDDEN","error":"Host not in room."}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("Request failed: {}", err);
|
error!("Request failed: {}", err);
|
||||||
resolved_map.insert(event_id, Err(err.to_string()));
|
resolved_map.insert(event_id, Err(err.to_string()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -487,7 +486,7 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
|
|
||||||
if value.get("state_key").is_none() {
|
if value.get("state_key").is_none() {
|
||||||
if !db.rooms.is_joined(&pdu.sender, &pdu.room_id)? {
|
if !db.rooms.is_joined(&pdu.sender, &pdu.room_id)? {
|
||||||
log::error!("Sender is not joined {}", pdu.kind);
|
error!("Sender is not joined {}", pdu.kind);
|
||||||
resolved_map.insert(event_id, Err("User is not in this room".into()));
|
resolved_map.insert(event_id, Err("User is not in this room".into()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue