Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebb1ff3354 | ||
|
|
ca724b6340 | ||
|
|
9bfc7b34b6 |
+31
-56
@@ -142,8 +142,12 @@ build:debug:cargo:x86_64-unknown-linux-musl:
|
||||
DOCKER_HOST: tcp://docker:2375/
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
DOCKER_DRIVER: overlay2
|
||||
PLATFORMS: "linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64"
|
||||
PLATFORMS: "linux/arm/v6,linux/arm/v7,linux/arm64,linux/amd64"
|
||||
DOCKER_FILE: "docker/ci-binaries-packaging.Dockerfile"
|
||||
cache:
|
||||
paths:
|
||||
- docker_cache
|
||||
key: "$CI_JOB_NAME"
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
# Only log in to Dockerhub if the credentials are given:
|
||||
@@ -156,80 +160,51 @@ build:debug:cargo:x86_64-unknown-linux-musl:
|
||||
- mkdir -p linux/ && mv ./conduit-x86_64-unknown-linux-musl linux/amd64
|
||||
- mkdir -p linux/arm/ && mv ./conduit-arm-unknown-linux-musleabihf linux/arm/v6
|
||||
- mkdir -p linux/arm/ && mv ./conduit-armv7-unknown-linux-musleabihf linux/arm/v7
|
||||
- mkdir -p linux/arm64/ && mv ./conduit-aarch64-unknown-linux-musl linux/arm64/v8
|
||||
# Actually create multiarch image:
|
||||
- mv ./conduit-aarch64-unknown-linux-musl linux/arm64
|
||||
- 'export CREATED=$(date -u +''%Y-%m-%dT%H:%M:%SZ'') && echo "Docker image creation date: $CREATED"'
|
||||
# Build and push image:
|
||||
- >
|
||||
docker buildx build
|
||||
--pull
|
||||
--push
|
||||
--build-arg CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
--cache-from=type=local,src=$CI_PROJECT_DIR/docker_cache
|
||||
--cache-to=type=local,dest=$CI_PROJECT_DIR/docker_cache
|
||||
--build-arg CREATED=$CREATED
|
||||
--build-arg VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml)
|
||||
--build-arg "GIT_REF=$CI_COMMIT_SHORT_SHA"
|
||||
--platform "$PLATFORMS"
|
||||
--tag "$GL_IMAGE_TAG"
|
||||
--tag "$GL_IMAGE_TAG-commit-$CI_COMMIT_SHORT_SHA"
|
||||
--tag "$TAG"
|
||||
--tag "$TAG-alpine"
|
||||
--tag "$TAG-commit-$CI_COMMIT_SHORT_SHA"
|
||||
--file "$DOCKER_FILE" .
|
||||
# Only try to push to docker hub, if auth data for dockerhub exists:
|
||||
- if [ -n "${DOCKER_HUB}" ]; then docker push "$DH_IMAGE_TAG"; fi
|
||||
- if [ -n "${DOCKER_HUB}" ]; then docker push "$DH_IMAGE_TAG-commit-$CI_COMMIT_SHORT_SHA"; fi
|
||||
|
||||
build:docker:next:
|
||||
docker:next:gitlab:
|
||||
extends: .docker-shared-settings
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "next"'
|
||||
variables:
|
||||
GL_IMAGE_TAG: "$CI_REGISTRY_IMAGE/matrix-conduit:next"
|
||||
DH_IMAGE_TAG: "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:next"
|
||||
TAG: "$CI_REGISTRY_IMAGE/matrix-conduit:next"
|
||||
|
||||
build:docker:master:
|
||||
docker:next:dockerhub:
|
||||
extends: .docker-shared-settings
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "next" && $DOCKER_HUB'
|
||||
variables:
|
||||
TAG: "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:next"
|
||||
|
||||
docker:master:gitlab:
|
||||
extends: .docker-shared-settings
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||
variables:
|
||||
GL_IMAGE_TAG: "$CI_REGISTRY_IMAGE/matrix-conduit:latest"
|
||||
DH_IMAGE_TAG: "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:latest"
|
||||
TAG: "$CI_REGISTRY_IMAGE/matrix-conduit:latest"
|
||||
|
||||
## Build a docker image by packaging up the x86_64-unknown-linux-musl binary into an alpine image
|
||||
#.docker-shared-settings:
|
||||
# stage: "build docker image"
|
||||
# needs: []
|
||||
# interruptible: true
|
||||
# image:
|
||||
# name: "gcr.io/kaniko-project/executor:debug"
|
||||
# entrypoint: [""]
|
||||
# tags: ["docker"]
|
||||
# variables:
|
||||
# # Configure Kaniko Caching: https://cloud.google.com/build/docs/kaniko-cache
|
||||
# KANIKO_CACHE_ARGS: "--cache=true --cache-copy-layers=true --cache-ttl=120h --cache-repo $CI_REGISTRY_IMAGE/kaniko-ci-cache"
|
||||
# before_script:
|
||||
# - "mkdir -p /kaniko/.docker"
|
||||
# - 'echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"},\"$DOCKER_HUB\":{\"username\":\"$DOCKER_HUB_USER\",\"password\":\"$DOCKER_HUB_PASSWORD\"}}}" > /kaniko/.docker/config.json'
|
||||
#
|
||||
#
|
||||
#build:docker:next:
|
||||
# extends: .docker-shared-settings
|
||||
# needs:
|
||||
# - "build:release:cargo:x86_64-unknown-linux-musl"
|
||||
# script:
|
||||
# - >
|
||||
# /kaniko/executor
|
||||
# $KANIKO_CACHE_ARGS
|
||||
# --force
|
||||
# --context $CI_PROJECT_DIR
|
||||
# --build-arg CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
# --build-arg VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml)
|
||||
# --build-arg "GIT_REF=$CI_COMMIT_SHORT_SHA"
|
||||
# --dockerfile "$CI_PROJECT_DIR/docker/ci-binaries-packaging.Dockerfile"
|
||||
# --destination "$CI_REGISTRY_IMAGE/conduit:next"
|
||||
# --destination "$CI_REGISTRY_IMAGE/conduit:next-alpine"
|
||||
# --destination "$CI_REGISTRY_IMAGE/conduit:commit-$CI_COMMIT_SHORT_SHA"
|
||||
# --destination "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:next"
|
||||
# --destination "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:next-alpine"
|
||||
# --destination "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:commit-$CI_COMMIT_SHORT_SHA"
|
||||
# rules:
|
||||
# - if: '$CI_COMMIT_BRANCH == "next"'
|
||||
#
|
||||
#
|
||||
docker:master:dockerhub:
|
||||
extends: .docker-shared-settings
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "master" && $DOCKER_HUB'
|
||||
variables:
|
||||
TAG: "$DOCKER_HUB_IMAGE/matrixconduit/matrix-conduit:latest"
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Run tests #
|
||||
|
||||
@@ -82,6 +82,9 @@ thread_local = "1.1.3"
|
||||
# used for TURN server authentication
|
||||
hmac = "0.11.0"
|
||||
sha-1 = "0.9.8"
|
||||
# used to embed Element Web into Conduit
|
||||
rust-embed="6.3.0"
|
||||
|
||||
|
||||
[features]
|
||||
default = ["conduit_bin", "backend_sqlite"]
|
||||
|
||||
@@ -12,20 +12,17 @@ only offer Linux binaries.
|
||||
|
||||
You may simply download the binary that fits your machine. Run `uname -m` to see what you need. Now copy the right url:
|
||||
|
||||
| CPU Architecture | Download link |
|
||||
| ------------------------------------------- | ----------------------- |
|
||||
| x84_64 / amd64 (Most servers and computers) | [Download][x84_64-musl] |
|
||||
| armv6 | [Download][armv6-musl] |
|
||||
| armv7 (e.g. Raspberry Pi by default) | [Download][armv7-musl] |
|
||||
| armv8 / aarch64 | [Download][armv8-musl] |
|
||||
| CPU Architecture | Download stable version |
|
||||
| ------------------------------------------- | ------------------------------ |
|
||||
| x84_64 / amd64 (Most servers and computers) | [Download][x84_64-musl-master] |
|
||||
| armv6 | [Download][armv6-musl-master] |
|
||||
| armv7 (e.g. Raspberry Pi by default) | [Download][armv7-musl-master] |
|
||||
| armv8 / aarch64 | [Download][armv8-musl-master] |
|
||||
|
||||
[x84_64-musl]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-x86_64-unknown-linux-musl?job=build:release:cargo:x86_64-unknown-linux-musl
|
||||
|
||||
[armv6-musl]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-arm-unknown-linux-musleabihf?job=build:release:cargo:arm-unknown-linux-musleabihf
|
||||
|
||||
[armv7-musl]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-armv7-unknown-linux-musleabihf?job=build:release:cargo:armv7-unknown-linux-musleabihf
|
||||
|
||||
[armv8-musl]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-aarch64-unknown-linux-musl?job=build:release:cargo:aarch64-unknown-linux-musl
|
||||
[x84_64-musl-master]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-x86_64-unknown-linux-musl?job=build:release:cargo:x86_64-unknown-linux-musl
|
||||
[armv6-musl-master]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-arm-unknown-linux-musleabihf?job=build:release:cargo:arm-unknown-linux-musleabihf
|
||||
[armv7-musl-master]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-armv7-unknown-linux-musleabihf?job=build:release:cargo:armv7-unknown-linux-musleabihf
|
||||
[armv8-musl-master]: https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-aarch64-unknown-linux-musl?job=build:release:cargo:aarch64-unknown-linux-musl
|
||||
|
||||
```bash
|
||||
$ sudo wget -O /usr/local/bin/matrix-conduit <url>
|
||||
|
||||
+2
-2
@@ -54,11 +54,11 @@ RUN apk add --no-cache \
|
||||
RUN mkdir -p /srv/conduit/.local/share/conduit
|
||||
|
||||
# Test if Conduit is still alive, uses the same endpoint as Element
|
||||
COPY ./docker/healthcheck.sh /srv/conduit/
|
||||
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
|
||||
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
|
||||
|
||||
# Copy over the actual Conduit binary from the builder stage
|
||||
COPY --from=builder /usr/src/conduit/target/release/conduit /srv/conduit/
|
||||
COPY --from=builder /usr/src/conduit/target/release/conduit /srv/conduit/conduit
|
||||
|
||||
# Improve security: Don't run stuff as root, that does not need to run as root:
|
||||
# Add www-data user and group with UID 82, as used by alpine
|
||||
|
||||
@@ -47,7 +47,7 @@ LABEL org.opencontainers.image.created=${CREATED} \
|
||||
RUN mkdir -p /srv/conduit/.local/share/conduit
|
||||
|
||||
# Test if Conduit is still alive, uses the same endpoint as Element
|
||||
COPY ./docker/healthcheck.sh /srv/conduit/
|
||||
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
|
||||
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ use ruma::{
|
||||
EventType,
|
||||
},
|
||||
identifiers::RoomName,
|
||||
push, RoomAliasId, RoomId, UserId,
|
||||
push, RoomAliasId, RoomId, RoomVersionId, UserId,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use tracing::info;
|
||||
@@ -282,7 +282,7 @@ pub async fn register_route(
|
||||
let mut content = RoomCreateEventContent::new(conduit_user.clone());
|
||||
content.federate = true;
|
||||
content.predecessor = None;
|
||||
content.room_version = db.globals.default_room_version();
|
||||
content.room_version = RoomVersionId::Version6;
|
||||
|
||||
// 1. The room create event
|
||||
db.rooms.build_and_append_pdu(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
||||
use ruma::api::client::r0::capabilities::{
|
||||
get_capabilities, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
||||
use crate::{ConduitResult, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::capabilities::{
|
||||
get_capabilities, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
||||
},
|
||||
RoomVersionId,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -14,28 +17,17 @@ use rocket::get;
|
||||
feature = "conduit_bin",
|
||||
get("/_matrix/client/r0/capabilities", data = "<_body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(_body, db))]
|
||||
#[tracing::instrument(skip(_body))]
|
||||
pub async fn get_capabilities_route(
|
||||
_body: Ruma<get_capabilities::Request>,
|
||||
db: DatabaseGuard,
|
||||
) -> ConduitResult<get_capabilities::Response> {
|
||||
let mut available = BTreeMap::new();
|
||||
if db.globals.allow_unstable_room_versions() {
|
||||
for room_version in &db.globals.unstable_room_versions {
|
||||
available.insert(room_version.clone(), RoomVersionStability::Stable);
|
||||
}
|
||||
} else {
|
||||
for room_version in &db.globals.unstable_room_versions {
|
||||
available.insert(room_version.clone(), RoomVersionStability::Unstable);
|
||||
}
|
||||
}
|
||||
for room_version in &db.globals.stable_room_versions {
|
||||
available.insert(room_version.clone(), RoomVersionStability::Stable);
|
||||
}
|
||||
available.insert(RoomVersionId::Version5, RoomVersionStability::Stable);
|
||||
available.insert(RoomVersionId::Version6, RoomVersionStability::Stable);
|
||||
|
||||
let mut capabilities = Capabilities::new();
|
||||
capabilities.room_versions = RoomVersionsCapability {
|
||||
default: db.globals.default_room_version(),
|
||||
default: RoomVersionId::Version6,
|
||||
available,
|
||||
};
|
||||
|
||||
|
||||
@@ -551,7 +551,7 @@ async fn join_room_by_id_helper(
|
||||
federation::membership::create_join_event_template::v1::Request {
|
||||
room_id,
|
||||
user_id: sender_user,
|
||||
ver: &db.globals.supported_room_versions(),
|
||||
ver: &[RoomVersionId::Version5, RoomVersionId::Version6],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -566,7 +566,12 @@ async fn join_room_by_id_helper(
|
||||
let (make_join_response, remote_server) = make_join_response_and_server?;
|
||||
|
||||
let room_version = match make_join_response.room_version {
|
||||
Some(room_version) if db.rooms.is_supported_version(&db, &room_version) => room_version,
|
||||
Some(room_version)
|
||||
if room_version == RoomVersionId::Version5
|
||||
|| room_version == RoomVersionId::Version6 =>
|
||||
{
|
||||
room_version
|
||||
}
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
@@ -885,10 +890,9 @@ pub(crate) async fn invite_helper<'a>(
|
||||
None
|
||||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a room with the default
|
||||
// version right now
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version_id = create_event_content
|
||||
.map_or(db.globals.default_room_version(), |create_event| {
|
||||
.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version =
|
||||
@@ -1035,8 +1039,7 @@ pub(crate) async fn invite_helper<'a>(
|
||||
let pub_key_map = RwLock::new(BTreeMap::new());
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(&response.event, &db)
|
||||
{
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(&response.event) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
|
||||
@@ -23,7 +23,7 @@ use ruma::{
|
||||
EventType,
|
||||
},
|
||||
serde::{CanonicalJsonObject, JsonObject},
|
||||
RoomAliasId, RoomId,
|
||||
RoomAliasId, RoomId, RoomVersionId,
|
||||
};
|
||||
use serde_json::{json, value::to_raw_value};
|
||||
use std::{
|
||||
@@ -109,7 +109,7 @@ pub async fn create_room_route(
|
||||
|
||||
let room_version = match body.room_version.clone() {
|
||||
Some(room_version) => {
|
||||
if db.rooms.is_supported_version(&db, &room_version) {
|
||||
if room_version == RoomVersionId::Version5 || room_version == RoomVersionId::Version6 {
|
||||
room_version
|
||||
} else {
|
||||
return Err(Error::BadRequest(
|
||||
@@ -118,7 +118,7 @@ pub async fn create_room_route(
|
||||
));
|
||||
}
|
||||
}
|
||||
None => db.globals.default_room_version(),
|
||||
None => RoomVersionId::Version6,
|
||||
};
|
||||
|
||||
let content = match &body.creation_content {
|
||||
@@ -505,7 +505,10 @@ pub async fn upgrade_room_route(
|
||||
) -> ConduitResult<upgrade_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
if !db.rooms.is_supported_version(&db, &body.new_version) {
|
||||
if !matches!(
|
||||
body.new_version,
|
||||
RoomVersionId::Version5 | RoomVersionId::Version6
|
||||
) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::UnsupportedRoomVersion,
|
||||
"This server does not support that room version.",
|
||||
|
||||
+1
-9
@@ -24,7 +24,7 @@ use rocket::{
|
||||
request::{FromRequest, Request},
|
||||
Shutdown, State,
|
||||
};
|
||||
use ruma::{DeviceId, EventId, RoomId, RoomVersionId, ServerName, UserId};
|
||||
use ruma::{DeviceId, EventId, RoomId, ServerName, UserId};
|
||||
use serde::{de::IgnoredAny, Deserialize};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
@@ -63,12 +63,8 @@ pub struct Config {
|
||||
allow_federation: bool,
|
||||
#[serde(default = "true_fn")]
|
||||
allow_room_creation: bool,
|
||||
#[serde(default = "true_fn")]
|
||||
allow_unstable_room_versions: bool,
|
||||
#[serde(default = "false_fn")]
|
||||
pub allow_jaeger: bool,
|
||||
#[serde(default = "default_room_version")]
|
||||
default_room_version: RoomVersionId,
|
||||
#[serde(default = "false_fn")]
|
||||
pub tracing_flame: bool,
|
||||
#[serde(default)]
|
||||
@@ -141,10 +137,6 @@ fn default_max_concurrent_requests() -> u16 {
|
||||
100
|
||||
}
|
||||
|
||||
fn default_room_version() -> RoomVersionId {
|
||||
RoomVersionId::Version6
|
||||
}
|
||||
|
||||
fn default_log() -> String {
|
||||
"info,state_res=warn,rocket=off,_=off,sled=off".to_owned()
|
||||
}
|
||||
|
||||
+2
-41
@@ -4,8 +4,7 @@ use ruma::{
|
||||
client::r0::sync::sync_events,
|
||||
federation::discovery::{ServerSigningKeys, VerifyKey},
|
||||
},
|
||||
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName,
|
||||
ServerSigningKeyId, UserId,
|
||||
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, UserId,
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
@@ -40,8 +39,6 @@ pub struct Globals {
|
||||
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
||||
dns_resolver: TokioAsyncResolver,
|
||||
jwt_decoding_key: Option<jsonwebtoken::DecodingKey<'static>>,
|
||||
pub stable_room_versions: Vec<RoomVersionId>,
|
||||
pub unstable_room_versions: Vec<RoomVersionId>,
|
||||
pub(super) server_signingkeys: Arc<dyn Tree>,
|
||||
pub bad_event_ratelimiter: Arc<RwLock<HashMap<EventId, RateLimitState>>>,
|
||||
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
|
||||
@@ -135,16 +132,7 @@ impl Globals {
|
||||
.as_ref()
|
||||
.map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static());
|
||||
|
||||
// Supported and stable room versions
|
||||
let stable_room_versions = vec![RoomVersionId::Version6];
|
||||
// Experimental, partially supported room versions
|
||||
let unstable_room_versions = vec![
|
||||
RoomVersionId::Version3,
|
||||
RoomVersionId::Version4,
|
||||
RoomVersionId::Version5,
|
||||
];
|
||||
|
||||
let mut s = Self {
|
||||
let s = Self {
|
||||
globals,
|
||||
config,
|
||||
keypair: Arc::new(keypair),
|
||||
@@ -155,8 +143,6 @@ impl Globals {
|
||||
tls_name_override,
|
||||
server_signingkeys,
|
||||
jwt_decoding_key,
|
||||
stable_room_versions,
|
||||
unstable_room_versions,
|
||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
bad_signature_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
servername_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
@@ -169,14 +155,6 @@ impl Globals {
|
||||
|
||||
fs::create_dir_all(s.get_media_folder())?;
|
||||
|
||||
if !s
|
||||
.supported_room_versions()
|
||||
.contains(&s.config.default_room_version)
|
||||
{
|
||||
error!("Room version in config isn't supported, falling back to Version 6");
|
||||
s.config.default_room_version = RoomVersionId::Version6;
|
||||
};
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
@@ -236,14 +214,6 @@ impl Globals {
|
||||
self.config.allow_room_creation
|
||||
}
|
||||
|
||||
pub fn allow_unstable_room_versions(&self) -> bool {
|
||||
self.config.allow_unstable_room_versions
|
||||
}
|
||||
|
||||
pub fn default_room_version(&self) -> RoomVersionId {
|
||||
self.config.default_room_version.clone()
|
||||
}
|
||||
|
||||
pub fn trusted_servers(&self) -> &[Box<ServerName>] {
|
||||
&self.config.trusted_servers
|
||||
}
|
||||
@@ -276,15 +246,6 @@ impl Globals {
|
||||
&self.config.turn_secret
|
||||
}
|
||||
|
||||
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> {
|
||||
let mut room_versions: Vec<RoomVersionId> = vec![];
|
||||
room_versions.extend(self.stable_room_versions.clone());
|
||||
if self.allow_unstable_room_versions() {
|
||||
room_versions.extend(self.unstable_room_versions.clone());
|
||||
};
|
||||
room_versions
|
||||
}
|
||||
|
||||
/// TODO: the key valid until timestamp is only honored in room version > 4
|
||||
/// Remove the outdated keys and insert the new ones.
|
||||
///
|
||||
|
||||
+7
-30
@@ -129,12 +129,6 @@ pub struct Rooms {
|
||||
}
|
||||
|
||||
impl Rooms {
|
||||
/// Returns true if a given room version is supported
|
||||
#[tracing::instrument(skip(self, db))]
|
||||
pub fn is_supported_version(&self, db: &Database, room_version: &RoomVersionId) -> bool {
|
||||
db.globals.supported_room_versions().contains(room_version)
|
||||
}
|
||||
|
||||
/// Builds a StateMap by iterating over all keys that start
|
||||
/// with state_hash, this gives the full state for the given state_hash.
|
||||
#[tracing::instrument(skip(self))]
|
||||
@@ -1989,10 +1983,9 @@ impl Rooms {
|
||||
None
|
||||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a room with the default
|
||||
// version right now
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version_id = create_event_content
|
||||
.map_or(db.globals.default_room_version(), |create_event| {
|
||||
.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
@@ -2785,7 +2778,11 @@ impl Rooms {
|
||||
let (make_leave_response, remote_server) = make_leave_response_and_server?;
|
||||
|
||||
let room_version_id = match make_leave_response.room_version {
|
||||
Some(version) if self.is_supported_version(&db, &version) => version,
|
||||
Some(version)
|
||||
if version == RoomVersionId::Version5 || version == RoomVersionId::Version6 =>
|
||||
{
|
||||
version
|
||||
}
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
@@ -3451,24 +3448,4 @@ impl Rooms {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the room's version.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_room_version(&self, room_id: &RoomId) -> Result<RoomVersionId> {
|
||||
let create_event = self.room_state_get(room_id, &EventType::RoomCreate, "")?;
|
||||
|
||||
let create_event_content: Option<RoomCreateEventContent> = create_event
|
||||
.as_ref()
|
||||
.map(|create_event| {
|
||||
serde_json::from_str(create_event.content.get()).map_err(|e| {
|
||||
warn!("Invalid create event: {}", e);
|
||||
Error::bad_database("Invalid create event in db.")
|
||||
})
|
||||
})
|
||||
.transpose()?;
|
||||
let room_version = create_event_content
|
||||
.map(|create_event| create_event.room_version)
|
||||
.ok_or_else(|| Error::BadDatabase("Invalid room version"))?;
|
||||
Ok(room_version)
|
||||
}
|
||||
}
|
||||
|
||||
+38
-1
@@ -17,11 +17,15 @@ mod pdu;
|
||||
mod ruma_wrapper;
|
||||
mod utils;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use database::Config;
|
||||
pub use database::Database;
|
||||
pub use error::{Error, Result};
|
||||
use http::StatusCode;
|
||||
use opentelemetry::trace::{FutureExt, Tracer};
|
||||
pub use pdu::PduEvent;
|
||||
pub use rocket::State;
|
||||
@@ -34,8 +38,12 @@ use rocket::{
|
||||
providers::{Env, Format, Toml},
|
||||
Figment,
|
||||
},
|
||||
routes, Request,
|
||||
get,
|
||||
http::{ContentType, Status},
|
||||
response, routes, Request,
|
||||
};
|
||||
|
||||
use rust_embed::RustEmbed;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||
|
||||
@@ -176,6 +184,7 @@ fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<
|
||||
server_server::claim_keys_route,
|
||||
],
|
||||
)
|
||||
.mount("/", routes![dist])
|
||||
.register(
|
||||
"/",
|
||||
catchers![
|
||||
@@ -276,6 +285,34 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "element_web"]
|
||||
struct ElementWebAsset;
|
||||
|
||||
#[get("/<file..>")]
|
||||
fn dist<'r>(file: PathBuf) -> response::Result<'r> {
|
||||
let filename = file.display().to_string();
|
||||
|
||||
ElementWebAsset::get(&filename).map_or_else(
|
||||
|| Err(Status::NotFound),
|
||||
|embedded_file| {
|
||||
let ext = file
|
||||
.as_path()
|
||||
.extension()
|
||||
.and_then(OsStr::to_str)
|
||||
.ok_or_else(|| Status::new(400))?;
|
||||
|
||||
let content_type = ContentType::from_extension(ext).ok_or_else(|| Status::new(400))?;
|
||||
|
||||
let response: Result<response::Response<'r>, Status> = response::Response::build()
|
||||
.header(content_type)
|
||||
.sized_body(embedded_file.data.len(), Cursor::new(embedded_file.data))
|
||||
.ok();
|
||||
return response;
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found_catcher(_: &Request<'_>) -> String {
|
||||
"404 Not Found".to_owned()
|
||||
|
||||
+4
-12
@@ -1,4 +1,4 @@
|
||||
use crate::{Database, Error};
|
||||
use crate::Error;
|
||||
use ruma::{
|
||||
events::{
|
||||
room::member::RoomMemberEventContent, AnyEphemeralRoomEvent, AnyInitialStateEvent,
|
||||
@@ -6,7 +6,7 @@ use ruma::{
|
||||
EventType, StateEvent,
|
||||
},
|
||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
state_res, EventId, MilliSecondsSinceUnixEpoch, RoomId, UInt, UserId,
|
||||
state_res, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, UInt, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{
|
||||
@@ -331,24 +331,16 @@ impl Ord for PduEvent {
|
||||
/// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap<String, CanonicalJsonValue>`.
|
||||
pub(crate) fn gen_event_id_canonical_json(
|
||||
pdu: &RawJsonValue,
|
||||
db: &Database,
|
||||
) -> crate::Result<(EventId, CanonicalJsonObject)> {
|
||||
let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
let value = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
warn!("Error parsing incoming event {:?}: {:?}", pdu, e);
|
||||
Error::BadServerResponse("Invalid PDU in server response")
|
||||
})?;
|
||||
|
||||
let room_id = value
|
||||
.get("room_id")
|
||||
.and_then(|id| RoomId::try_from(id.as_str()?).ok())
|
||||
.expect("Invalid room id in event");
|
||||
|
||||
let room_version_id = db.rooms.get_room_version(&room_id);
|
||||
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
// Anything higher than version3 behaves the same
|
||||
ruma::signatures::reference_hash(&value, &room_version_id?)
|
||||
ruma::signatures::reference_hash(&value, &RoomVersionId::Version6)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
||||
+9
-10
@@ -725,7 +725,7 @@ pub async fn send_transaction_message_route(
|
||||
|
||||
for pdu in &body.pdus {
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu, &db) {
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
@@ -1911,7 +1911,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
||||
Ok(res) => {
|
||||
warn!("Got {} over federation", id);
|
||||
let (calculated_event_id, value) =
|
||||
match crate::pdu::gen_event_id_canonical_json(&res.pdu, &db) {
|
||||
match crate::pdu::gen_event_id_canonical_json(&res.pdu) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
back_off((**id).clone());
|
||||
@@ -2670,12 +2670,10 @@ pub fn create_join_event_template_route(
|
||||
None
|
||||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a room with the default version
|
||||
// right now
|
||||
let room_version_id = create_event_content
|
||||
.map_or(db.globals.default_room_version(), |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version_id = create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
if !body.ver.contains(&room_version_id) {
|
||||
@@ -2815,7 +2813,7 @@ async fn create_join_event(
|
||||
// let mut auth_cache = EventMap::new();
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu, &db) {
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
@@ -2939,7 +2937,8 @@ pub async fn create_invite_route(
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
}
|
||||
|
||||
if !db.rooms.is_supported_version(&db, &body.room_version) {
|
||||
if body.room_version != RoomVersionId::Version5 && body.room_version != RoomVersionId::Version6
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion {
|
||||
room_version: body.room_version.clone(),
|
||||
|
||||
Reference in New Issue
Block a user