Browse Source

chore: migrate to rust 2024 edition

rate-limiting
Matthias Ahouansou 2 months ago
parent
commit
8d10c3f5f5
No known key found for this signature in database
  1. 2
      Cargo.toml
  2. 4
      conduit-config/src/error.rs
  3. 6
      conduit-config/src/lib.rs
  4. 4
      conduit/src/api/appservice_server.rs
  5. 12
      conduit/src/api/client_server/account.rs
  6. 2
      conduit/src/api/client_server/alias.rs
  7. 2
      conduit/src/api/client_server/appservice.rs
  8. 2
      conduit/src/api/client_server/backup.rs
  9. 2
      conduit/src/api/client_server/capabilities.rs
  10. 2
      conduit/src/api/client_server/config.rs
  11. 2
      conduit/src/api/client_server/context.rs
  12. 2
      conduit/src/api/client_server/device.rs
  13. 8
      conduit/src/api/client_server/directory.rs
  14. 2
      conduit/src/api/client_server/filter.rs
  15. 8
      conduit/src/api/client_server/keys.rs
  16. 4
      conduit/src/api/client_server/media.rs
  17. 20
      conduit/src/api/client_server/membership.rs
  18. 3
      conduit/src/api/client_server/message.rs
  19. 2
      conduit/src/api/client_server/openid.rs
  20. 2
      conduit/src/api/client_server/presence.rs
  21. 4
      conduit/src/api/client_server/profile.rs
  22. 4
      conduit/src/api/client_server/push.rs
  23. 10
      conduit/src/api/client_server/read_marker.rs
  24. 4
      conduit/src/api/client_server/redact.rs
  25. 2
      conduit/src/api/client_server/relations.rs
  26. 4
      conduit/src/api/client_server/report.rs
  27. 8
      conduit/src/api/client_server/room.rs
  28. 4
      conduit/src/api/client_server/search.rs
  29. 4
      conduit/src/api/client_server/session.rs
  30. 4
      conduit/src/api/client_server/space.rs
  31. 6
      conduit/src/api/client_server/state.rs
  32. 13
      conduit/src/api/client_server/sync.rs
  33. 4
      conduit/src/api/client_server/tag.rs
  34. 2
      conduit/src/api/client_server/threads.rs
  35. 2
      conduit/src/api/client_server/to_device.rs
  36. 2
      conduit/src/api/client_server/typing.rs
  37. 4
      conduit/src/api/client_server/user_directory.rs
  38. 6
      conduit/src/api/client_server/voip.rs
  39. 2
      conduit/src/api/client_server/well_known.rs
  40. 14
      conduit/src/api/ruma_wrapper/axum.rs
  41. 6
      conduit/src/api/ruma_wrapper/mod.rs
  42. 28
      conduit/src/api/server_server.rs
  43. 4
      conduit/src/database/abstraction/rocksdb.rs
  44. 2
      conduit/src/database/abstraction/sqlite.rs
  45. 2
      conduit/src/database/abstraction/watchers.rs
  46. 4
      conduit/src/database/key_value/account_data.rs
  47. 2
      conduit/src/database/key_value/appservice.rs
  48. 7
      conduit/src/database/key_value/globals.rs
  49. 4
      conduit/src/database/key_value/key_backups.rs
  50. 27
      conduit/src/database/key_value/media.rs
  51. 4
      conduit/src/database/key_value/pusher.rs
  52. 6
      conduit/src/database/key_value/rooms/alias.rs
  53. 2
      conduit/src/database/key_value/rooms/auth_chain.rs
  54. 2
      conduit/src/database/key_value/rooms/directory.rs
  55. 4
      conduit/src/database/key_value/rooms/edus/presence.rs
  56. 4
      conduit/src/database/key_value/rooms/edus/read_receipt.rs
  57. 2
      conduit/src/database/key_value/rooms/lazy_load.rs
  58. 2
      conduit/src/database/key_value/rooms/metadata.rs
  59. 2
      conduit/src/database/key_value/rooms/outlier.rs
  60. 3
      conduit/src/database/key_value/rooms/pdu_metadata.rs
  61. 2
      conduit/src/database/key_value/rooms/search.rs
  62. 4
      conduit/src/database/key_value/rooms/short.rs
  63. 2
      conduit/src/database/key_value/rooms/state.rs
  64. 4
      conduit/src/database/key_value/rooms/state_accessor.rs
  65. 7
      conduit/src/database/key_value/rooms/state_cache.rs
  66. 3
      conduit/src/database/key_value/rooms/state_compressor.rs
  67. 4
      conduit/src/database/key_value/rooms/threads.rs
  68. 10
      conduit/src/database/key_value/rooms/timeline.rs
  69. 4
      conduit/src/database/key_value/rooms/user.rs
  70. 3
      conduit/src/database/key_value/sending.rs
  71. 2
      conduit/src/database/key_value/transaction_ids.rs
  72. 4
      conduit/src/database/key_value/uiaa.rs
  73. 7
      conduit/src/database/key_value/users.rs
  74. 23
      conduit/src/database/mod.rs
  75. 2
      conduit/src/lib.rs
  76. 32
      conduit/src/main.rs
  77. 2
      conduit/src/service/account_data/data.rs
  78. 2
      conduit/src/service/account_data/mod.rs
  79. 22
      conduit/src/service/admin/mod.rs
  80. 4
      conduit/src/service/appservice/mod.rs
  81. 4
      conduit/src/service/globals/data.rs
  82. 14
      conduit/src/service/globals/mod.rs
  83. 4
      conduit/src/service/key_backups/data.rs
  84. 2
      conduit/src/service/key_backups/mod.rs
  85. 2
      conduit/src/service/media/data.rs
  86. 8
      conduit/src/service/media/mod.rs
  87. 2
      conduit/src/service/mod.rs
  88. 11
      conduit/src/service/pdu.rs
  89. 4
      conduit/src/service/pusher/data.rs
  90. 9
      conduit/src/service/pusher/mod.rs
  91. 6
      conduit/src/service/rooms/alias/mod.rs
  92. 2
      conduit/src/service/rooms/auth_chain/data.rs
  93. 6
      conduit/src/service/rooms/auth_chain/mod.rs
  94. 2
      conduit/src/service/rooms/edus/presence/data.rs
  95. 2
      conduit/src/service/rooms/edus/presence/mod.rs
  96. 2
      conduit/src/service/rooms/edus/read_receipt/data.rs
  97. 6
      conduit/src/service/rooms/edus/read_receipt/mod.rs
  98. 6
      conduit/src/service/rooms/edus/typing/mod.rs
  99. 38
      conduit/src/service/rooms/event_handler/mod.rs
  100. 30
      conduit/src/service/rooms/helpers/mod.rs
  101. Some files were not shown because too many files have changed in this diff Show More

2
Cargo.toml

@ -14,7 +14,7 @@ str_to_string = "warn"
[workspace.package] [workspace.package]
# See also `rust-toolchain.toml` # See also `rust-toolchain.toml`
edition = "2021" edition = "2024"
homepage = "https://conduit.rs" homepage = "https://conduit.rs"
repository = "https://gitlab.com/famedly/conduit" repository = "https://gitlab.com/famedly/conduit"
rust-version = "1.85.0" rust-version = "1.85.0"

4
conduit-config/src/error.rs

@ -4,7 +4,9 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
#[error("The media directory structure depth multiplied by the length is equal to or greater than a sha256 hex hash, please reduce at least one of the two so that their product is less than 64")] #[error(
"The media directory structure depth multiplied by the length is equal to or greater than a sha256 hex hash, please reduce at least one of the two so that their product is less than 64"
)]
DirectoryStructureLengthDepthTooLarge, DirectoryStructureLengthDepthTooLarge,
#[error("Invalid S3 config")] #[error("Invalid S3 config")]

6
conduit-config/src/lib.rs

@ -8,10 +8,10 @@ use std::{
use bytesize::ByteSize; use bytesize::ByteSize;
pub use error::Error; pub use error::Error;
use ruma::{api::federation::discovery::VerifyKey, serde::Base64, OwnedServerName, RoomVersionId}; use ruma::{OwnedServerName, RoomVersionId, api::federation::discovery::VerifyKey, serde::Base64};
use serde::{ use serde::{
de::{Error as _, IgnoredAny},
Deserialize, Deserialize,
de::{Error as _, IgnoredAny},
}; };
use url::Url; use url::Url;
@ -728,7 +728,7 @@ impl std::fmt::Display for Config {
let mut msg: String = "Active config values:\n\n".to_owned(); let mut msg: String = "Active config values:\n\n".to_owned();
for line in lines.into_iter().enumerate() { for line in lines.into_iter().enumerate() {
msg += &format!("{}: {}\n", line.1 .0, line.1 .1); msg += &format!("{}: {}\n", line.1.0, line.1.1);
} }
write!(f, "{msg}") write!(f, "{msg}")

4
conduit/src/api/appservice_server.rs

@ -1,6 +1,6 @@
use crate::{services, utils, Error, Result, SUPPORTED_VERSIONS}; use crate::{Error, Result, SUPPORTED_VERSIONS, services, utils};
use bytes::BytesMut; use bytes::BytesMut;
use ruma::api::{appservice::Registration, IncomingResponse, OutgoingRequest, SendAccessToken}; use ruma::api::{IncomingResponse, OutgoingRequest, SendAccessToken, appservice::Registration};
use std::{fmt::Debug, mem, time::Duration}; use std::{fmt::Debug, mem, time::Duration};
use tracing::warn; use tracing::warn;

12
conduit/src/api/client_server/account.rs

@ -1,18 +1,20 @@
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
use crate::{api::client_server, services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, api::client_server, services, utils};
use ruma::{ use ruma::{
UserId,
api::client::{ api::client::{
account::{ account::{
change_password, deactivate, get_3pids, get_username_availability, ThirdPartyIdRemovalStatus, change_password, deactivate, get_3pids,
get_username_availability,
register::{self, LoginType}, register::{self, LoginType},
request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn,
whoami, ThirdPartyIdRemovalStatus, whoami,
}, },
error::ErrorKind, error::ErrorKind,
uiaa::{AuthFlow, AuthType, UiaaInfo}, uiaa::{AuthFlow, AuthType, UiaaInfo},
}, },
events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType}, events::{GlobalAccountDataEventType, room::message::RoomMessageEventContent},
push, UserId, push,
}; };
use tracing::{info, warn}; use tracing::{info, warn};

2
conduit/src/api/client_server/alias.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::api::client::{ use ruma::api::client::{
alias::{create_alias, delete_alias, get_alias}, alias::{create_alias, delete_alias, get_alias},
error::ErrorKind, error::ErrorKind,

2
conduit/src/api/client_server/appservice.rs

@ -5,7 +5,7 @@ use ruma::api::{
client::{appservice::request_ping, error::ErrorKind}, client::{appservice::request_ping, error::ErrorKind},
}; };
use crate::{api::appservice_server, Error, Result, Ruma}; use crate::{Error, Result, Ruma, api::appservice_server};
/// # `POST /_matrix/client/v1/appservice/{appserviceId}/ping` /// # `POST /_matrix/client/v1/appservice/{appserviceId}/ping`
/// ///

2
conduit/src/api/client_server/backup.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::api::client::{ use ruma::api::client::{
backup::{ backup::{
add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session, add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session,

2
conduit/src/api/client_server/capabilities.rs

@ -1,4 +1,4 @@
use crate::{services, Result, Ruma}; use crate::{Result, Ruma, services};
use ruma::api::client::discovery::get_capabilities::{ use ruma::api::client::discovery::get_capabilities::{
self, self,
v3::{Capabilities, RoomVersionStability, RoomVersionsCapability}, v3::{Capabilities, RoomVersionStability, RoomVersionsCapability},

2
conduit/src/api/client_server/config.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
api::client::{ api::client::{
config::{ config::{

2
conduit/src/api/client_server/context.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
api::client::{context::get_context, error::ErrorKind, filter::LazyLoadOptions}, api::client::{context::get_context, error::ErrorKind, filter::LazyLoadOptions},
events::StateEventType, events::StateEventType,

2
conduit/src/api/client_server/device.rs

@ -1,4 +1,4 @@
use crate::{services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils};
use ruma::api::client::{ use ruma::api::client::{
device::{self, delete_device, delete_devices, get_device, get_devices, update_device}, device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
error::ErrorKind, error::ErrorKind,

8
conduit/src/api/client_server/directory.rs

@ -1,5 +1,6 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
ServerName, UInt,
api::{ api::{
client::{ client::{
directory::{ directory::{
@ -13,6 +14,7 @@ use ruma::{
}, },
directory::{Filter, PublicRoomsChunk, RoomNetwork}, directory::{Filter, PublicRoomsChunk, RoomNetwork},
events::{ events::{
StateEventType,
room::{ room::{
avatar::RoomAvatarEventContent, avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent, canonical_alias::RoomCanonicalAliasEventContent,
@ -22,9 +24,7 @@ use ruma::{
join_rules::RoomJoinRulesEventContent, join_rules::RoomJoinRulesEventContent,
topic::RoomTopicEventContent, topic::RoomTopicEventContent,
}, },
StateEventType,
}, },
ServerName, UInt,
}; };
use tracing::{error, info, warn}; use tracing::{error, info, warn};
@ -169,7 +169,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Invalid `since` token", "Invalid `since` token",
)) ));
} }
}; };

2
conduit/src/api/client_server/filter.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::api::client::{ use ruma::api::client::{
error::ErrorKind, error::ErrorKind,
filter::{create_filter, get_filter}, filter::{create_filter, get_filter},

8
conduit/src/api/client_server/keys.rs

@ -1,7 +1,8 @@
use super::SESSION_ID_LENGTH; use super::SESSION_ID_LENGTH;
use crate::{services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils};
use futures_util::{stream::FuturesUnordered, StreamExt}; use futures_util::{StreamExt, stream::FuturesUnordered};
use ruma::{ use ruma::{
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
api::{ api::{
client::{ client::{
error::ErrorKind, error::ErrorKind,
@ -14,11 +15,10 @@ use ruma::{
federation, federation,
}, },
serde::Raw, serde::Raw,
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
}; };
use serde_json::json; use serde_json::json;
use std::{ use std::{
collections::{hash_map, BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet, hash_map},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use tracing::{debug, error}; use tracing::{debug, error};

4
conduit/src/api/client_server/media.rs

@ -3,9 +3,10 @@
use std::time::Duration; use std::time::Duration;
use crate::{service::media::FileMeta, services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, service::media::FileMeta, services, utils};
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma::{ use ruma::{
ServerName, UInt,
api::{ api::{
client::{ client::{
authenticated_media::{ authenticated_media::{
@ -18,7 +19,6 @@ use ruma::{
}, },
http_headers::{ContentDisposition, ContentDispositionType}, http_headers::{ContentDisposition, ContentDispositionType},
media::Method, media::Method,
ServerName, UInt,
}; };
const MXC_LENGTH: usize = 32; const MXC_LENGTH: usize = 32;

20
conduit/src/api/client_server/membership.rs

@ -1,4 +1,5 @@
use ruma::{ use ruma::{
OwnedServerName, RoomId, UserId,
api::{ api::{
client::{ client::{
error::ErrorKind, error::ErrorKind,
@ -11,17 +12,16 @@ use ruma::{
}, },
federation::{ federation::{
self, self,
membership::{create_invite, RawStrippedState}, membership::{RawStrippedState, create_invite},
}, },
}, },
events::{ events::{
StateEventType, TimelineEventType,
room::{ room::{
join_rules::JoinRule, join_rules::JoinRule,
member::{MembershipState, RoomMemberEventContent}, member::{MembershipState, RoomMemberEventContent},
}, },
StateEventType, TimelineEventType,
}, },
OwnedServerName, RoomId, UserId,
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use std::{ use std::{
@ -32,8 +32,9 @@ use tokio::sync::RwLock;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use crate::{ use crate::{
service::pdu::{gen_event_id_canonical_json, PduBuilder}, Error, PduEvent, Result, Ruma,
services, utils, Error, PduEvent, Result, Ruma, service::pdu::{PduBuilder, gen_event_id_canonical_json},
services, utils,
}; };
/// # `POST /_matrix/client/r0/rooms/{roomId}/join` /// # `POST /_matrix/client/r0/rooms/{roomId}/join`
@ -253,7 +254,7 @@ pub async fn knock_room_route(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::forbidden(), ErrorKind::forbidden(),
"You are not allowed to knock on this room.", "You are not allowed to knock on this room.",
)) ));
} }
}; };
@ -774,7 +775,12 @@ pub(crate) async fn invite_helper(
}; };
if *pdu.event_id != *event_id { if *pdu.event_id != *event_id {
warn!("Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", user_id.server_name(), pdu_json, value); warn!(
"Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}",
user_id.server_name(),
pdu_json,
value
);
} }
let origin: OwnedServerName = serde_json::from_value( let origin: OwnedServerName = serde_json::from_value(

3
conduit/src/api/client_server/message.rs

@ -1,6 +1,7 @@
use crate::{ use crate::{
Error, Result, Ruma,
service::{pdu::PduBuilder, rooms::timeline::PduCount}, service::{pdu::PduBuilder, rooms::timeline::PduCount},
services, utils, Error, Result, Ruma, services, utils,
}; };
use ruma::{ use ruma::{
api::client::{ api::client::{

2
conduit/src/api/client_server/openid.rs

@ -2,7 +2,7 @@ use std::time::Duration;
use ruma::{api::client::account, authentication::TokenType}; use ruma::{api::client::account, authentication::TokenType};
use crate::{services, Result, Ruma}; use crate::{Result, Ruma, services};
/// # `POST /_matrix/client/r0/user/{userId}/openid/request_token` /// # `POST /_matrix/client/r0/user/{userId}/openid/request_token`
/// ///

2
conduit/src/api/client_server/presence.rs

@ -1,4 +1,4 @@
use crate::{services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils};
use ruma::api::client::{ use ruma::api::client::{
error::ErrorKind, error::ErrorKind,
presence::{get_presence, set_presence}, presence::{get_presence, set_presence},

4
conduit/src/api/client_server/profile.rs

@ -1,4 +1,4 @@
use crate::{service::pdu::PduBuilder, services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, service::pdu::PduBuilder, services, utils};
use ruma::{ use ruma::{
api::{ api::{
client::{ client::{
@ -9,7 +9,7 @@ use ruma::{
}, },
federation::{self, query::get_profile_information::v1::ProfileField}, federation::{self, query::get_profile_information::v1::ProfileField},
}, },
events::{room::member::RoomMemberEventContent, StateEventType, TimelineEventType}, events::{StateEventType, TimelineEventType, room::member::RoomMemberEventContent},
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use std::sync::Arc; use std::sync::Arc;

4
conduit/src/api/client_server/push.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
@ -8,7 +8,7 @@ use ruma::{
set_pushrule_enabled, set_pushrule_enabled,
}, },
}, },
events::{push_rules::PushRulesEvent, GlobalAccountDataEventType}, events::{GlobalAccountDataEventType, push_rules::PushRulesEvent},
push::{InsertPushRuleError, RemovePushRuleError}, push::{InsertPushRuleError, RemovePushRuleError},
}; };

10
conduit/src/api/client_server/read_marker.rs

@ -1,11 +1,11 @@
use crate::{service::rooms::timeline::PduCount, services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, service::rooms::timeline::PduCount, services};
use ruma::{ use ruma::{
MilliSecondsSinceUnixEpoch,
api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt}, api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt},
events::{ events::{
receipt::{ReceiptThread, ReceiptType},
RoomAccountDataEventType, RoomAccountDataEventType,
receipt::{ReceiptThread, ReceiptType},
}, },
MilliSecondsSinceUnixEpoch,
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -55,7 +55,7 @@ pub async fn set_read_marker_route(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Read receipt is in backfilled timeline", "Read receipt is in backfilled timeline",
)) ));
} }
PduCount::Normal(c) => c, PduCount::Normal(c) => c,
}; };
@ -165,7 +165,7 @@ pub async fn create_receipt_route(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Read receipt is in backfilled timeline", "Read receipt is in backfilled timeline",
)) ));
} }
PduCount::Normal(c) => c, PduCount::Normal(c) => c,
}; };

4
conduit/src/api/client_server/redact.rs

@ -1,9 +1,9 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{service::pdu::PduBuilder, services, Result, Ruma}; use crate::{Result, Ruma, service::pdu::PduBuilder, services};
use ruma::{ use ruma::{
api::client::redact::redact_event, api::client::redact::redact_event,
events::{room::redaction::RoomRedactionEventContent, TimelineEventType}, events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;

2
conduit/src/api/client_server/relations.rs

@ -3,7 +3,7 @@ use ruma::api::client::relations::{
get_relating_events_with_rel_type_and_event_type, get_relating_events_with_rel_type_and_event_type,
}; };
use crate::{services, Result, Ruma}; use crate::{Result, Ruma, services};
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
pub async fn get_relating_events_with_rel_type_and_event_type_route( pub async fn get_relating_events_with_rel_type_and_event_type_route(

4
conduit/src/api/client_server/report.rs

@ -1,4 +1,4 @@
use crate::{services, utils::HtmlEscape, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils::HtmlEscape};
use ruma::{ use ruma::{
api::client::{error::ErrorKind, room::report_content}, api::client::{error::ErrorKind, room::report_content},
events::room::message, events::room::message,
@ -20,7 +20,7 @@ pub async fn report_event_route(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Invalid Event ID", "Invalid Event ID",
)) ));
} }
}; };

8
conduit/src/api/client_server/room.rs

@ -1,12 +1,15 @@
use crate::{ use crate::{
api::client_server::invite_helper, service::pdu::PduBuilder, services, Error, Result, Ruma, Error, Result, Ruma, api::client_server::invite_helper, service::pdu::PduBuilder, services,
}; };
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId,
RoomVersionId,
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
room::{self, aliases, create_room, get_room_event, upgrade_room}, room::{self, aliases, create_room, get_room_event, upgrade_room},
}, },
events::{ events::{
StateEventType, TimelineEventType,
room::{ room::{
canonical_alias::RoomCanonicalAliasEventContent, canonical_alias::RoomCanonicalAliasEventContent,
create::RoomCreateEventContent, create::RoomCreateEventContent,
@ -19,12 +22,9 @@ use ruma::{
tombstone::RoomTombstoneEventContent, tombstone::RoomTombstoneEventContent,
topic::RoomTopicEventContent, topic::RoomTopicEventContent,
}, },
StateEventType, TimelineEventType,
}, },
int, int,
serde::JsonObject, serde::JsonObject,
CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId,
RoomVersionId,
}; };
use serde::Deserialize; use serde::Deserialize;
use serde_json::{json, value::to_raw_value}; use serde_json::{json, value::to_raw_value};

4
conduit/src/api/client_server/search.rs

@ -1,4 +1,4 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::api::client::{ use ruma::api::client::{
error::ErrorKind, error::ErrorKind,
search::search_events::{ search::search_events::{
@ -63,7 +63,7 @@ pub async fn search_events_route(
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Invalid next_batch token.", "Invalid next_batch token.",
)) ));
} }
None => 0, // Default to the start None => 0, // Default to the start
}; };

4
conduit/src/api/client_server/session.rs

@ -1,12 +1,12 @@
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH}; use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
use crate::{services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils};
use ruma::{ use ruma::{
UserId,
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
session::{get_login_types, login, logout, logout_all}, session::{get_login_types, login, logout, logout_all},
uiaa::UserIdentifier, uiaa::UserIdentifier,
}, },
UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
use tracing::{info, warn}; use tracing::{info, warn};

4
conduit/src/api/client_server/space.rs

@ -1,9 +1,9 @@
use std::str::FromStr; use std::str::FromStr;
use crate::{service::rooms::spaces::PagnationToken, services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, service::rooms::spaces::PagnationToken, services};
use ruma::{ use ruma::{
api::client::{error::ErrorKind, space::get_hierarchy},
UInt, UInt,
api::client::{error::ErrorKind, space::get_hierarchy},
}; };
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`` /// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy``

6
conduit/src/api/client_server/state.rs

@ -1,7 +1,8 @@
use std::sync::Arc; use std::sync::Arc;
use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaResponse}; use crate::{Error, Result, Ruma, RumaResponse, service::pdu::PduBuilder, services};
use ruma::{ use ruma::{
EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
state::{ state::{
@ -10,10 +11,9 @@ use ruma::{
}, },
}, },
events::{ events::{
room::canonical_alias::RoomCanonicalAliasEventContent, AnyStateEventContent, StateEventType, AnyStateEventContent, StateEventType, room::canonical_alias::RoomCanonicalAliasEventContent,
}, },
serde::Raw, serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
}; };
use tracing::warn; use tracing::warn;

13
conduit/src/api/client_server/sync.rs

@ -1,31 +1,32 @@
use crate::{ use crate::{
Error, PduEvent, Result, Ruma, RumaResponse,
service::{pdu::EventHash, rooms::timeline::PduCount}, service::{pdu::EventHash, rooms::timeline::PduCount},
services, utils, Error, PduEvent, Result, Ruma, RumaResponse, services, utils,
}; };
use ruma::{ use ruma::{
DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId,
api::client::{ api::client::{
filter::{FilterDefinition, LazyLoadOptions}, filter::{FilterDefinition, LazyLoadOptions},
sync::sync_events::{ sync::sync_events::{
self, self, DeviceLists, UnreadNotificationsCount,
v3::{ v3::{
Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom, Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom,
KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms, KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms,
State, StateEvents, Timeline, ToDevice, State, StateEvents, Timeline, ToDevice,
}, },
DeviceLists, UnreadNotificationsCount,
}, },
uiaa::UiaaResponse, uiaa::UiaaResponse,
}, },
events::{ events::{
room::member::{MembershipState, RoomMemberEventContent},
StateEventType, TimelineEventType, StateEventType, TimelineEventType,
room::member::{MembershipState, RoomMemberEventContent},
}, },
serde::Raw, serde::Raw,
uint, DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, uint,
}; };
use std::{ use std::{
collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet}, collections::{BTreeMap, BTreeSet, HashMap, HashSet, hash_map::Entry},
sync::Arc, sync::Arc,
time::Duration, time::Duration,
}; };

4
conduit/src/api/client_server/tag.rs

@ -1,9 +1,9 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
api::client::tag::{create_tag, delete_tag, get_tags}, api::client::tag::{create_tag, delete_tag, get_tags},
events::{ events::{
tag::{TagEvent, TagEventContent},
RoomAccountDataEventType, RoomAccountDataEventType,
tag::{TagEvent, TagEventContent},
}, },
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;

2
conduit/src/api/client_server/threads.rs

@ -1,6 +1,6 @@
use ruma::api::client::{error::ErrorKind, threads::get_threads}; use ruma::api::client::{error::ErrorKind, threads::get_threads};
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads` /// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
pub async fn get_threads_route( pub async fn get_threads_route(

2
conduit/src/api/client_server/to_device.rs

@ -1,6 +1,6 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use ruma::{ use ruma::{
api::{ api::{
client::{error::ErrorKind, to_device::send_event_to_device}, client::{error::ErrorKind, to_device::send_event_to_device},

2
conduit/src/api/client_server/typing.rs

@ -1,4 +1,4 @@
use crate::{services, utils, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services, utils};
use ruma::api::client::{error::ErrorKind, typing::create_typing_event}; use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}` /// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`

4
conduit/src/api/client_server/user_directory.rs

@ -1,9 +1,9 @@
use crate::{services, Result, Ruma}; use crate::{Result, Ruma, services};
use ruma::{ use ruma::{
api::client::user_directory::search_users, api::client::user_directory::search_users,
events::{ events::{
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
StateEventType, StateEventType,
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
}, },
}; };

6
conduit/src/api/client_server/voip.rs

@ -1,10 +1,10 @@
use crate::{services, Error, Result, Ruma}; use crate::{Error, Result, Ruma, services};
use base64::{engine::general_purpose, Engine as _}; use base64::{Engine as _, engine::general_purpose};
use conduit_config::TurnAuth; use conduit_config::TurnAuth;
use hmac::{Hmac, Mac}; use hmac::{Hmac, Mac};
use ruma::{ use ruma::{
api::client::{error::ErrorKind, voip::get_turn_server_info},
SecondsSinceUnixEpoch, SecondsSinceUnixEpoch,
api::client::{error::ErrorKind, voip::get_turn_server_info},
}; };
use sha1::Sha1; use sha1::Sha1;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};

2
conduit/src/api/client_server/well_known.rs

@ -1,6 +1,6 @@
use ruma::api::client::discovery::discover_homeserver::{self, HomeserverInfo}; use ruma::api::client::discovery::discover_homeserver::{self, HomeserverInfo};
use crate::{services, Result, Ruma}; use crate::{Result, Ruma, services};
/// # `GET /.well-known/matrix/client` /// # `GET /.well-known/matrix/client`
/// ///

14
conduit/src/api/ruma_wrapper/axum.rs

@ -1,30 +1,30 @@
use std::{collections::BTreeMap, error::Error as _, iter::FromIterator, str}; use std::{collections::BTreeMap, error::Error as _, iter::FromIterator, str};
use axum::{ use axum::{
RequestPartsExt,
body::Body, body::Body,
extract::{FromRequest, Path}, extract::{FromRequest, Path},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
RequestPartsExt,
}; };
use axum_extra::{ use axum_extra::{
headers::{authorization::Bearer, Authorization},
typed_header::TypedHeaderRejectionReason,
TypedHeader, TypedHeader,
headers::{Authorization, authorization::Bearer},
typed_header::TypedHeaderRejectionReason,
}; };
use bytes::{BufMut, BytesMut}; use bytes::{BufMut, BytesMut};
use http::{Request, StatusCode}; use http::{Request, StatusCode};
use ruma::{ use ruma::{
CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId,
api::{ api::{
client::error::ErrorKind, federation::authentication::XMatrix, AuthScheme, IncomingRequest, AuthScheme, IncomingRequest, OutgoingResponse, client::error::ErrorKind,
OutgoingResponse, federation::authentication::XMatrix,
}, },
CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
use tracing::{debug, error, warn}; use tracing::{debug, error, warn};
use super::{Ruma, RumaResponse}; use super::{Ruma, RumaResponse};
use crate::{service::appservice::RegistrationInfo, services, Error, Result}; use crate::{Error, Result, service::appservice::RegistrationInfo, services};
enum Token { enum Token {
Appservice(Box<RegistrationInfo>), Appservice(Box<RegistrationInfo>),

6
conduit/src/api/ruma_wrapper/mod.rs

@ -1,7 +1,7 @@
use crate::{service::appservice::RegistrationInfo, Error}; use crate::{Error, service::appservice::RegistrationInfo};
use ruma::{ use ruma::{
api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId,
OwnedUserId, api::client::uiaa::UiaaResponse,
}; };
use std::ops::Deref; use std::ops::Deref;

28
conduit/src/api/server_server.rs

@ -1,33 +1,38 @@
#![allow(deprecated)] #![allow(deprecated)]
use crate::{ use crate::{
Error, PduEvent, Result, Ruma, SUPPORTED_VERSIONS,
api::client_server::{self, claim_keys_helper, get_keys_helper}, api::client_server::{self, claim_keys_helper, get_keys_helper},
service::{ service::{
globals::SigningKeys, globals::SigningKeys,
media::FileMeta, media::FileMeta,
pdu::{gen_event_id_canonical_json, PduBuilder}, pdu::{PduBuilder, gen_event_id_canonical_json},
}, },
services, utils, Error, PduEvent, Result, Ruma, SUPPORTED_VERSIONS, services, utils,
}; };
use axum::{response::IntoResponse, Json}; use axum::{Json, response::IntoResponse};
use axum_extra::headers::{CacheControl, Header}; use axum_extra::headers::{CacheControl, Header};
use get_profile_information::v1::ProfileField; use get_profile_information::v1::ProfileField;
use http::header::AUTHORIZATION; use http::header::AUTHORIZATION;
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, RoomVersionId,
ServerName, Signatures, UserId,
api::{ api::{
EndpointError, IncomingResponse, OutgoingRequest, OutgoingResponse, SendAccessToken,
client::error::{Error as RumaError, ErrorKind}, client::error::{Error as RumaError, ErrorKind},
federation::{ federation::{
authenticated_media::{ authenticated_media::{
get_content, get_content_thumbnail, Content, ContentMetadata, FileOrLocation, Content, ContentMetadata, FileOrLocation, get_content, get_content_thumbnail,
}, },
authorization::get_event_authorization, authorization::get_event_authorization,
backfill::get_backfill, backfill::get_backfill,
device::get_devices::{self, v1::UserDevice}, device::get_devices::{self, v1::UserDevice},
directory::{get_public_rooms, get_public_rooms_filtered}, directory::{get_public_rooms, get_public_rooms_filtered},
discovery::{ discovery::{
discover_homeserver, get_server_keys, get_server_version, ServerSigningKeys, ServerSigningKeys, VerifyKey, discover_homeserver, get_server_keys,
VerifyKey, get_server_version,
}, },
event::{get_event, get_missing_events, get_room_state, get_room_state_ids}, event::{get_event, get_missing_events, get_room_state, get_room_state_ids},
keys::{claim_keys, get_keys}, keys::{claim_keys, get_keys},
@ -43,25 +48,22 @@ use ruma::{
send_transaction_message, send_transaction_message,
}, },
}, },
EndpointError, IncomingResponse, OutgoingRequest, OutgoingResponse, SendAccessToken,
}, },
directory::{Filter, RoomNetwork}, directory::{Filter, RoomNetwork},
events::{ events::{
StateEventType, TimelineEventType,
receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType}, receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType},
room::{ room::{
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
member::{MembershipState, RoomMemberEventContent}, member::{MembershipState, RoomMemberEventContent},
}, },
StateEventType, TimelineEventType,
}, },
room_version_rules::{AuthorizationRules, RoomVersionRules}, room_version_rules::{AuthorizationRules, RoomVersionRules},
serde::{Base64, JsonObject, Raw}, serde::{Base64, JsonObject, Raw},
to_device::DeviceIdOrAllDevices, to_device::DeviceIdOrAllDevices,
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, uint, user_id,
OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId,
RoomVersionId, ServerName, Signatures, UserId,
}; };
use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
fmt::Debug, fmt::Debug,
@ -2545,7 +2547,7 @@ pub async fn well_known_server(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{add_port_to_hostname, get_ip_with_port, FedDest}; use super::{FedDest, add_port_to_hostname, get_ip_with_port};
#[test] #[test]
fn ips_get_default_ports() { fn ips_get_default_ports() {

4
conduit/src/database/abstraction/rocksdb.rs

@ -1,5 +1,5 @@
use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree}; use super::{KeyValueDatabaseEngine, KvTree, watchers::Watchers};
use crate::{utils, Result}; use crate::{Result, utils};
use conduit_config::Config; use conduit_config::Config;
use std::{ use std::{
future::Future, future::Future,

2
conduit/src/database/abstraction/sqlite.rs

@ -1,4 +1,4 @@
use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree}; use super::{KeyValueDatabaseEngine, KvTree, watchers::Watchers};
use crate::Result; use crate::Result;
use conduit_config::Config; use conduit_config::Config;
use parking_lot::{Mutex, MutexGuard}; use parking_lot::{Mutex, MutexGuard};

2
conduit/src/database/abstraction/watchers.rs

@ -1,5 +1,5 @@
use std::{ use std::{
collections::{hash_map, HashMap}, collections::{HashMap, hash_map},
future::Future, future::Future,
pin::Pin, pin::Pin,
sync::RwLock, sync::RwLock,

4
conduit/src/database/key_value/account_data.rs

@ -1,13 +1,13 @@
use std::collections::HashMap; use std::collections::HashMap;
use ruma::{ use ruma::{
RoomId, UserId,
api::client::error::ErrorKind, api::client::error::ErrorKind,
events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType},
serde::Raw, serde::Raw,
RoomId, UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::account_data::Data for KeyValueDatabase { impl service::account_data::Data for KeyValueDatabase {
/// Places one event in the account data of the user and removes the previous entry. /// Places one event in the account data of the user and removes the previous entry.

2
conduit/src/database/key_value/appservice.rs

@ -1,6 +1,6 @@
use ruma::api::appservice::Registration; use ruma::api::appservice::Registration;
use crate::{database::KeyValueDatabase, service, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::appservice::Data for KeyValueDatabase { impl service::appservice::Data for KeyValueDatabase {
/// Registers an appservice and returns the ID to the caller /// Registers an appservice and returns the ID to the caller

7
conduit/src/database/key_value/globals.rs

@ -1,18 +1,19 @@
use std::collections::HashMap; use std::collections::HashMap;
use async_trait::async_trait; use async_trait::async_trait;
use futures_util::{stream::FuturesUnordered, StreamExt}; use futures_util::{StreamExt, stream::FuturesUnordered};
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::{ use ruma::{
DeviceId, ServerName, UserId,
api::federation::discovery::{OldVerifyKey, ServerSigningKeys}, api::federation::discovery::{OldVerifyKey, ServerSigningKeys},
signatures::Ed25519KeyPair, signatures::Ed25519KeyPair,
DeviceId, ServerName, UserId,
}; };
use crate::{ use crate::{
Error, Result,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{self, globals::SigningKeys}, service::{self, globals::SigningKeys},
services, utils, Error, Result, services, utils,
}; };
pub const COUNTER: &[u8] = b"c"; pub const COUNTER: &[u8] = b"c";

4
conduit/src/database/key_value/key_backups.rs

@ -1,15 +1,15 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma::{ use ruma::{
OwnedRoomId, RoomId, UserId,
api::client::{ api::client::{
backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
error::ErrorKind, error::ErrorKind,
}, },
serde::Raw, serde::Raw,
OwnedRoomId, RoomId, UserId,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::key_backups::Data for KeyValueDatabase { impl service::key_backups::Data for KeyValueDatabase {
fn create_backup( fn create_backup(

27
conduit/src/database/key_value/media.rs

@ -2,11 +2,12 @@ use std::{collections::BTreeMap, ops::Range, slice::Split};
use bytesize::ByteSize; use bytesize::ByteSize;
use conduit_config::{MediaRetentionConfig, MediaRetentionScope}; use conduit_config::{MediaRetentionConfig, MediaRetentionScope};
use ruma::{api::client::error::ErrorKind, OwnedServerName, ServerName, UserId}; use ruma::{OwnedServerName, ServerName, UserId, api::client::error::ErrorKind};
use sha2::{digest::Output, Sha256}; use sha2::{Sha256, digest::Output};
use tracing::error; use tracing::error;
use crate::{ use crate::{
Error, Result,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{ service::{
self, self,
@ -15,7 +16,7 @@ use crate::{
MediaQueryFileInfo, MediaQueryThumbInfo, MediaType, ServerNameOrUserId, MediaQueryFileInfo, MediaQueryThumbInfo, MediaType, ServerNameOrUserId,
}, },
}, },
services, utils, Error, Result, services, utils,
}; };
impl service::media::Data for KeyValueDatabase { impl service::media::Data for KeyValueDatabase {
@ -664,9 +665,9 @@ impl service::media::Data for KeyValueDatabase {
} }
} else { } else {
error!( error!(
"Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}", "Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest) hex::encode(&metadata.sha256_digest)
); );
errors.push(Error::BadDatabase( errors.push(Error::BadDatabase(
"Invalid format of key in filehash_servername_mediaid", "Invalid format of key in filehash_servername_mediaid",
)); ));
@ -675,9 +676,9 @@ impl service::media::Data for KeyValueDatabase {
let thumbnail_id_error = || { let thumbnail_id_error = || {
error!( error!(
"Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}", "Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest) hex::encode(&metadata.sha256_digest)
); );
Error::BadDatabase("Invalid format of value in filehash_thumbnailid") Error::BadDatabase("Invalid format of value in filehash_thumbnailid")
}; };
@ -732,7 +733,9 @@ impl service::media::Data for KeyValueDatabase {
} }
Ok(None) => (), Ok(None) => (),
Ok(Some(Err(e))) => { Ok(Some(Err(e))) => {
error!("Error parsing metadata for \"mxc://{server_name}/{media_id}\" from servernamemediaid_metadata: {e}"); error!(
"Error parsing metadata for \"mxc://{server_name}/{media_id}\" from servernamemediaid_metadata: {e}"
);
errors.push(e); errors.push(e);
continue; continue;
} }
@ -748,7 +751,9 @@ impl service::media::Data for KeyValueDatabase {
maybe_remove_remaining_metadata(&metadata, &mut errors); maybe_remove_remaining_metadata(&metadata, &mut errors);
} }
Err(e) => { Err(e) => {
error!("Error parsing metadata for thumbnail of \"mxc://{server_name}/{media_id}\" from thumbnailid_metadata: {e}"); error!(
"Error parsing metadata for thumbnail of \"mxc://{server_name}/{media_id}\" from thumbnailid_metadata: {e}"
);
errors.push(e); errors.push(e);
} }
} }

4
conduit/src/database/key_value/pusher.rs

@ -1,9 +1,9 @@
use ruma::{ use ruma::{
api::client::push::{set_pusher, Pusher},
UserId, UserId,
api::client::push::{Pusher, set_pusher},
}; };
use crate::{database::KeyValueDatabase, service, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::pusher::Data for KeyValueDatabase { impl service::pusher::Data for KeyValueDatabase {
fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> {

6
conduit/src/database/key_value/rooms/alias.rs

@ -1,9 +1,9 @@
use ruma::{ use ruma::{
api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, UserId,
UserId, api::client::error::ErrorKind,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::alias::Data for KeyValueDatabase { impl service::rooms::alias::Data for KeyValueDatabase {
fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId, user_id: &UserId) -> Result<()> { fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId, user_id: &UserId) -> Result<()> {

2
conduit/src/database/key_value/rooms/auth_chain.rs

@ -1,6 +1,6 @@
use std::{collections::HashSet, mem::size_of, sync::Arc}; use std::{collections::HashSet, mem::size_of, sync::Arc};
use crate::{database::KeyValueDatabase, service, utils, Result}; use crate::{Result, database::KeyValueDatabase, service, utils};
impl service::rooms::auth_chain::Data for KeyValueDatabase { impl service::rooms::auth_chain::Data for KeyValueDatabase {
fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result<Option<Arc<HashSet<u64>>>> { fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result<Option<Arc<HashSet<u64>>>> {

2
conduit/src/database/key_value/rooms/directory.rs

@ -1,6 +1,6 @@
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
use crate::{database::KeyValueDatabase, service, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::rooms::directory::Data for KeyValueDatabase { impl service::rooms::directory::Data for KeyValueDatabase {
fn set_public(&self, room_id: &RoomId) -> Result<()> { fn set_public(&self, room_id: &RoomId) -> Result<()> {

4
conduit/src/database/key_value/rooms/edus/presence.rs

@ -1,10 +1,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use ruma::{ use ruma::{
events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, RoomId, UInt, UserId, OwnedUserId, RoomId, UInt, UserId, events::presence::PresenceEvent, presence::PresenceState,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::edus::presence::Data for KeyValueDatabase { impl service::rooms::edus::presence::Data for KeyValueDatabase {
fn update_presence( fn update_presence(

4
conduit/src/database/key_value/rooms/edus/read_receipt.rs

@ -1,8 +1,8 @@
use ruma::{ use ruma::{
events::receipt::ReceiptEvent, serde::Raw, CanonicalJsonObject, OwnedUserId, RoomId, UserId, CanonicalJsonObject, OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw,
}; };
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::edus::read_receipt::Data for KeyValueDatabase { impl service::rooms::edus::read_receipt::Data for KeyValueDatabase {
fn readreceipt_update( fn readreceipt_update(

2
conduit/src/database/key_value/rooms/lazy_load.rs

@ -1,6 +1,6 @@
use ruma::{DeviceId, RoomId, UserId}; use ruma::{DeviceId, RoomId, UserId};
use crate::{database::KeyValueDatabase, service, Result}; use crate::{Result, database::KeyValueDatabase, service};
impl service::rooms::lazy_loading::Data for KeyValueDatabase { impl service::rooms::lazy_loading::Data for KeyValueDatabase {
fn lazy_load_was_sent_before( fn lazy_load_was_sent_before(

2
conduit/src/database/key_value/rooms/metadata.rs

@ -1,6 +1,6 @@
use ruma::{OwnedRoomId, RoomId}; use ruma::{OwnedRoomId, RoomId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::metadata::Data for KeyValueDatabase { impl service::rooms::metadata::Data for KeyValueDatabase {
fn exists(&self, room_id: &RoomId) -> Result<bool> { fn exists(&self, room_id: &RoomId) -> Result<bool> {

2
conduit/src/database/key_value/rooms/outlier.rs

@ -1,6 +1,6 @@
use ruma::{CanonicalJsonObject, EventId}; use ruma::{CanonicalJsonObject, EventId};
use crate::{database::KeyValueDatabase, service, Error, PduEvent, Result}; use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service};
impl service::rooms::outlier::Data for KeyValueDatabase { impl service::rooms::outlier::Data for KeyValueDatabase {
fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> { fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> {

3
conduit/src/database/key_value/rooms/pdu_metadata.rs

@ -3,9 +3,10 @@ use std::sync::Arc;
use ruma::{EventId, RoomId, UserId}; use ruma::{EventId, RoomId, UserId};
use crate::{ use crate::{
Error, PduEvent, Result,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{self, rooms::timeline::PduCount}, service::{self, rooms::timeline::PduCount},
services, utils, Error, PduEvent, Result, services, utils,
}; };
impl service::rooms::pdu_metadata::Data for KeyValueDatabase { impl service::rooms::pdu_metadata::Data for KeyValueDatabase {

2
conduit/src/database/key_value/rooms/search.rs

@ -1,6 +1,6 @@
use ruma::RoomId; use ruma::RoomId;
use crate::{database::KeyValueDatabase, service, services, utils, Result}; use crate::{Result, database::KeyValueDatabase, service, services, utils};
/// Splits a string into tokens used as keys in the search inverted index /// Splits a string into tokens used as keys in the search inverted index
/// ///

4
conduit/src/database/key_value/rooms/short.rs

@ -1,8 +1,8 @@
use std::sync::Arc; use std::sync::Arc;
use ruma::{events::StateEventType, EventId, RoomId}; use ruma::{EventId, RoomId, events::StateEventType};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::short::Data for KeyValueDatabase { impl service::rooms::short::Data for KeyValueDatabase {
fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> {

2
conduit/src/database/key_value/rooms/state.rs

@ -4,7 +4,7 @@ use std::collections::HashSet;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::MutexGuard; use tokio::sync::MutexGuard;
use crate::{database::KeyValueDatabase, service, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::rooms::state::Data for KeyValueDatabase { impl service::rooms::state::Data for KeyValueDatabase {
fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> { fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> {

4
conduit/src/database/key_value/rooms/state_accessor.rs

@ -1,8 +1,8 @@
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils};
use async_trait::async_trait; use async_trait::async_trait;
use ruma::{events::StateEventType, EventId, RoomId}; use ruma::{EventId, RoomId, events::StateEventType};
#[async_trait] #[async_trait]
impl service::rooms::state_accessor::Data for KeyValueDatabase { impl service::rooms::state_accessor::Data for KeyValueDatabase {

7
conduit/src/database/key_value/rooms/state_cache.rs

@ -1,15 +1,16 @@
use std::{collections::HashSet, sync::Arc}; use std::{collections::HashSet, sync::Arc};
use ruma::{ use ruma::{
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
events::{AnyStrippedStateEvent, AnySyncStateEvent}, events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw, serde::Raw,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
}; };
use crate::{ use crate::{
database::{abstraction::KvTree, KeyValueDatabase}, Error, Result,
database::{KeyValueDatabase, abstraction::KvTree},
service::{self, appservice::RegistrationInfo}, service::{self, appservice::RegistrationInfo},
services, utils, Error, Result, services, utils,
}; };
use super::{get_room_and_user_byte_ids, get_userroom_id_bytes}; use super::{get_room_and_user_byte_ids, get_userroom_id_bytes};

3
conduit/src/database/key_value/rooms/state_compressor.rs

@ -1,9 +1,10 @@
use std::{collections::HashSet, mem::size_of, sync::Arc}; use std::{collections::HashSet, mem::size_of, sync::Arc};
use crate::{ use crate::{
Error, Result,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{self, rooms::state_compressor::data::StateDiff}, service::{self, rooms::state_compressor::data::StateDiff},
utils, Error, Result, utils,
}; };
impl service::rooms::state_compressor::Data for KeyValueDatabase { impl service::rooms::state_compressor::Data for KeyValueDatabase {

4
conduit/src/database/key_value/rooms/threads.rs

@ -1,6 +1,6 @@
use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId, api::client::threads::get_threads::v1::IncludeThreads};
use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils};
impl service::rooms::threads::Data for KeyValueDatabase { impl service::rooms::threads::Data for KeyValueDatabase {
fn threads_until<'a>( fn threads_until<'a>(

10
conduit/src/database/key_value/rooms/timeline.rs

@ -1,11 +1,11 @@
use std::{collections::hash_map, mem::size_of, sync::Arc}; use std::{collections::hash_map, mem::size_of, sync::Arc};
use ruma::{ use ruma::{
api::client::error::ErrorKind, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, api::client::error::ErrorKind,
}; };
use tracing::error; use tracing::error;
use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils};
use service::rooms::timeline::PduCount; use service::rooms::timeline::PduCount;
@ -346,11 +346,7 @@ fn count_to_id(
pdu_id.extend_from_slice(&0_u64.to_be_bytes()); pdu_id.extend_from_slice(&0_u64.to_be_bytes());
let num = u64::MAX - x; let num = u64::MAX - x;
if subtract { if subtract {
if num > 0 { if num > 0 { num - offset } else { num }
num - offset
} else {
num
}
} else { } else {
num + offset num + offset
} }

4
conduit/src/database/key_value/rooms/user.rs

@ -1,6 +1,6 @@
use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId};
use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service, services, utils};
use super::{get_room_and_user_byte_ids, get_userroom_id_bytes}; use super::{get_room_and_user_byte_ids, get_userroom_id_bytes};
@ -115,7 +115,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
let roomid_index = key let roomid_index = key
.iter() .iter()
.enumerate() .enumerate()
.find(|(_, &b)| b == 0xff) .find(|&(_, &b)| b == 0xff)
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
.0 .0
+ 1; // +1 because the room id starts AFTER the separator + 1; // +1 because the room id starts AFTER the separator

3
conduit/src/database/key_value/sending.rs

@ -1,12 +1,13 @@
use ruma::{ServerName, UserId}; use ruma::{ServerName, UserId};
use crate::{ use crate::{
Error, Result,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{ service::{
self, self,
sending::{OutgoingKind, SendingEventType}, sending::{OutgoingKind, SendingEventType},
}, },
services, utils, Error, Result, services, utils,
}; };
impl service::sending::Data for KeyValueDatabase { impl service::sending::Data for KeyValueDatabase {

2
conduit/src/database/key_value/transaction_ids.rs

@ -1,6 +1,6 @@
use ruma::{DeviceId, TransactionId, UserId}; use ruma::{DeviceId, TransactionId, UserId};
use crate::{database::KeyValueDatabase, service, Result}; use crate::{Result, database::KeyValueDatabase, service};
impl service::transaction_ids::Data for KeyValueDatabase { impl service::transaction_ids::Data for KeyValueDatabase {
fn add_txnid( fn add_txnid(

4
conduit/src/database/key_value/uiaa.rs

@ -1,9 +1,9 @@
use ruma::{ use ruma::{
api::client::{error::ErrorKind, uiaa::UiaaInfo},
CanonicalJsonValue, DeviceId, UserId, CanonicalJsonValue, DeviceId, UserId,
api::client::{error::ErrorKind, uiaa::UiaaInfo},
}; };
use crate::{database::KeyValueDatabase, service, Error, Result}; use crate::{Error, Result, database::KeyValueDatabase, service};
impl service::uiaa::Data for KeyValueDatabase { impl service::uiaa::Data for KeyValueDatabase {
fn set_uiaa_request( fn set_uiaa_request(

7
conduit/src/database/key_value/users.rs

@ -1,20 +1,21 @@
use std::{collections::BTreeMap, mem::size_of}; use std::{collections::BTreeMap, mem::size_of};
use ruma::{ use ruma::{
DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri,
OwnedOneTimeKeyId, OwnedUserId, UInt, UserId,
api::client::{device::Device, error::ErrorKind, filter::FilterDefinition}, api::client::{device::Device, error::ErrorKind, filter::FilterDefinition},
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
events::{AnyToDeviceEvent, StateEventType}, events::{AnyToDeviceEvent, StateEventType},
serde::Raw, serde::Raw,
DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri,
OwnedOneTimeKeyId, OwnedUserId, UInt, UserId,
}; };
use tracing::warn; use tracing::warn;
use crate::{ use crate::{
Error, Result,
api::client_server::TOKEN_LENGTH, api::client_server::TOKEN_LENGTH,
database::KeyValueDatabase, database::KeyValueDatabase,
service::{self, users::clean_signatures}, service::{self, users::clean_signatures},
services, utils, Error, Result, services, utils,
}; };
impl service::users::Data for KeyValueDatabase { impl service::users::Data for KeyValueDatabase {

23
conduit/src/database/mod.rs

@ -2,24 +2,25 @@ pub mod abstraction;
pub mod key_value; pub mod key_value;
use crate::{ use crate::{
Config, Error, PduEvent, Result, SERVICES, Services,
service::{globals, rooms::timeline::PduCount}, service::{globals, rooms::timeline::PduCount},
services, utils, Config, Error, PduEvent, Result, Services, SERVICES, services, utils,
}; };
use abstraction::{KeyValueDatabaseEngine, KvTree}; use abstraction::{KeyValueDatabaseEngine, KvTree};
use base64::{engine::general_purpose, Engine}; use base64::{Engine, engine::general_purpose};
use conduit_config::DatabaseBackend; use conduit_config::DatabaseBackend;
use key_value::media::FilehashMetadata; use key_value::media::FilehashMetadata;
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::{ use ruma::{
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId,
OwnedUserId, RoomId, UserId,
events::{ events::{
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
push_rules::{PushRulesEvent, PushRulesEventContent}, push_rules::{PushRulesEvent, PushRulesEventContent},
room::message::RoomMessageEventContent, room::message::RoomMessageEventContent,
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
}, },
push::Ruleset, push::Ruleset,
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId,
OwnedUserId, RoomId, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@ -446,7 +447,7 @@ impl KeyValueDatabase {
conduit_user conduit_user
); );
return Err(Error::bad_database( return Err(Error::bad_database(
"Cannot reuse an existing database after changing the server name, please delete the old one first." "Cannot reuse an existing database after changing the server name, please delete the old one first.",
)); ));
} }
} }
@ -1000,7 +1001,9 @@ impl KeyValueDatabase {
} }
if services().globals.database_version()? < 17 { if services().globals.database_version()? < 17 {
warn!("Migrating media repository to new format. If you have a lot of media stored, this may take a while, so please be patiant!"); warn!(
"Migrating media repository to new format. If you have a lot of media stored, this may take a while, so please be patiant!"
);
let tree = db._db.open_tree("mediaid_file")?; let tree = db._db.open_tree("mediaid_file")?;
tree.clear().unwrap(); tree.clear().unwrap();
@ -1117,7 +1120,9 @@ impl KeyValueDatabase {
match set_emergency_access() { match set_emergency_access() {
Ok(pwd_set) => { Ok(pwd_set) => {
if pwd_set { if pwd_set {
warn!("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!"); warn!(
"The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!"
);
services().admin.send_message(RoomMessageEventContent::text_plain("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!")); services().admin.send_message(RoomMessageEventContent::text_plain("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!"));
} }
} }
@ -1210,7 +1215,7 @@ impl KeyValueDatabase {
#[tracing::instrument] #[tracing::instrument]
pub async fn start_cleanup_task() { pub async fn start_cleanup_task() {
#[cfg(unix)] #[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{SignalKind, signal};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

2
conduit/src/lib.rs

@ -16,7 +16,7 @@ pub use api::ruma_wrapper::{Ruma, RumaResponse};
pub use conduit_config::Config; pub use conduit_config::Config;
pub use database::KeyValueDatabase; pub use database::KeyValueDatabase;
use ruma::api::{MatrixVersion, SupportedVersions}; use ruma::api::{MatrixVersion, SupportedVersions};
pub use service::{pdu::PduEvent, Services}; pub use service::{Services, pdu::PduEvent};
pub use utils::error::{Error, Result}; pub use utils::error::{Error, Result};
pub static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None); pub static SERVICES: RwLock<Option<&'static Services>> = RwLock::new(None);

32
conduit/src/main.rs

@ -1,41 +1,41 @@
use std::{future::Future, io, net::SocketAddr, sync::atomic, time::Duration}; use std::{future::Future, io, net::SocketAddr, sync::atomic, time::Duration};
use axum::{ use axum::{
Router,
body::Body, body::Body,
extract::{FromRequestParts, MatchedPath}, extract::{FromRequestParts, MatchedPath},
middleware::map_response, middleware::map_response,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
routing::{any, get, on, MethodFilter}, routing::{MethodFilter, any, get, on},
Router,
}; };
use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; use axum_server::{Handle as ServerHandle, bind, bind_rustls, tls_rustls::RustlsConfig};
use conduit::api::{client_server, server_server}; use conduit::api::{client_server, server_server};
use figment::{ use figment::{
Figment,
providers::{Env, Format, Toml}, providers::{Env, Format, Toml},
value::Uncased, value::Uncased,
Figment,
}; };
use http::{ use http::{
header::{self, HeaderName, CONTENT_SECURITY_POLICY},
Method, StatusCode, Uri, Method, StatusCode, Uri,
header::{self, CONTENT_SECURITY_POLICY, HeaderName},
}; };
use opentelemetry::trace::TracerProvider; use opentelemetry::trace::TracerProvider;
use ruma::api::{ use ruma::api::{
IncomingRequest,
client::{ client::{
error::{Error as RumaError, ErrorBody, ErrorKind}, error::{Error as RumaError, ErrorBody, ErrorKind},
uiaa::UiaaResponse, uiaa::UiaaResponse,
}, },
IncomingRequest,
}; };
use tokio::signal; use tokio::signal;
use tower::ServiceBuilder; use tower::ServiceBuilder;
use tower_http::{ use tower_http::{
ServiceBuilderExt as _,
cors::{self, CorsLayer}, cors::{self, CorsLayer},
trace::TraceLayer, trace::TraceLayer,
ServiceBuilderExt as _,
}; };
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
use tracing_subscriber::{prelude::*, EnvFilter}; use tracing_subscriber::{EnvFilter, prelude::*};
pub use conduit::*; // Re-export everything from the library crate pub use conduit::*; // Re-export everything from the library crate
@ -124,7 +124,9 @@ async fn main() {
} }
if was_deprecated { if was_deprecated {
warn!("Read conduit documentation and check your configuration if any new configuration parameters should be adjusted"); warn!(
"Read conduit documentation and check your configuration if any new configuration parameters should be adjusted"
);
} }
let jaeger = if config.allow_jaeger { let jaeger = if config.allow_jaeger {
@ -178,7 +180,9 @@ async fn main() {
let filter_layer = match EnvFilter::try_new(&config.log) { let filter_layer = match EnvFilter::try_new(&config.log) {
Ok(s) => s, Ok(s) => s,
Err(e) => { Err(e) => {
eprintln!("It looks like your config is invalid. The following error occurred while parsing it: {e}"); eprintln!(
"It looks like your config is invalid. The following error occurred while parsing it: {e}"
);
EnvFilter::try_new("warn").unwrap() EnvFilter::try_new("warn").unwrap()
} }
}; };
@ -217,7 +221,11 @@ async fn main() {
/// Adds additional headers to prevent any potential XSS attacks via the media repo /// Adds additional headers to prevent any potential XSS attacks via the media repo
async fn set_csp_header(response: Response) -> impl IntoResponse { async fn set_csp_header(response: Response) -> impl IntoResponse {
( (
[(CONTENT_SECURITY_POLICY, "sandbox; default-src 'none'; script-src 'none'; plugin-types application/pdf; style-src 'unsafe-inline'; object-src 'self';")], response [(
CONTENT_SECURITY_POLICY,
"sandbox; default-src 'none'; script-src 'none'; plugin-types application/pdf; style-src 'unsafe-inline'; object-src 'self';",
)],
response,
) )
} }
@ -665,7 +673,7 @@ fn method_to_filter(method: Method) -> MethodFilter {
#[cfg(unix)] #[cfg(unix)]
#[tracing::instrument(err)] #[tracing::instrument(err)]
fn maximize_fd_limit() -> Result<(), nix::errno::Errno> { fn maximize_fd_limit() -> Result<(), nix::errno::Errno> {
use nix::sys::resource::{getrlimit, setrlimit, Resource}; use nix::sys::resource::{Resource, getrlimit, setrlimit};
let res = Resource::RLIMIT_NOFILE; let res = Resource::RLIMIT_NOFILE;

2
conduit/src/service/account_data/data.rs

@ -2,9 +2,9 @@ use std::collections::HashMap;
use crate::Result; use crate::Result;
use ruma::{ use ruma::{
RoomId, UserId,
events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType},
serde::Raw, serde::Raw,
RoomId, UserId,
}; };
pub trait Data: Send + Sync { pub trait Data: Send + Sync {

2
conduit/src/service/account_data/mod.rs

@ -3,9 +3,9 @@ mod data;
pub use data::Data; pub use data::Data;
use ruma::{ use ruma::{
RoomId, UserId,
events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType},
serde::Raw, serde::Raw,
RoomId, UserId,
}; };
use std::collections::HashMap; use std::collections::HashMap;

22
conduit/src/service/admin/mod.rs

@ -12,9 +12,13 @@ use clap::{Args, Parser};
use image::GenericImageView; use image::GenericImageView;
use regex::Regex; use regex::Regex;
use ruma::{ use ruma::{
EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId,
OwnedServerName, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
api::appservice::Registration, api::appservice::Registration,
events::{ events::{
TimelineEventType,
room::{ room::{
MediaSource,
canonical_alias::RoomCanonicalAliasEventContent, canonical_alias::RoomCanonicalAliasEventContent,
create::RoomCreateEventContent, create::RoomCreateEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent}, guest_access::{GuestAccess, RoomGuestAccessEventContent},
@ -28,28 +32,24 @@ use ruma::{
name::RoomNameEventContent, name::RoomNameEventContent,
power_levels::RoomPowerLevelsEventContent, power_levels::RoomPowerLevelsEventContent,
topic::RoomTopicEventContent, topic::RoomTopicEventContent,
MediaSource,
}, },
TimelineEventType,
}, },
room_version_rules::RoomVersionRules, room_version_rules::RoomVersionRules,
EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId,
OwnedServerName, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
}; };
use serde_json::value::to_raw_value; use serde_json::value::to_raw_value;
use tokio::sync::{mpsc, Mutex, RwLock}; use tokio::sync::{Mutex, RwLock, mpsc};
use crate::{ use crate::{
api::client_server::{self, leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH}, Error, PduEvent, Result,
api::client_server::{self, AUTO_GEN_PASSWORD_LENGTH, leave_all_rooms},
services, services,
utils::{self, HtmlEscape}, utils::{self, HtmlEscape},
Error, PduEvent, Result,
}; };
use super::{ use super::{
media::{ media::{
size, BlockedMediaInfo, FileInfo, MediaListItem, MediaQuery, MediaQueryFileInfo, BlockedMediaInfo, FileInfo, MediaListItem, MediaQuery, MediaQueryFileInfo,
MediaQueryThumbInfo, ServerNameOrUserId, MediaQueryThumbInfo, ServerNameOrUserId, size,
}, },
pdu::PduBuilder, pdu::PduBuilder,
}; };
@ -794,7 +794,7 @@ impl Service {
return Ok(RoomMessageEventContent::text_plain(format!( return Ok(RoomMessageEventContent::text_plain(format!(
"The supplied username is not a valid username: {e}" "The supplied username is not a valid username: {e}"
)) ))
.into()) .into());
} }
}; };
@ -849,7 +849,7 @@ impl Service {
return Ok(RoomMessageEventContent::text_plain(format!( return Ok(RoomMessageEventContent::text_plain(format!(
"The supplied username is not a valid username: {e}" "The supplied username is not a valid username: {e}"
)) ))
.into()) .into());
} }
}; };

4
conduit/src/service/appservice/mod.rs

@ -7,12 +7,12 @@ pub use data::Data;
use futures_util::Future; use futures_util::Future;
use regex::RegexSet; use regex::RegexSet;
use ruma::{ use ruma::{
api::appservice::{Namespace, Registration},
RoomAliasId, RoomId, UserId, RoomAliasId, RoomId, UserId,
api::appservice::{Namespace, Registration},
}; };
use tokio::sync::RwLock; use tokio::sync::RwLock;
use crate::{services, Result}; use crate::{Result, services};
/// Compiled regular expressions for a namespace. /// Compiled regular expressions for a namespace.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

4
conduit/src/service/globals/data.rs

@ -3,13 +3,13 @@ use std::{
time::{Duration, SystemTime}, time::{Duration, SystemTime},
}; };
use crate::{services, Result}; use crate::{Result, services};
use async_trait::async_trait; use async_trait::async_trait;
use ruma::{ use ruma::{
DeviceId, MilliSecondsSinceUnixEpoch, ServerName, UserId,
api::federation::discovery::{OldVerifyKey, ServerSigningKeys, VerifyKey}, api::federation::discovery::{OldVerifyKey, ServerSigningKeys, VerifyKey},
serde::Base64, serde::Base64,
signatures::Ed25519KeyPair, signatures::Ed25519KeyPair,
DeviceId, MilliSecondsSinceUnixEpoch, ServerName, UserId,
}; };
use serde::Deserialize; use serde::Deserialize;

14
conduit/src/service/globals/mod.rs

@ -1,21 +1,21 @@
mod data; mod data;
pub use data::{Data, SigningKeys}; pub use data::{Data, SigningKeys};
use ruma::{ use ruma::{
room_version_rules::RoomVersionRules, serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId, OwnedRoomId,
OwnedEventId, OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, OwnedServerName, OwnedUserId, RoomAliasId, room_version_rules::RoomVersionRules, serde::Base64,
}; };
use crate::api::server_server::DestinationResponse; use crate::api::server_server::DestinationResponse;
use crate::{services, Config, Error, Result}; use crate::{Config, Error, Result, services};
use conduit_config::{DirectoryStructure, MediaBackendConfig, TurnConfig}; use conduit_config::{DirectoryStructure, MediaBackendConfig, TurnConfig};
use futures_util::FutureExt; use futures_util::FutureExt;
use hickory_resolver::TokioResolver; use hickory_resolver::TokioResolver;
use hyper_util::client::legacy::connect::dns::{GaiResolver, Name as HyperName}; use hyper_util::client::legacy::connect::dns::{GaiResolver, Name as HyperName};
use reqwest::dns::{Addrs, Name, Resolve, Resolving}; use reqwest::dns::{Addrs, Name, Resolve, Resolving};
use ruma::{ use ruma::{
api::{client::sync::sync_events, federation::discovery::ServerSigningKeys},
DeviceId, RoomVersionId, ServerName, UserId, DeviceId, RoomVersionId, ServerName, UserId,
api::{client::sync::sync_events, federation::discovery::ServerSigningKeys},
}; };
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
@ -27,12 +27,12 @@ use std::{
path::PathBuf, path::PathBuf,
str::FromStr, str::FromStr,
sync::{ sync::{
atomic::{self, AtomicBool},
Arc, RwLock as StdRwLock, Arc, RwLock as StdRwLock,
atomic::{self, AtomicBool},
}, },
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use tokio::sync::{broadcast, watch::Receiver, Mutex, RwLock, Semaphore}; use tokio::sync::{Mutex, RwLock, Semaphore, broadcast, watch::Receiver};
use tower_service::Service as TowerService; use tower_service::Service as TowerService;
use tracing::{error, info}; use tracing::{error, info};
@ -86,7 +86,7 @@ impl RotationHandler {
Self(s) Self(s)
} }
pub fn watch(&self) -> impl Future<Output = ()> { pub fn watch(&self) -> impl Future<Output = ()> + use<> {
let mut r = self.0.subscribe(); let mut r = self.0.subscribe();
async move { async move {

4
conduit/src/service/key_backups/data.rs

@ -2,9 +2,9 @@ use std::collections::BTreeMap;
use crate::Result; use crate::Result;
use ruma::{ use ruma::{
OwnedRoomId, RoomId, UserId,
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
serde::Raw, serde::Raw,
OwnedRoomId, RoomId, UserId,
}; };
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
@ -26,7 +26,7 @@ pub trait Data: Send + Sync {
fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>>; fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>>;
fn get_latest_backup(&self, user_id: &UserId) fn get_latest_backup(&self, user_id: &UserId)
-> Result<Option<(String, Raw<BackupAlgorithm>)>>; -> Result<Option<(String, Raw<BackupAlgorithm>)>>;
fn get_backup(&self, user_id: &UserId, version: &str) -> Result<Option<Raw<BackupAlgorithm>>>; fn get_backup(&self, user_id: &UserId, version: &str) -> Result<Option<Raw<BackupAlgorithm>>>;

2
conduit/src/service/key_backups/mod.rs

@ -3,9 +3,9 @@ pub use data::Data;
use crate::Result; use crate::Result;
use ruma::{ use ruma::{
OwnedRoomId, RoomId, UserId,
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
serde::Raw, serde::Raw,
OwnedRoomId, RoomId, UserId,
}; };
use std::collections::BTreeMap; use std::collections::BTreeMap;

2
conduit/src/service/media/data.rs

@ -1,6 +1,6 @@
use conduit_config::MediaRetentionConfig; use conduit_config::MediaRetentionConfig;
use ruma::{OwnedServerName, ServerName, UserId}; use ruma::{OwnedServerName, ServerName, UserId};
use sha2::{digest::Output, Sha256}; use sha2::{Sha256, digest::Output};
use crate::{Error, Result}; use crate::{Error, Result};

8
conduit/src/service/media/mod.rs

@ -5,18 +5,18 @@ use conduit_config::{DirectoryStructure, MediaBackendConfig, S3MediaBackend};
pub use data::Data; pub use data::Data;
use http::StatusCode; use http::StatusCode;
use ruma::{ use ruma::{
OwnedServerName, ServerName, UserId,
api::client::{error::ErrorKind, media::is_safe_inline_content_type}, api::client::{error::ErrorKind, media::is_safe_inline_content_type},
http_headers::{ContentDisposition, ContentDispositionType}, http_headers::{ContentDisposition, ContentDispositionType},
OwnedServerName, ServerName, UserId,
}; };
use rusty_s3::{ use rusty_s3::{
actions::{DeleteObjectsResponse, ObjectIdentifier},
S3Action, S3Action,
actions::{DeleteObjectsResponse, ObjectIdentifier},
}; };
use sha2::{digest::Output, Digest, Sha256}; use sha2::{Digest, Sha256, digest::Output};
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use crate::{services, utils, Error, Result}; use crate::{Error, Result, services, utils};
use image::imageops::FilterType; use image::imageops::FilterType;
pub struct DbFileMeta { pub struct DbFileMeta {

2
conduit/src/service/mod.rs

@ -4,7 +4,7 @@ use std::{
}; };
use lru_cache::LruCache; use lru_cache::LruCache;
use tokio::sync::{broadcast, Mutex}; use tokio::sync::{Mutex, broadcast};
use crate::{Config, Result}; use crate::{Config, Result};
use tokio::sync::RwLock; use tokio::sync::RwLock;

11
conduit/src/service/pdu.rs

@ -1,23 +1,24 @@
use crate::Error; use crate::Error;
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
api::client::error::ErrorKind, api::client::error::ErrorKind,
canonical_json::redact_content_in_place, canonical_json::redact_content_in_place,
events::{ events::{
room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent},
space::child::HierarchySpaceChildEvent,
AnyInitialStateEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, AnyInitialStateEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
StateEvent, TimelineEventType, StateEvent, TimelineEventType,
room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent},
space::child::HierarchySpaceChildEvent,
}, },
room_version_rules::{RedactionRules, RoomVersionRules}, room_version_rules::{RedactionRules, RoomVersionRules},
serde::{JsonCastable, Raw}, serde::{JsonCastable, Raw},
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, state_res,
OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{ use serde_json::{
json, json,
value::{to_raw_value, RawValue as RawJsonValue}, value::{RawValue as RawJsonValue, to_raw_value},
}; };
use std::{borrow::Cow, cmp::Ordering, collections::BTreeMap, sync::Arc}; use std::{borrow::Cow, cmp::Ordering, collections::BTreeMap, sync::Arc};
use tracing::warn; use tracing::warn;

4
conduit/src/service/pusher/data.rs

@ -1,7 +1,7 @@
use crate::Result; use crate::Result;
use ruma::{ use ruma::{
api::client::push::{set_pusher, Pusher},
UserId, UserId,
api::client::push::{Pusher, set_pusher},
}; };
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
@ -12,5 +12,5 @@ pub trait Data: Send + Sync {
fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>>; fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>>;
fn get_pushkeys<'a>(&'a self, sender: &UserId) fn get_pushkeys<'a>(&'a self, sender: &UserId)
-> Box<dyn Iterator<Item = Result<String>> + 'a>; -> Box<dyn Iterator<Item = Result<String>> + 'a>;
} }

9
conduit/src/service/pusher/mod.rs

@ -2,21 +2,22 @@ mod data;
pub use data::Data; pub use data::Data;
use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx}; use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx};
use crate::{services, Error, PduEvent, Result, SUPPORTED_VERSIONS}; use crate::{Error, PduEvent, Result, SUPPORTED_VERSIONS, services};
use bytes::BytesMut; use bytes::BytesMut;
use ruma::{ use ruma::{
RoomId, UInt, UserId,
api::{ api::{
client::push::{set_pusher, Pusher, PusherKind}, IncomingResponse, OutgoingRequest, SendAccessToken,
client::push::{Pusher, PusherKind, set_pusher},
push_gateway::send_event_notification::{ push_gateway::send_event_notification::{
self, self,
v1::{Device, Notification, NotificationCounts, NotificationPriority}, v1::{Device, Notification, NotificationCounts, NotificationPriority},
}, },
IncomingResponse, OutgoingRequest, SendAccessToken,
}, },
events::TimelineEventType, events::TimelineEventType,
push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak}, push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak},
serde::Raw, serde::Raw,
uint, RoomId, UInt, UserId, uint,
}; };
use std::{fmt::Debug, mem}; use std::{fmt::Debug, mem};

6
conduit/src/service/rooms/alias/mod.rs

@ -4,15 +4,15 @@ pub use data::Data;
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use tracing::warn; use tracing::warn;
use crate::{services, Error, Result}; use crate::{Error, Result, services};
use ruma::{ use ruma::{
OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId,
api::{ api::{
appservice, appservice,
client::{alias::get_alias, error::ErrorKind}, client::{alias::get_alias, error::ErrorKind},
federation, federation,
}, },
events::StateEventType, events::StateEventType,
OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId,
}; };
pub struct Service { pub struct Service {
@ -149,7 +149,7 @@ impl Service {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::NotFound, ErrorKind::NotFound,
"Room with alias not found.", "Room with alias not found.",
)) ));
} }
}; };

2
conduit/src/service/rooms/auth_chain/data.rs

@ -7,5 +7,5 @@ pub trait Data: Send + Sync {
shorteventid: &[u64], shorteventid: &[u64],
) -> Result<Option<Arc<HashSet<u64>>>>; ) -> Result<Option<Arc<HashSet<u64>>>>;
fn cache_auth_chain(&self, shorteventid: Vec<u64>, auth_chain: Arc<HashSet<u64>>) fn cache_auth_chain(&self, shorteventid: Vec<u64>, auth_chain: Arc<HashSet<u64>>)
-> Result<()>; -> Result<()>;
} }

6
conduit/src/service/rooms/auth_chain/mod.rs

@ -5,10 +5,10 @@ use std::{
}; };
pub use data::Data; pub use data::Data;
use ruma::{api::client::error::ErrorKind, state_res::StateMap, EventId, RoomId}; use ruma::{EventId, RoomId, api::client::error::ErrorKind, state_res::StateMap};
use tracing::{debug, error, warn}; use tracing::{debug, error, warn};
use crate::{services, Error, Result}; use crate::{Error, Result, services};
pub struct Service { pub struct Service {
pub db: &'static dyn Data, pub db: &'static dyn Data,
@ -29,7 +29,7 @@ impl Service {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
starting_events: Vec<Arc<EventId>>, starting_events: Vec<Arc<EventId>>,
) -> Result<impl Iterator<Item = Arc<EventId>> + 'a> { ) -> Result<impl Iterator<Item = Arc<EventId>> + 'a + use<'a>> {
const NUM_BUCKETS: usize = 50; const NUM_BUCKETS: usize = 50;
let mut buckets = vec![BTreeSet::new(); NUM_BUCKETS]; let mut buckets = vec![BTreeSet::new(); NUM_BUCKETS];

2
conduit/src/service/rooms/edus/presence/data.rs

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::Result; use crate::Result;
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Adds a presence event which will be saved until a new event replaces it. /// Adds a presence event which will be saved until a new event replaces it.

2
conduit/src/service/rooms/edus/presence/mod.rs

@ -2,7 +2,7 @@ mod data;
use std::collections::HashMap; use std::collections::HashMap;
pub use data::Data; pub use data::Data;
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent};
use crate::Result; use crate::Result;

2
conduit/src/service/rooms/edus/read_receipt/data.rs

@ -1,5 +1,5 @@
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw};
pub trait Data: Send + Sync { pub trait Data: Send + Sync {
/// Replaces the previous read receipt. /// Replaces the previous read receipt.

6
conduit/src/service/rooms/edus/read_receipt/mod.rs

@ -3,7 +3,7 @@ mod data;
pub use data::Data; pub use data::Data;
use crate::Result; use crate::Result;
use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; use ruma::{OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw};
pub struct Service { pub struct Service {
pub db: &'static dyn Data, pub db: &'static dyn Data,
@ -32,7 +32,9 @@ impl Service {
u64, u64,
Raw<ruma::events::AnySyncEphemeralRoomEvent>, Raw<ruma::events::AnySyncEphemeralRoomEvent>,
)>, )>,
> + 'a { >
+ 'a
+ use<'a> {
self.db.readreceipts_since(room_id, since) self.db.readreceipts_since(room_id, since)
} }

6
conduit/src/service/rooms/edus/typing/mod.rs

@ -1,8 +1,8 @@
use ruma::{events::SyncEphemeralRoomEvent, OwnedRoomId, OwnedUserId, RoomId, UserId}; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId, events::SyncEphemeralRoomEvent};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use tokio::sync::{broadcast, RwLock}; use tokio::sync::{RwLock, broadcast};
use crate::{services, utils, Result}; use crate::{Result, services, utils};
pub struct Service { pub struct Service {
pub typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout pub typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout

38
conduit/src/service/rooms/event_handler/mod.rs

@ -2,15 +2,17 @@
type AsyncRecursiveType<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>; type AsyncRecursiveType<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
use std::{ use std::{
collections::{hash_map, BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet, hash_map},
pin::Pin, pin::Pin,
sync::Arc, sync::Arc,
time::{Duration, Instant, SystemTime}, time::{Duration, Instant, SystemTime},
}; };
use futures_util::{stream::FuturesUnordered, Future, StreamExt}; use futures_util::{Future, StreamExt, stream::FuturesUnordered};
use globals::SigningKeys; use globals::SigningKeys;
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName,
OwnedServerSigningKeyId, RoomId, ServerName,
api::{ api::{
client::error::ErrorKind, client::error::ErrorKind,
federation::{ federation::{
@ -24,24 +26,23 @@ use ruma::{
}, },
}, },
events::{ events::{
StateEventType, TimelineEventType,
room::{ room::{
create::RoomCreateEventContent, redaction::RoomRedactionEventContent, create::RoomCreateEventContent, redaction::RoomRedactionEventContent,
server_acl::RoomServerAclEventContent, server_acl::RoomServerAclEventContent,
}, },
StateEventType, TimelineEventType,
}, },
int, int,
room_version_rules::{AuthorizationRules, RoomVersionRules, StateResolutionV2Rules}, room_version_rules::{AuthorizationRules, RoomVersionRules, StateResolutionV2Rules},
serde::Base64, serde::Base64,
state_res::{self, StateMap}, state_res::{self, StateMap},
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, uint,
OwnedServerName, OwnedServerSigningKeyId, RoomId, ServerName,
}; };
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use tokio::sync::{RwLock, RwLockWriteGuard, Semaphore}; use tokio::sync::{RwLock, RwLockWriteGuard, Semaphore};
use tracing::{debug, error, info, trace, warn}; use tracing::{debug, error, info, trace, warn};
use crate::{service::*, services, Error, PduEvent, Result}; use crate::{Error, PduEvent, Result, service::*, services};
use super::state_compressor::CompressedStateEvent; use super::state_compressor::CompressedStateEvent;
@ -371,7 +372,7 @@ impl Service {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Redaction failed", "Redaction failed",
)) ));
} }
}; };
@ -718,7 +719,10 @@ impl Service {
.collect::<Result<_>>()?, .collect::<Result<_>>()?,
), ),
Err(e) => { Err(e) => {
warn!("State resolution on prev events failed, either an event could not be found or deserialization: {}", e); warn!(
"State resolution on prev events failed, either an event could not be found or deserialization: {}",
e
);
None None
} }
} }
@ -773,9 +777,11 @@ impl Service {
hash_map::Entry::Vacant(v) => { hash_map::Entry::Vacant(v) => {
v.insert(Arc::from(&*pdu.event_id)); v.insert(Arc::from(&*pdu.event_id));
} }
hash_map::Entry::Occupied(_) => return Err( hash_map::Entry::Occupied(_) => {
Error::bad_database("State event's type and state_key combination exists multiple times."), return Err(Error::bad_database(
), "State event's type and state_key combination exists multiple times.",
));
}
} }
} }
@ -1100,7 +1106,9 @@ impl Service {
) { ) {
Ok(new_state) => new_state, Ok(new_state) => new_state,
Err(_) => { Err(_) => {
return Err(Error::bad_database("State resolution failed, either an event could not be found or deserialization")); return Err(Error::bad_database(
"State resolution failed, either an event could not be found or deserialization",
));
} }
}; };
@ -1241,8 +1249,10 @@ impl Service {
}; };
if calculated_event_id != *next_id { if calculated_event_id != *next_id {
warn!("Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}", warn!(
next_id, calculated_event_id, &res.pdu); "Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}",
next_id, calculated_event_id, &res.pdu
);
} }
if let Some(auth_events) = if let Some(auth_events) =

30
conduit/src/service/rooms/helpers/mod.rs

@ -1,38 +1,40 @@
use std::{ use std::{
collections::{hash_map::Entry, BTreeMap, HashMap}, collections::{BTreeMap, HashMap, hash_map::Entry},
sync::Arc, sync::Arc,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedServerName, RoomId, RoomVersionId, UserId,
api::{ api::{
client::{ client::{
error::ErrorKind, error::ErrorKind,
membership::{join_room_by_id, ThirdPartySigned}, membership::{ThirdPartySigned, join_room_by_id},
}, },
federation, federation,
}, },
events::{ events::{
TimelineEventType,
room::{ room::{
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
member::{MembershipState, RoomMemberEventContent}, member::{MembershipState, RoomMemberEventContent},
}, },
TimelineEventType,
}, },
room_version_rules::RoomVersionRules, room_version_rules::RoomVersionRules,
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, state_res,
OwnedEventId, OwnedServerName, RoomId, RoomVersionId, UserId,
}; };
use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
use crate::{ use crate::{
Error, PduEvent, Result,
service::{ service::{
globals::SigningKeys, globals::SigningKeys,
pdu::{gen_event_id_canonical_json, PduBuilder}, pdu::{PduBuilder, gen_event_id_canonical_json},
}, },
services, utils, Error, PduEvent, Result, services, utils,
}; };
pub struct Service; pub struct Service;
@ -120,7 +122,9 @@ impl Service {
info!("send_join finished"); info!("send_join finished");
if let Some(signed_raw) = &send_join_response.room_state.event { if let Some(signed_raw) = &send_join_response.room_state.event {
info!("There is a signed event. This room is probably using restricted joins. Adding signature to our event"); info!(
"There is a signed event. This room is probably using restricted joins. Adding signature to our event"
);
let (signed_event_id, signed_value) = let (signed_event_id, signed_value) =
match gen_event_id_canonical_json(signed_raw, &room_version_rules) { match gen_event_id_canonical_json(signed_raw, &room_version_rules) {
Ok(t) => t, Ok(t) => t,
@ -162,8 +166,8 @@ impl Service {
} }
Err(e) => { Err(e) => {
warn!( warn!(
"Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}: {e:?}", "Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}: {e:?}",
); );
} }
} }
} }
@ -426,8 +430,8 @@ impl Service {
.any(|s| *s != services().globals.server_name()) .any(|s| *s != services().globals.server_name())
{ {
info!( info!(
"We couldn't do the join locally, maybe federation can help to satisfy the restricted join requirements" "We couldn't do the join locally, maybe federation can help to satisfy the restricted join requirements"
); );
let (make_join_response, remote_server) = let (make_join_response, remote_server) =
make_join_request(sender_user, room_id, servers).await?; make_join_request(sender_user, room_id, servers).await?;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save