Browse Source

chore: migrate to rust 2024 edition

rate-limiting
Matthias Ahouansou 1 month 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]
# See also `rust-toolchain.toml`
edition = "2021"
edition = "2024"
homepage = "https://conduit.rs"
repository = "https://gitlab.com/famedly/conduit"
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)]
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,
#[error("Invalid S3 config")]

6
conduit-config/src/lib.rs

@ -8,10 +8,10 @@ use std::{
use bytesize::ByteSize;
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::{
de::{Error as _, IgnoredAny},
Deserialize,
de::{Error as _, IgnoredAny},
};
use url::Url;
@ -728,7 +728,7 @@ impl std::fmt::Display for Config {
let mut msg: String = "Active config values:\n\n".to_owned();
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}")

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 ruma::api::{appservice::Registration, IncomingResponse, OutgoingRequest, SendAccessToken};
use ruma::api::{IncomingResponse, OutgoingRequest, SendAccessToken, appservice::Registration};
use std::{fmt::Debug, mem, time::Duration};
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 crate::{api::client_server, services, utils, Error, Result, Ruma};
use crate::{Error, Result, Ruma, api::client_server, services, utils};
use ruma::{
UserId,
api::client::{
account::{
change_password, deactivate, get_3pids, get_username_availability,
ThirdPartyIdRemovalStatus, change_password, deactivate, get_3pids,
get_username_availability,
register::{self, LoginType},
request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn,
whoami, ThirdPartyIdRemovalStatus,
whoami,
},
error::ErrorKind,
uiaa::{AuthFlow, AuthType, UiaaInfo},
},
events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType},
push, UserId,
events::{GlobalAccountDataEventType, room::message::RoomMessageEventContent},
push,
};
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::{
alias::{create_alias, delete_alias, get_alias},
error::ErrorKind,

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

@ -5,7 +5,7 @@ use ruma::api::{
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`
///

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::{
backup::{
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::{
self,
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::{
api::client::{
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::{
api::client::{context::get_context, error::ErrorKind, filter::LazyLoadOptions},
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::{
device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
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::{
ServerName, UInt,
api::{
client::{
directory::{
@ -13,6 +14,7 @@ use ruma::{
},
directory::{Filter, PublicRoomsChunk, RoomNetwork},
events::{
StateEventType,
room::{
avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent,
@ -22,9 +24,7 @@ use ruma::{
join_rules::RoomJoinRulesEventContent,
topic::RoomTopicEventContent,
},
StateEventType,
},
ServerName, UInt,
};
use tracing::{error, info, warn};
@ -169,7 +169,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"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::{
error::ErrorKind,
filter::{create_filter, get_filter},

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

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

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

@ -3,9 +3,10 @@
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 ruma::{
ServerName, UInt,
api::{
client::{
authenticated_media::{
@ -18,7 +19,6 @@ use ruma::{
},
http_headers::{ContentDisposition, ContentDispositionType},
media::Method,
ServerName, UInt,
};
const MXC_LENGTH: usize = 32;

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

@ -1,4 +1,5 @@
use ruma::{
OwnedServerName, RoomId, UserId,
api::{
client::{
error::ErrorKind,
@ -11,17 +12,16 @@ use ruma::{
},
federation::{
self,
membership::{create_invite, RawStrippedState},
membership::{RawStrippedState, create_invite},
},
},
events::{
StateEventType, TimelineEventType,
room::{
join_rules::JoinRule,
member::{MembershipState, RoomMemberEventContent},
},
StateEventType, TimelineEventType,
},
OwnedServerName, RoomId, UserId,
};
use serde_json::value::to_raw_value;
use std::{
@ -32,8 +32,9 @@ use tokio::sync::RwLock;
use tracing::{error, info, warn};
use crate::{
service::pdu::{gen_event_id_canonical_json, PduBuilder},
services, utils, Error, PduEvent, Result, Ruma,
Error, PduEvent, Result, Ruma,
service::pdu::{PduBuilder, gen_event_id_canonical_json},
services, utils,
};
/// # `POST /_matrix/client/r0/rooms/{roomId}/join`
@ -253,7 +254,7 @@ pub async fn knock_room_route(
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"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 {
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(

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

@ -1,6 +1,7 @@
use crate::{
Error, Result, Ruma,
service::{pdu::PduBuilder, rooms::timeline::PduCount},
services, utils, Error, Result, Ruma,
services, utils,
};
use ruma::{
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 crate::{services, Result, Ruma};
use crate::{Result, Ruma, services};
/// # `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::{
error::ErrorKind,
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::{
api::{
client::{
@ -9,7 +9,7 @@ use ruma::{
},
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 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::{
api::client::{
error::ErrorKind,
@ -8,7 +8,7 @@ use ruma::{
set_pushrule_enabled,
},
},
events::{push_rules::PushRulesEvent, GlobalAccountDataEventType},
events::{GlobalAccountDataEventType, push_rules::PushRulesEvent},
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::{
MilliSecondsSinceUnixEpoch,
api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt},
events::{
receipt::{ReceiptThread, ReceiptType},
RoomAccountDataEventType,
receipt::{ReceiptThread, ReceiptType},
},
MilliSecondsSinceUnixEpoch,
};
use std::collections::BTreeMap;
@ -55,7 +55,7 @@ pub async fn set_read_marker_route(
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Read receipt is in backfilled timeline",
))
));
}
PduCount::Normal(c) => c,
};
@ -165,7 +165,7 @@ pub async fn create_receipt_route(
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Read receipt is in backfilled timeline",
))
));
}
PduCount::Normal(c) => c,
};

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

@ -1,9 +1,9 @@
use std::sync::Arc;
use crate::{service::pdu::PduBuilder, services, Result, Ruma};
use crate::{Result, Ruma, service::pdu::PduBuilder, services};
use ruma::{
api::client::redact::redact_event,
events::{room::redaction::RoomRedactionEventContent, TimelineEventType},
events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
};
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,
};
use crate::{services, Result, Ruma};
use crate::{Result, Ruma, services};
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
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::{
api::client::{error::ErrorKind, room::report_content},
events::room::message,
@ -20,7 +20,7 @@ pub async fn report_event_route(
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Invalid Event ID",
))
));
}
};

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

@ -1,12 +1,15 @@
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::{
CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId,
RoomVersionId,
api::client::{
error::ErrorKind,
room::{self, aliases, create_room, get_room_event, upgrade_room},
},
events::{
StateEventType, TimelineEventType,
room::{
canonical_alias::RoomCanonicalAliasEventContent,
create::RoomCreateEventContent,
@ -19,12 +22,9 @@ use ruma::{
tombstone::RoomTombstoneEventContent,
topic::RoomTopicEventContent,
},
StateEventType, TimelineEventType,
},
int,
serde::JsonObject,
CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId,
RoomVersionId,
};
use serde::Deserialize;
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::{
error::ErrorKind,
search::search_events::{
@ -63,7 +63,7 @@ pub async fn search_events_route(
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Invalid next_batch token.",
))
));
}
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 crate::{services, utils, Error, Result, Ruma};
use crate::{Error, Result, Ruma, services, utils};
use ruma::{
UserId,
api::client::{
error::ErrorKind,
session::{get_login_types, login, logout, logout_all},
uiaa::UserIdentifier,
},
UserId,
};
use serde::Deserialize;
use tracing::{info, warn};

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

@ -1,9 +1,9 @@
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::{
api::client::{error::ErrorKind, space::get_hierarchy},
UInt,
api::client::{error::ErrorKind, space::get_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 crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaResponse};
use crate::{Error, Result, Ruma, RumaResponse, service::pdu::PduBuilder, services};
use ruma::{
EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
api::client::{
error::ErrorKind,
state::{
@ -10,10 +11,9 @@ use ruma::{
},
},
events::{
room::canonical_alias::RoomCanonicalAliasEventContent, AnyStateEventContent, StateEventType,
AnyStateEventContent, StateEventType, room::canonical_alias::RoomCanonicalAliasEventContent,
},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
};
use tracing::warn;

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

@ -1,31 +1,32 @@
use crate::{
Error, PduEvent, Result, Ruma, RumaResponse,
service::{pdu::EventHash, rooms::timeline::PduCount},
services, utils, Error, PduEvent, Result, Ruma, RumaResponse,
services, utils,
};
use ruma::{
DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId,
api::client::{
filter::{FilterDefinition, LazyLoadOptions},
sync::sync_events::{
self,
self, DeviceLists, UnreadNotificationsCount,
v3::{
Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom,
KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms,
State, StateEvents, Timeline, ToDevice,
},
DeviceLists, UnreadNotificationsCount,
},
uiaa::UiaaResponse,
},
events::{
room::member::{MembershipState, RoomMemberEventContent},
StateEventType, TimelineEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
serde::Raw,
uint, DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId,
uint,
};
use std::{
collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet},
collections::{BTreeMap, BTreeSet, HashMap, HashSet, hash_map::Entry},
sync::Arc,
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::{
api::client::tag::{create_tag, delete_tag, get_tags},
events::{
tag::{TagEvent, TagEventContent},
RoomAccountDataEventType,
tag::{TagEvent, TagEventContent},
},
};
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 crate::{services, Error, Result, Ruma};
use crate::{Error, Result, Ruma, services};
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
pub async fn get_threads_route(

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

@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use crate::{services, Error, Result, Ruma};
use crate::{Error, Result, Ruma, services};
use ruma::{
api::{
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};
/// # `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::{
api::client::user_directory::search_users,
events::{
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
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 base64::{engine::general_purpose, Engine as _};
use crate::{Error, Result, Ruma, services};
use base64::{Engine as _, engine::general_purpose};
use conduit_config::TurnAuth;
use hmac::{Hmac, Mac};
use ruma::{
api::client::{error::ErrorKind, voip::get_turn_server_info},
SecondsSinceUnixEpoch,
api::client::{error::ErrorKind, voip::get_turn_server_info},
};
use sha1::Sha1;
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 crate::{services, Result, Ruma};
use crate::{Result, Ruma, services};
/// # `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 axum::{
RequestPartsExt,
body::Body,
extract::{FromRequest, Path},
response::{IntoResponse, Response},
RequestPartsExt,
};
use axum_extra::{
headers::{authorization::Bearer, Authorization},
typed_header::TypedHeaderRejectionReason,
TypedHeader,
headers::{Authorization, authorization::Bearer},
typed_header::TypedHeaderRejectionReason,
};
use bytes::{BufMut, BytesMut};
use http::{Request, StatusCode};
use ruma::{
CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId,
api::{
client::error::ErrorKind, federation::authentication::XMatrix, AuthScheme, IncomingRequest,
OutgoingResponse,
AuthScheme, IncomingRequest, OutgoingResponse, client::error::ErrorKind,
federation::authentication::XMatrix,
},
CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId,
};
use serde::Deserialize;
use tracing::{debug, error, warn};
use super::{Ruma, RumaResponse};
use crate::{service::appservice::RegistrationInfo, services, Error, Result};
use crate::{Error, Result, service::appservice::RegistrationInfo, services};
enum Token {
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::{
api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName,
OwnedUserId,
CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId,
api::client::uiaa::UiaaResponse,
};
use std::ops::Deref;

28
conduit/src/api/server_server.rs

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

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

@ -1,5 +1,5 @@
use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree};
use crate::{utils, Result};
use super::{KeyValueDatabaseEngine, KvTree, watchers::Watchers};
use crate::{Result, utils};
use conduit_config::Config;
use std::{
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 conduit_config::Config;
use parking_lot::{Mutex, MutexGuard};

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

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

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

@ -1,13 +1,13 @@
use std::collections::HashMap;
use ruma::{
RoomId, UserId,
api::client::error::ErrorKind,
events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType},
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 {
/// 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 crate::{database::KeyValueDatabase, service, utils, Error, Result};
use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::appservice::Data for KeyValueDatabase {
/// 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 async_trait::async_trait;
use futures_util::{stream::FuturesUnordered, StreamExt};
use futures_util::{StreamExt, stream::FuturesUnordered};
use lru_cache::LruCache;
use ruma::{
DeviceId, ServerName, UserId,
api::federation::discovery::{OldVerifyKey, ServerSigningKeys},
signatures::Ed25519KeyPair,
DeviceId, ServerName, UserId,
};
use crate::{
Error, Result,
database::KeyValueDatabase,
service::{self, globals::SigningKeys},
services, utils, Error, Result,
services, utils,
};
pub const COUNTER: &[u8] = b"c";

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

@ -1,15 +1,15 @@
use std::collections::BTreeMap;
use ruma::{
OwnedRoomId, RoomId, UserId,
api::client::{
backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
error::ErrorKind,
},
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 {
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 conduit_config::{MediaRetentionConfig, MediaRetentionScope};
use ruma::{api::client::error::ErrorKind, OwnedServerName, ServerName, UserId};
use sha2::{digest::Output, Sha256};
use ruma::{OwnedServerName, ServerName, UserId, api::client::error::ErrorKind};
use sha2::{Sha256, digest::Output};
use tracing::error;
use crate::{
Error, Result,
database::KeyValueDatabase,
service::{
self,
@ -15,7 +16,7 @@ use crate::{
MediaQueryFileInfo, MediaQueryThumbInfo, MediaType, ServerNameOrUserId,
},
},
services, utils, Error, Result,
services, utils,
};
impl service::media::Data for KeyValueDatabase {
@ -664,9 +665,9 @@ impl service::media::Data for KeyValueDatabase {
}
} else {
error!(
"Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest)
);
"Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest)
);
errors.push(Error::BadDatabase(
"Invalid format of key in filehash_servername_mediaid",
));
@ -675,9 +676,9 @@ impl service::media::Data for KeyValueDatabase {
let thumbnail_id_error = || {
error!(
"Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest)
);
"Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}",
hex::encode(&metadata.sha256_digest)
);
Error::BadDatabase("Invalid format of value in filehash_thumbnailid")
};
@ -732,7 +733,9 @@ impl service::media::Data for KeyValueDatabase {
}
Ok(None) => (),
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);
continue;
}
@ -748,7 +751,9 @@ impl service::media::Data for KeyValueDatabase {
maybe_remove_remaining_metadata(&metadata, &mut errors);
}
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);
}
}

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

@ -1,9 +1,9 @@
use ruma::{
api::client::push::{set_pusher, Pusher},
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 {
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::{
api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId,
UserId,
OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, 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 {
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 crate::{database::KeyValueDatabase, service, utils, Result};
use crate::{Result, database::KeyValueDatabase, service, utils};
impl service::rooms::auth_chain::Data for KeyValueDatabase {
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 crate::{database::KeyValueDatabase, service, utils, Error, Result};
use crate::{Error, Result, database::KeyValueDatabase, service, utils};
impl service::rooms::directory::Data for KeyValueDatabase {
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 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 {
fn update_presence(

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

@ -1,8 +1,8 @@
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 {
fn readreceipt_update(

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

@ -1,6 +1,6 @@
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 {
fn lazy_load_was_sent_before(

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

@ -1,6 +1,6 @@
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 {
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 crate::{database::KeyValueDatabase, service, Error, PduEvent, Result};
use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service};
impl service::rooms::outlier::Data for KeyValueDatabase {
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 crate::{
Error, PduEvent, Result,
database::KeyValueDatabase,
service::{self, rooms::timeline::PduCount},
services, utils, Error, PduEvent, Result,
services, utils,
};
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 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
///

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

@ -1,8 +1,8 @@
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 {
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 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 {
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 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 ruma::{events::StateEventType, EventId, RoomId};
use ruma::{EventId, RoomId, events::StateEventType};
#[async_trait]
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 ruma::{
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
};
use crate::{
database::{abstraction::KvTree, KeyValueDatabase},
Error, Result,
database::{KeyValueDatabase, abstraction::KvTree},
service::{self, appservice::RegistrationInfo},
services, utils, Error, Result,
services, utils,
};
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 crate::{
Error, Result,
database::KeyValueDatabase,
service::{self, rooms::state_compressor::data::StateDiff},
utils, Error, Result,
utils,
};
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 {
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 ruma::{
api::client::error::ErrorKind, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId,
CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, api::client::error::ErrorKind,
};
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;
@ -346,11 +346,7 @@ fn count_to_id(
pdu_id.extend_from_slice(&0_u64.to_be_bytes());
let num = u64::MAX - x;
if subtract {
if num > 0 {
num - offset
} else {
num
}
if num > 0 { num - offset } else { num }
} else {
num + offset
}

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

@ -1,6 +1,6 @@
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};
@ -115,7 +115,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
let roomid_index = key
.iter()
.enumerate()
.find(|(_, &b)| b == 0xff)
.find(|&(_, &b)| b == 0xff)
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
.0
+ 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 crate::{
Error, Result,
database::KeyValueDatabase,
service::{
self,
sending::{OutgoingKind, SendingEventType},
},
services, utils, Error, Result,
services, utils,
};
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 crate::{database::KeyValueDatabase, service, Result};
use crate::{Result, database::KeyValueDatabase, service};
impl service::transaction_ids::Data for KeyValueDatabase {
fn add_txnid(

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

@ -1,9 +1,9 @@
use ruma::{
api::client::{error::ErrorKind, uiaa::UiaaInfo},
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 {
fn set_uiaa_request(

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

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

23
conduit/src/database/mod.rs

@ -2,24 +2,25 @@ pub mod abstraction;
pub mod key_value;
use crate::{
Config, Error, PduEvent, Result, SERVICES, Services,
service::{globals, rooms::timeline::PduCount},
services, utils, Config, Error, PduEvent, Result, Services, SERVICES,
services, utils,
};
use abstraction::{KeyValueDatabaseEngine, KvTree};
use base64::{engine::general_purpose, Engine};
use base64::{Engine, engine::general_purpose};
use conduit_config::DatabaseBackend;
use key_value::media::FilehashMetadata;
use lru_cache::LruCache;
use ruma::{
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId,
OwnedUserId, RoomId, UserId,
events::{
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
push_rules::{PushRulesEvent, PushRulesEventContent},
room::message::RoomMessageEventContent,
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
},
push::Ruleset,
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId,
OwnedUserId, RoomId, UserId,
};
use serde::Deserialize;
use sha2::{Digest, Sha256};
@ -446,7 +447,7 @@ impl KeyValueDatabase {
conduit_user
);
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 {
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")?;
tree.clear().unwrap();
@ -1117,7 +1120,9 @@ impl KeyValueDatabase {
match set_emergency_access() {
Ok(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!"));
}
}
@ -1210,7 +1215,7 @@ impl KeyValueDatabase {
#[tracing::instrument]
pub async fn start_cleanup_task() {
#[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind};
use tokio::signal::unix::{SignalKind, signal};
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 database::KeyValueDatabase;
use ruma::api::{MatrixVersion, SupportedVersions};
pub use service::{pdu::PduEvent, Services};
pub use service::{Services, pdu::PduEvent};
pub use utils::error::{Error, Result};
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 axum::{
Router,
body::Body,
extract::{FromRequestParts, MatchedPath},
middleware::map_response,
response::{IntoResponse, Response},
routing::{any, get, on, MethodFilter},
Router,
routing::{MethodFilter, any, get, on},
};
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 figment::{
Figment,
providers::{Env, Format, Toml},
value::Uncased,
Figment,
};
use http::{
header::{self, HeaderName, CONTENT_SECURITY_POLICY},
Method, StatusCode, Uri,
header::{self, CONTENT_SECURITY_POLICY, HeaderName},
};
use opentelemetry::trace::TracerProvider;
use ruma::api::{
IncomingRequest,
client::{
error::{Error as RumaError, ErrorBody, ErrorKind},
uiaa::UiaaResponse,
},
IncomingRequest,
};
use tokio::signal;
use tower::ServiceBuilder;
use tower_http::{
ServiceBuilderExt as _,
cors::{self, CorsLayer},
trace::TraceLayer,
ServiceBuilderExt as _,
};
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
@ -124,7 +124,9 @@ async fn main() {
}
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 {
@ -178,7 +180,9 @@ async fn main() {
let filter_layer = match EnvFilter::try_new(&config.log) {
Ok(s) => s,
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()
}
};
@ -217,7 +221,11 @@ async fn main() {
/// Adds additional headers to prevent any potential XSS attacks via the media repo
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)]
#[tracing::instrument(err)]
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;

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

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

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

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

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

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

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

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

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

@ -1,21 +1,21 @@
mod data;
pub use data::{Data, SigningKeys};
use ruma::{
room_version_rules::RoomVersionRules, serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId,
OwnedEventId, OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId,
MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId, OwnedRoomId,
OwnedServerName, OwnedUserId, RoomAliasId, room_version_rules::RoomVersionRules, serde::Base64,
};
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 futures_util::FutureExt;
use hickory_resolver::TokioResolver;
use hyper_util::client::legacy::connect::dns::{GaiResolver, Name as HyperName};
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
use ruma::{
api::{client::sync::sync_events, federation::discovery::ServerSigningKeys},
DeviceId, RoomVersionId, ServerName, UserId,
api::{client::sync::sync_events, federation::discovery::ServerSigningKeys},
};
use std::{
collections::{BTreeMap, HashMap},
@ -27,12 +27,12 @@ use std::{
path::PathBuf,
str::FromStr,
sync::{
atomic::{self, AtomicBool},
Arc, RwLock as StdRwLock,
atomic::{self, AtomicBool},
},
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 tracing::{error, info};
@ -86,7 +86,7 @@ impl RotationHandler {
Self(s)
}
pub fn watch(&self) -> impl Future<Output = ()> {
pub fn watch(&self) -> impl Future<Output = ()> + use<> {
let mut r = self.0.subscribe();
async move {

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

@ -2,9 +2,9 @@ use std::collections::BTreeMap;
use crate::Result;
use ruma::{
OwnedRoomId, RoomId, UserId,
api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup},
serde::Raw,
OwnedRoomId, RoomId, UserId,
};
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(&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>>>;

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

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

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

@ -1,6 +1,6 @@
use conduit_config::MediaRetentionConfig;
use ruma::{OwnedServerName, ServerName, UserId};
use sha2::{digest::Output, Sha256};
use sha2::{Sha256, digest::Output};
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;
use http::StatusCode;
use ruma::{
OwnedServerName, ServerName, UserId,
api::client::{error::ErrorKind, media::is_safe_inline_content_type},
http_headers::{ContentDisposition, ContentDispositionType},
OwnedServerName, ServerName, UserId,
};
use rusty_s3::{
actions::{DeleteObjectsResponse, ObjectIdentifier},
S3Action,
actions::{DeleteObjectsResponse, ObjectIdentifier},
};
use sha2::{digest::Output, Digest, Sha256};
use sha2::{Digest, Sha256, digest::Output};
use tracing::{error, info, warn};
use crate::{services, utils, Error, Result};
use crate::{Error, Result, services, utils};
use image::imageops::FilterType;
pub struct DbFileMeta {

2
conduit/src/service/mod.rs

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

11
conduit/src/service/pdu.rs

@ -1,23 +1,24 @@
use crate::Error;
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
api::client::error::ErrorKind,
canonical_json::redact_content_in_place,
events::{
room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent},
space::child::HierarchySpaceChildEvent,
AnyInitialStateEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent,
StateEvent, TimelineEventType,
room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent},
space::child::HierarchySpaceChildEvent,
},
room_version_rules::{RedactionRules, RoomVersionRules},
serde::{JsonCastable, Raw},
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
state_res,
};
use serde::{Deserialize, Serialize};
use serde_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 tracing::warn;

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

@ -1,7 +1,7 @@
use crate::Result;
use ruma::{
api::client::push::{set_pusher, Pusher},
UserId,
api::client::push::{Pusher, set_pusher},
};
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_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;
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 ruma::{
RoomId, UInt, UserId,
api::{
client::push::{set_pusher, Pusher, PusherKind},
IncomingResponse, OutgoingRequest, SendAccessToken,
client::push::{Pusher, PusherKind, set_pusher},
push_gateway::send_event_notification::{
self,
v1::{Device, Notification, NotificationCounts, NotificationPriority},
},
IncomingResponse, OutgoingRequest, SendAccessToken,
},
events::TimelineEventType,
push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak},
serde::Raw,
uint, RoomId, UInt, UserId,
uint,
};
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 tracing::warn;
use crate::{services, Error, Result};
use crate::{Error, Result, services};
use ruma::{
OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId,
api::{
appservice,
client::{alias::get_alias, error::ErrorKind},
federation,
},
events::StateEventType,
OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId,
};
pub struct Service {
@ -149,7 +149,7 @@ impl Service {
return Err(Error::BadRequest(
ErrorKind::NotFound,
"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],
) -> Result<Option<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;
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 crate::{services, Error, Result};
use crate::{Error, Result, services};
pub struct Service {
pub db: &'static dyn Data,
@ -29,7 +29,7 @@ impl Service {
&self,
room_id: &RoomId,
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;
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 crate::Result;
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent};
pub trait Data: Send + Sync {
/// 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;
pub use data::Data;
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent};
use crate::Result;

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

@ -1,5 +1,5 @@
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 {
/// 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;
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 db: &'static dyn Data,
@ -32,7 +32,9 @@ impl Service {
u64,
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
)>,
> + 'a {
>
+ 'a
+ use<'a> {
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 tokio::sync::{broadcast, RwLock};
use tokio::sync::{RwLock, broadcast};
use crate::{services, utils, Result};
use crate::{Result, services, utils};
pub struct Service {
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>>;
use std::{
collections::{hash_map, BTreeMap, HashMap, HashSet},
collections::{BTreeMap, HashMap, HashSet, hash_map},
pin::Pin,
sync::Arc,
time::{Duration, Instant, SystemTime},
};
use futures_util::{stream::FuturesUnordered, Future, StreamExt};
use futures_util::{Future, StreamExt, stream::FuturesUnordered};
use globals::SigningKeys;
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName,
OwnedServerSigningKeyId, RoomId, ServerName,
api::{
client::error::ErrorKind,
federation::{
@ -24,24 +26,23 @@ use ruma::{
},
},
events::{
StateEventType, TimelineEventType,
room::{
create::RoomCreateEventContent, redaction::RoomRedactionEventContent,
server_acl::RoomServerAclEventContent,
},
StateEventType, TimelineEventType,
},
int,
room_version_rules::{AuthorizationRules, RoomVersionRules, StateResolutionV2Rules},
serde::Base64,
state_res::{self, StateMap},
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
OwnedServerName, OwnedServerSigningKeyId, RoomId, ServerName,
uint,
};
use serde_json::value::RawValue as RawJsonValue;
use tokio::sync::{RwLock, RwLockWriteGuard, Semaphore};
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;
@ -371,7 +372,7 @@ impl Service {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Redaction failed",
))
));
}
};
@ -718,7 +719,10 @@ impl Service {
.collect::<Result<_>>()?,
),
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
}
}
@ -773,9 +777,11 @@ impl Service {
hash_map::Entry::Vacant(v) => {
v.insert(Arc::from(&*pdu.event_id));
}
hash_map::Entry::Occupied(_) => return Err(
Error::bad_database("State event's type and state_key combination exists multiple times."),
),
hash_map::Entry::Occupied(_) => {
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,
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 {
warn!("Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}",
next_id, calculated_event_id, &res.pdu);
warn!(
"Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}",
next_id, calculated_event_id, &res.pdu
);
}
if let Some(auth_events) =

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

@ -1,38 +1,40 @@
use std::{
collections::{hash_map::Entry, BTreeMap, HashMap},
collections::{BTreeMap, HashMap, hash_map::Entry},
sync::Arc,
time::{Duration, Instant},
};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedServerName, RoomId, RoomVersionId, UserId,
api::{
client::{
error::ErrorKind,
membership::{join_room_by_id, ThirdPartySigned},
membership::{ThirdPartySigned, join_room_by_id},
},
federation,
},
events::{
TimelineEventType,
room::{
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
member::{MembershipState, RoomMemberEventContent},
},
TimelineEventType,
},
room_version_rules::RoomVersionRules,
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
OwnedEventId, OwnedServerName, RoomId, RoomVersionId, UserId,
state_res,
};
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 tracing::{debug, error, info, warn};
use crate::{
Error, PduEvent, Result,
service::{
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;
@ -120,7 +122,9 @@ impl Service {
info!("send_join finished");
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) =
match gen_event_id_canonical_json(signed_raw, &room_version_rules) {
Ok(t) => t,
@ -162,8 +166,8 @@ impl Service {
}
Err(e) => {
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())
{
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) =
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