chore: update dependencies
parent
bb234ca002
commit
23f81bfaf7
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,7 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Used to handle requests
|
# Used to handle requests
|
||||||
# TODO: This can become optional as soon as proper configs are supported
|
# TODO: This can become optional as soon as proper configs are supported
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "93e62c86eddf7cc9a7fc40b044182f83f0d7d92a", features = ["tls"] } # Used to handle requests
|
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "e1307ddf48dac14e6a37e526098732327bcb86f0", features = ["tls"] } # Used to handle requests
|
||||||
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
|
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
|
||||||
|
|
||||||
# Used for matrix spec type definitions and helpers
|
# Used for matrix spec type definitions and helpers
|
||||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -21,7 +21,6 @@ pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||||
|
|
||||||
use rocket::{
|
use rocket::{
|
||||||
catch, catchers,
|
catch, catchers,
|
||||||
fairing::AdHoc,
|
|
||||||
figment::{
|
figment::{
|
||||||
providers::{Env, Format, Toml},
|
providers::{Env, Format, Toml},
|
||||||
Figment,
|
Figment,
|
||||||
|
@ -31,9 +30,9 @@ use rocket::{
|
||||||
use tracing::span;
|
use tracing::span;
|
||||||
use tracing_subscriber::{prelude::*, Registry};
|
use tracing_subscriber::{prelude::*, Registry};
|
||||||
|
|
||||||
fn setup_rocket() -> (rocket::Rocket, Config) {
|
async fn setup_rocket() -> (rocket::Rocket<rocket::Build>, Config) {
|
||||||
// Force log level off, so we can use our own logger
|
// Force log level off, so we can use our own logger
|
||||||
std::env::set_var("CONDUIT_LOG_LEVEL", "off");
|
//std::env::set_var("CONDUIT_LOG_LEVEL", "off");
|
||||||
|
|
||||||
let config =
|
let config =
|
||||||
Figment::from(rocket::Config::release_default())
|
Figment::from(rocket::Config::release_default())
|
||||||
|
@ -48,9 +47,15 @@ fn setup_rocket() -> (rocket::Rocket, Config) {
|
||||||
let parsed_config = config
|
let parsed_config = config
|
||||||
.extract::<Config>()
|
.extract::<Config>()
|
||||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||||
let parsed_config2 = parsed_config.clone();
|
|
||||||
|
let data = Database::load_or_create(parsed_config.clone())
|
||||||
|
.await
|
||||||
|
.expect("config is valid");
|
||||||
|
|
||||||
|
data.sending.start_handler(&data);
|
||||||
|
|
||||||
let rocket = rocket::custom(config)
|
let rocket = rocket::custom(config)
|
||||||
|
.manage(data)
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
routes![
|
routes![
|
||||||
|
@ -176,29 +181,23 @@ fn setup_rocket() -> (rocket::Rocket, Config) {
|
||||||
server_server::get_profile_information_route,
|
server_server::get_profile_information_route,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.register(catchers![
|
.register(
|
||||||
|
"/",
|
||||||
|
catchers![
|
||||||
not_found_catcher,
|
not_found_catcher,
|
||||||
forbidden_catcher,
|
forbidden_catcher,
|
||||||
unknown_token_catcher,
|
unknown_token_catcher,
|
||||||
missing_token_catcher,
|
missing_token_catcher,
|
||||||
bad_json_catcher
|
bad_json_catcher
|
||||||
])
|
],
|
||||||
.attach(AdHoc::on_attach("Config", |rocket| async {
|
);
|
||||||
let data = Database::load_or_create(parsed_config2)
|
|
||||||
.await
|
|
||||||
.expect("config is valid");
|
|
||||||
|
|
||||||
data.sending.start_handler(&data);
|
|
||||||
|
|
||||||
Ok(rocket.manage(data))
|
|
||||||
}));
|
|
||||||
|
|
||||||
(rocket, parsed_config)
|
(rocket, parsed_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let (rocket, config) = setup_rocket();
|
let (rocket, config) = setup_rocket().await;
|
||||||
|
|
||||||
if config.allow_jaeger {
|
if config.allow_jaeger {
|
||||||
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||||
|
@ -213,11 +212,11 @@ async fn main() {
|
||||||
|
|
||||||
rocket.launch().await.unwrap();
|
rocket.launch().await.unwrap();
|
||||||
} else {
|
} else {
|
||||||
std::env::set_var("CONDUIT_LOG", config.log);
|
//std::env::set_var("CONDUIT_LOG", config.log);
|
||||||
pretty_env_logger::init_custom_env("CONDUIT_LOG");
|
//pretty_env_logger::init_custom_env("CONDUIT_LOG");
|
||||||
|
|
||||||
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
//let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||||
let _enter = root.enter();
|
//let _enter = root.enter();
|
||||||
|
|
||||||
rocket.launch().await.unwrap();
|
rocket.launch().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,7 @@ use {
|
||||||
crate::{server_server, utils},
|
crate::{server_server, utils},
|
||||||
log::{debug, warn},
|
log::{debug, warn},
|
||||||
rocket::{
|
rocket::{
|
||||||
data::{
|
data::{self, ByteUnit, Data, FromData},
|
||||||
ByteUnit, Data, FromDataFuture, FromTransformedData, Transform, TransformFuture,
|
|
||||||
Transformed,
|
|
||||||
},
|
|
||||||
http::Status,
|
http::Status,
|
||||||
outcome::Outcome::*,
|
outcome::Outcome::*,
|
||||||
response::{self, Responder},
|
response::{self, Responder},
|
||||||
|
@ -42,29 +39,15 @@ pub struct Ruma<T: Outgoing> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "conduit_bin")]
|
#[cfg(feature = "conduit_bin")]
|
||||||
impl<'a, T: Outgoing> FromTransformedData<'a> for Ruma<T>
|
#[rocket::async_trait]
|
||||||
|
impl<'a, T: Outgoing> FromData<'a> for Ruma<T>
|
||||||
where
|
where
|
||||||
T::Incoming: IncomingRequest,
|
T::Incoming: IncomingRequest,
|
||||||
{
|
{
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Owned = Data;
|
|
||||||
type Borrowed = Self::Owned;
|
|
||||||
|
|
||||||
fn transform<'r>(
|
async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self, Self::Error> {
|
||||||
_req: &'r Request<'_>,
|
|
||||||
data: Data,
|
|
||||||
) -> TransformFuture<'r, Self::Owned, Self::Error> {
|
|
||||||
Box::pin(async move { Transform::Owned(Success(data)) })
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_data(
|
|
||||||
request: &'a Request<'_>,
|
|
||||||
outcome: Transformed<'a, Self>,
|
|
||||||
) -> FromDataFuture<'a, Self, Self::Error> {
|
|
||||||
let metadata = T::Incoming::METADATA;
|
let metadata = T::Incoming::METADATA;
|
||||||
|
|
||||||
Box::pin(async move {
|
|
||||||
let data = rocket::try_outcome!(outcome.owned());
|
|
||||||
let db = request
|
let db = request
|
||||||
.guard::<State<'_, crate::Database>>()
|
.guard::<State<'_, crate::Database>>()
|
||||||
.await
|
.await
|
||||||
|
@ -75,15 +58,15 @@ where
|
||||||
.headers()
|
.headers()
|
||||||
.get_one("Authorization")
|
.get_one("Authorization")
|
||||||
.map(|s| s[7..].to_owned()) // Split off "Bearer "
|
.map(|s| s[7..].to_owned()) // Split off "Bearer "
|
||||||
.or_else(|| request.get_query_value("access_token").and_then(|r| r.ok()));
|
.or_else(|| request.query_value("access_token").and_then(|r| r.ok()));
|
||||||
|
|
||||||
let limit = db.globals.max_request_size();
|
let limit = db.globals.max_request_size();
|
||||||
let mut handle = data.open(ByteUnit::Byte(limit.into()));
|
let mut handle = data.open(ByteUnit::Byte(limit.into()));
|
||||||
let mut body = Vec::new();
|
let mut body = Vec::new();
|
||||||
handle.read_to_end(&mut body).await.unwrap();
|
handle.read_to_end(&mut body).await.unwrap();
|
||||||
|
|
||||||
let (sender_user, sender_device, from_appservice) = if let Some((_id, registration)) =
|
let (sender_user, sender_device, from_appservice) = if let Some((_id, registration)) = db
|
||||||
db.appservice
|
.appservice
|
||||||
.iter_all()
|
.iter_all()
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.find(|(_id, registration)| {
|
.find(|(_id, registration)| {
|
||||||
|
@ -94,7 +77,7 @@ where
|
||||||
}) {
|
}) {
|
||||||
match metadata.authentication {
|
match metadata.authentication {
|
||||||
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
|
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
|
||||||
let user_id = request.get_query_value::<String>("user_id").map_or_else(
|
let user_id = request.query_value::<String>("user_id").map_or_else(
|
||||||
|| {
|
|| {
|
||||||
UserId::parse_with_server_name(
|
UserId::parse_with_server_name(
|
||||||
registration
|
registration
|
||||||
|
@ -217,15 +200,16 @@ where
|
||||||
"uri".to_owned(),
|
"uri".to_owned(),
|
||||||
CanonicalJsonValue::String(request.uri().to_string()),
|
CanonicalJsonValue::String(request.uri().to_string()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
println!("{}: {:?}", origin, request.uri().to_string());
|
||||||
|
|
||||||
request_map.insert(
|
request_map.insert(
|
||||||
"origin".to_owned(),
|
"origin".to_owned(),
|
||||||
CanonicalJsonValue::String(origin.as_str().to_owned()),
|
CanonicalJsonValue::String(origin.as_str().to_owned()),
|
||||||
);
|
);
|
||||||
request_map.insert(
|
request_map.insert(
|
||||||
"destination".to_owned(),
|
"destination".to_owned(),
|
||||||
CanonicalJsonValue::String(
|
CanonicalJsonValue::String(db.globals.server_name().as_str().to_owned()),
|
||||||
db.globals.server_name().as_str().to_owned(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut origin_signatures = BTreeMap::new();
|
let mut origin_signatures = BTreeMap::new();
|
||||||
|
@ -265,10 +249,7 @@ where
|
||||||
match ruma::signatures::verify_json(&pub_key_map, &request_map) {
|
match ruma::signatures::verify_json(&pub_key_map, &request_map) {
|
||||||
Ok(()) => (None, None, false),
|
Ok(()) => (None, None, false),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!(
|
warn!("Failed to verify json request from {}: {}", origin, e,);
|
||||||
"Failed to verify json request: {}: {:?} {:?}",
|
|
||||||
e, pub_key_map, request_map
|
|
||||||
);
|
|
||||||
|
|
||||||
// Forbidden
|
// Forbidden
|
||||||
return Failure((Status::raw(580), ()));
|
return Failure((Status::raw(580), ()));
|
||||||
|
@ -304,7 +285,6 @@ where
|
||||||
Failure((Status::raw(583), ()))
|
Failure((Status::raw(583), ()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue