general misc bug fixes and slight improvements

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-11-10 21:20:38 -05:00
parent fd2a002480
commit 4f0bdb5194
10 changed files with 127 additions and 100 deletions

View file

@ -1240,8 +1240,8 @@ async fn make_join_request(
) -> Result<(federation::membership::prepare_join_event::v1::Response, OwnedServerName)> {
let mut make_join_response_and_server = Err!(BadServerResponse("No server available to assist in joining."));
let mut make_join_counter: u16 = 0;
let mut incompatible_room_version_count: u8 = 0;
let mut make_join_counter: usize = 0;
let mut incompatible_room_version_count: usize = 0;
for remote_server in servers {
if services.globals.server_is_ours(remote_server) {
@ -1264,28 +1264,25 @@ async fn make_join_request(
make_join_counter = make_join_counter.saturating_add(1);
if let Err(ref e) = make_join_response {
trace!("make_join ErrorKind string: {:?}", e.kind().to_string());
// converting to a string is necessary (i think) because ruma is forcing us to
// fill in the struct for M_INCOMPATIBLE_ROOM_VERSION
if e.kind().to_string().contains("M_INCOMPATIBLE_ROOM_VERSION")
|| e.kind().to_string().contains("M_UNSUPPORTED_ROOM_VERSION")
{
if matches!(
e.kind(),
ErrorKind::IncompatibleRoomVersion { .. } | ErrorKind::UnsupportedRoomVersion
) {
incompatible_room_version_count = incompatible_room_version_count.saturating_add(1);
}
if incompatible_room_version_count > 15 {
info!(
"15 servers have responded with M_INCOMPATIBLE_ROOM_VERSION or M_UNSUPPORTED_ROOM_VERSION, \
assuming that Conduwuit does not support the room {room_id}: {e}"
assuming that conduwuit does not support the room {room_id}: {e}"
);
make_join_response_and_server = Err!(BadServerResponse("Room version is not supported by Conduwuit"));
return make_join_response_and_server;
}
if make_join_counter > 50 {
if make_join_counter > 40 {
warn!(
"50 servers failed to provide valid make_join response, assuming no server can assist in joining."
"40 servers failed to provide valid make_join response, assuming no server can assist in joining."
);
make_join_response_and_server = Err!(BadServerResponse("No server available to assist in joining."));
return make_join_response_and_server;

View file

@ -13,6 +13,7 @@ use ruma::{
profile::{get_avatar_url, get_display_name, get_profile, get_profile_key, get_timezone_key},
voip::get_turn_server_info,
},
federation::openid::get_openid_userinfo,
AuthScheme, IncomingRequest, Metadata,
},
server_util::authorization::XMatrix,
@ -102,26 +103,6 @@ pub(super) async fn auth(
}
match (metadata.authentication, token) {
(_, Token::Invalid) => {
// OpenID endpoint uses a query param with the same name, drop this once query
// params for user auth are removed from the spec. This is required to make
// integration manager work.
if request.query.access_token.is_some() && request.parts.uri.path().contains("/openid/") {
Ok(Auth {
origin: None,
sender_user: None,
sender_device: None,
appservice_info: None,
})
} else {
Err(Error::BadRequest(
ErrorKind::UnknownToken {
soft_logout: false,
},
"Unknown access token.",
))
}
},
(AuthScheme::AccessToken, Token::Appservice(info)) => Ok(auth_appservice(services, request, info).await?),
(AuthScheme::None | AuthScheme::AccessTokenOptional | AuthScheme::AppserviceToken, Token::Appservice(info)) => {
Ok(Auth {
@ -132,7 +113,6 @@ pub(super) async fn auth(
})
},
(AuthScheme::AccessToken, Token::None) => match metadata {
// TODO: can we check this better?
&get_turn_server_info::v3::Request::METADATA => {
if services.globals.config.turn_allow_guests {
Ok(Auth {
@ -171,6 +151,32 @@ pub(super) async fn auth(
ErrorKind::Unauthorized,
"Only appservice access tokens should be used on this endpoint.",
)),
(AuthScheme::None, Token::Invalid) => {
// OpenID federation endpoint uses a query param with the same name, drop this
// once query params for user auth are removed from the spec. This is
// required to make integration manager work.
if request.query.access_token.is_some() && metadata == &get_openid_userinfo::v1::Request::METADATA {
Ok(Auth {
origin: None,
sender_user: None,
sender_device: None,
appservice_info: None,
})
} else {
Err(Error::BadRequest(
ErrorKind::UnknownToken {
soft_logout: false,
},
"Unknown access token.",
))
}
},
(_, Token::Invalid) => Err(Error::BadRequest(
ErrorKind::UnknownToken {
soft_logout: false,
},
"Unknown access token.",
)),
}
}

View file

@ -1,5 +1,6 @@
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use base64::{engine::general_purpose, Engine as _};
use conduit::{err, utils, warn, Err, Error, PduEvent, Result};
use ruma::{
api::{client::error::ErrorKind, federation::membership::create_invite},
@ -125,8 +126,10 @@ pub(crate) async fn create_invite_route(
invite_state.push(pdu.to_stripped_state_event());
// If we are active in the room, the remote server will notify us about the join
// via /send
// If we are active in the room, the remote server will notify us about the
// join/invite through /send. If we are not in the room, we need to manually
// record the invited state for client /sync through update_membership(), and
// send the invite PDU to the relevant appservices.
if !services
.rooms
.state_cache
@ -148,6 +151,25 @@ pub(crate) async fn create_invite_route(
.await?;
}
for appservice in services.appservice.read().await.values() {
if appservice.is_user_match(&invited_user) {
services
.sending
.send_appservice_request(
appservice.registration.clone(),
ruma::api::appservice::event::push_events::v1::Request {
events: vec![pdu.to_room_event()],
txn_id: general_purpose::URL_SAFE_NO_PAD
.encode(utils::calculate_hash(&[pdu.event_id.as_bytes()]))
.into(),
ephemeral: Vec::new(),
to_device: Vec::new(),
},
)
.await?;
}
}
Ok(create_invite::v2::Response {
event: services
.sending

View file

@ -80,6 +80,14 @@ pub(crate) async fn create_join_event_template_route(
}
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
if !body.ver.contains(&room_version_id) {
return Err(Error::BadRequest(
ErrorKind::IncompatibleRoomVersion {
room_version: room_version_id,
},
"Room version not supported.",
));
}
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
@ -118,16 +126,6 @@ pub(crate) async fn create_join_event_template_route(
None
};
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
if !body.ver.contains(&room_version_id) {
return Err(Error::BadRequest(
ErrorKind::IncompatibleRoomVersion {
room_version: room_version_id,
},
"Room version not supported.",
));
}
let (_pdu, mut pdu_json) = services
.rooms
.timeline

View file

@ -157,7 +157,5 @@ async fn create_leave_event(
.room_servers(room_id)
.ready_filter(|server| !services.globals.server_is_ours(server));
services.sending.send_pdu_servers(servers, &pdu_id).await?;
Ok(())
services.sending.send_pdu_servers(servers, &pdu_id).await
}