Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62f90ed04c | ||
|
|
1a4cc81df1 | ||
|
|
c07d744ece |
@@ -59,7 +59,6 @@ $RECYCLE.BIN/
|
||||
# Conduit
|
||||
Rocket.toml
|
||||
conduit.toml
|
||||
conduit.db
|
||||
|
||||
# Etc.
|
||||
**/*.rs.bk
|
||||
|
||||
+16
-176
@@ -1,188 +1,28 @@
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
- publish artifacts
|
||||
- release nightly
|
||||
image: "rust:latest"
|
||||
|
||||
default:
|
||||
tags: [docker]
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- target
|
||||
- cargohome
|
||||
|
||||
|
||||
variables:
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
CARGO_HOME: "cargohome"
|
||||
FF_USE_FASTZIP: 1
|
||||
CACHE_COMPRESSION_LEVEL: fastest
|
||||
|
||||
before_script:
|
||||
- mkdir -p $CARGO_HOME && echo "using $CARGO_HOME to cache cargo deps"
|
||||
- apt-get update -yqq
|
||||
- apt-get install -yqq --no-install-recommends build-essential libssl-dev pkg-config
|
||||
- rustup component add clippy rustfmt
|
||||
|
||||
test:cargo:
|
||||
stage: "test"
|
||||
needs: []
|
||||
image: "rust:latest"
|
||||
variables:
|
||||
CARGO_HOME: "cargohome"
|
||||
cache:
|
||||
paths:
|
||||
- target
|
||||
- cargohome
|
||||
key: test_cache
|
||||
interruptible: true
|
||||
before_script:
|
||||
- mkdir -p $CARGO_HOME && echo "using $CARGO_HOME to cache cargo deps"
|
||||
- apt-get update -yqq
|
||||
- apt-get install -yqq --no-install-recommends build-essential libssl-dev pkg-config
|
||||
- rustup component add clippy rustfmt
|
||||
script:
|
||||
- rustc --version && cargo --version # Print version info for debugging
|
||||
- cargo test --workspace --verbose --locked
|
||||
- cargo fmt --all -- --check
|
||||
- cargo clippy
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Cargo: Compiling for different architectures #
|
||||
# --------------------------------------------------------------------- #
|
||||
|
||||
.build-cargo-shared-settings:
|
||||
stage: "build"
|
||||
needs: []
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
||||
interruptible: true
|
||||
image: "rust:latest"
|
||||
cache:
|
||||
paths:
|
||||
- cargohome
|
||||
- target/
|
||||
key: "build_cache-$TARGET"
|
||||
before_script:
|
||||
- 'echo "Building for target $TARGET"'
|
||||
- 'mkdir -p cargohome && CARGOHOME="cargohome"'
|
||||
- "cat /etc/*-release && rustc --version && cargo --version" # Print version info for debugging
|
||||
- 'apt-get update -yqq'
|
||||
- 'echo "Installing packages: $NEEDED_PACKAGES"'
|
||||
- "apt-get install -yqq --no-install-recommends $NEEDED_PACKAGES"
|
||||
- "rustup target add $TARGET"
|
||||
script:
|
||||
- time cargo build --target $TARGET --release
|
||||
- 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"'
|
||||
artifacts:
|
||||
name: "conduit-$TARGET"
|
||||
expose_as: "Binary"
|
||||
paths:
|
||||
- "conduit-$TARGET"
|
||||
|
||||
build:cargo:x86_64-unknown-linux-gnu:
|
||||
extends: .build-cargo-shared-settings
|
||||
variables:
|
||||
TARGET: "x86_64-unknown-linux-gnu"
|
||||
|
||||
build:cargo:armv7-unknown-linux-gnueabihf:
|
||||
extends: .build-cargo-shared-settings
|
||||
variables:
|
||||
TARGET: "armv7-unknown-linux-gnueabihf"
|
||||
NEEDED_PACKAGES: "build-essential gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross"
|
||||
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
|
||||
CC_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc
|
||||
CXX_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++
|
||||
|
||||
build:cargo:aarch64-unknown-linux-gnu:
|
||||
extends: .build-cargo-shared-settings
|
||||
variables:
|
||||
TARGET: "aarch64-unknown-linux-gnu"
|
||||
NEEDED_PACKAGES: "build-essential gcc-8-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross"
|
||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
|
||||
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
|
||||
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
|
||||
TARGET_CC: "/usr/bin/aarch64-linux-gnu-gcc-8"
|
||||
TARGET_AR: "/usr/bin/aarch64-linux-gnu-gcc-ar-8"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Cargo: Compiling deb packages for different architectures #
|
||||
# --------------------------------------------------------------------- #
|
||||
|
||||
|
||||
.build-cargo-deb-shared-settings:
|
||||
stage: "build"
|
||||
needs: []
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
||||
interruptible: true
|
||||
image: "rust:latest"
|
||||
cache:
|
||||
paths:
|
||||
- cargohome
|
||||
- target/
|
||||
key: "build_cache-deb-$TARGET"
|
||||
before_script:
|
||||
- 'echo "Building debian package for target $TARGET"'
|
||||
- 'mkdir -p cargohome && CARGOHOME="cargohome"'
|
||||
- "cat /etc/*-release && rustc --version && cargo --version" # Print version info for debugging
|
||||
- 'apt-get update -yqq'
|
||||
- 'echo "Installing packages: $NEEDED_PACKAGES"'
|
||||
- "apt-get install -yqq --no-install-recommends $NEEDED_PACKAGES"
|
||||
- "rustup target add $TARGET"
|
||||
- "cargo install cargo-deb"
|
||||
script:
|
||||
- time cargo deb --target $TARGET
|
||||
- 'mv target/$TARGET/debian/*.deb "conduit-$TARGET.deb"'
|
||||
artifacts:
|
||||
name: "conduit-$TARGET.deb"
|
||||
expose_as: "Debian Package"
|
||||
paths:
|
||||
- "conduit-$TARGET.deb"
|
||||
|
||||
build:cargo-deb:x86_64-unknown-linux-gnu:
|
||||
extends: .build-cargo-deb-shared-settings
|
||||
variables:
|
||||
TARGET: "x86_64-unknown-linux-gnu"
|
||||
NEEDED_PACKAGES: ""
|
||||
|
||||
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Storing and releasing compiled binaries #
|
||||
# --------------------------------------------------------------------- #
|
||||
|
||||
publish:package:
|
||||
stage: "publish artifacts"
|
||||
needs:
|
||||
- "build:cargo:x86_64-unknown-linux-gnu"
|
||||
- "build:cargo:armv7-unknown-linux-gnueabihf"
|
||||
- "build:cargo:aarch64-unknown-linux-gnu"
|
||||
- "build:cargo-deb:x86_64-unknown-linux-gnu"
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
||||
image: curlimages/curl:latest
|
||||
variables:
|
||||
GIT_STRATEGY: "none" # Don't need a clean copy of the code, we just operate on artifacts
|
||||
script:
|
||||
- 'BASE_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}"'
|
||||
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-x86_64-unknown-linux-gnu "${BASE_URL}/conduit-x86_64-unknown-linux-gnu"'
|
||||
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-armv7-unknown-linux-gnueabihf "${BASE_URL}/conduit-armv7-unknown-linux-gnueabihf"'
|
||||
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-aarch64-unknown-linux-gnu "${BASE_URL}/conduit-aarch64-unknown-linux-gnu"'
|
||||
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-x86_64-unknown-linux-gnu.deb "${BASE_URL}/conduit-x86_64-unknown-linux-gnu.deb"'
|
||||
|
||||
|
||||
|
||||
publish:nightly:
|
||||
stage: "release nightly"
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
needs:
|
||||
- job: "publish:package"
|
||||
artifacts: false
|
||||
variables:
|
||||
GIT_STRATEGY: "none" # Don't need a clean copy of the code, we just operate on artifacts
|
||||
script: "echo 'Releasing current state as release'"
|
||||
rules:
|
||||
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH" # Run this job on the main branch
|
||||
release:
|
||||
name: 'Nightly'
|
||||
description: '⚠️ The latest development version of the day, fresh from the repository. Use at your own risk!'
|
||||
tag_name: 'nightly'
|
||||
assets:
|
||||
links:
|
||||
- name: 'conduit-x86_64-unknown-linux-gnu'
|
||||
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}/conduit-x86_64-unknown-linux-gnu"
|
||||
- name: 'conduit-armv7-unknown-linux-gnueabihf'
|
||||
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}/conduit-armv7-unknown-linux-gnueabihf"
|
||||
- name: 'conduit-aarch64-unknown-linux-gnu'
|
||||
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}/conduit-aarch64-unknown-linux-gnu"
|
||||
- name: 'conduit-x86_64-unknown-linux-gnu.deb'
|
||||
url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}/conduit-x86_64-unknown-linux-gnu.deb"
|
||||
|
||||
Generated
+26
-166
@@ -6,17 +6,6 @@ version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
|
||||
dependencies = [
|
||||
"getrandom 0.2.2",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.15"
|
||||
@@ -249,17 +238,14 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"bytes",
|
||||
"crossbeam",
|
||||
"directories",
|
||||
"http",
|
||||
"image",
|
||||
"jsonwebtoken",
|
||||
"log",
|
||||
"lru-cache",
|
||||
"num_cpus",
|
||||
"opentelemetry",
|
||||
"opentelemetry-jaeger",
|
||||
"parking_lot",
|
||||
"pretty_env_logger",
|
||||
"rand 0.8.3",
|
||||
"regex",
|
||||
@@ -268,7 +254,6 @@ dependencies = [
|
||||
"rocket",
|
||||
"rocksdb",
|
||||
"ruma",
|
||||
"rusqlite",
|
||||
"rust-argon2",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
@@ -354,46 +339,11 @@ dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-queue",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.5"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
|
||||
checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils",
|
||||
@@ -402,22 +352,13 @@ dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.5"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
|
||||
checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if 1.0.0",
|
||||
"lazy_static",
|
||||
]
|
||||
@@ -606,18 +547,6 @@ dependencies = [
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-streaming-iterator"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
|
||||
[[package]]
|
||||
name = "figment"
|
||||
version = "0.10.5"
|
||||
@@ -845,24 +774,6 @@ version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf"
|
||||
dependencies = [
|
||||
"hashbrown 0.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.2"
|
||||
@@ -1009,7 +920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown 0.9.1",
|
||||
"hashbrown",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@@ -1172,17 +1083,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.22.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.4"
|
||||
@@ -1584,12 +1484,6 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.16.8"
|
||||
@@ -1868,7 +1762,6 @@ dependencies = [
|
||||
"serde_urlencoded",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-socks",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
@@ -1990,7 +1883,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
@@ -2011,7 +1904,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-api"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
@@ -2027,7 +1920,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-api-macros"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2038,7 +1931,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"ruma-api",
|
||||
"ruma-common",
|
||||
@@ -2052,7 +1945,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.11.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"bytes",
|
||||
@@ -2072,7 +1965,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.5.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"js_int",
|
||||
@@ -2086,8 +1979,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.23.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
version = "0.23.2"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"indoc",
|
||||
"js_int",
|
||||
@@ -2101,8 +1994,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruma-events-macros"
|
||||
version = "0.23.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
version = "0.23.2"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2113,7 +2006,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
@@ -2128,7 +2021,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers"
|
||||
version = "0.19.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"paste",
|
||||
"rand 0.8.3",
|
||||
@@ -2142,7 +2035,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-macros"
|
||||
version = "0.19.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
@@ -2152,12 +2045,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
|
||||
[[package]]
|
||||
name = "ruma-identity-service-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
@@ -2170,7 +2063,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
@@ -2185,7 +2078,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-serde"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
@@ -2199,7 +2092,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-serde-macros"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2210,7 +2103,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.8.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"ed25519-dalek",
|
||||
@@ -2227,7 +2120,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-state-res"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=174555857ef90d49e4b9a672be9e2fe0acdc2687#174555857ef90d49e4b9a672be9e2fe0acdc2687"
|
||||
source = "git+https://github.com/DevinR528/ruma?branch=state-closure#95208b9d03876e7c85543fe8655ceb2f7dc76363"
|
||||
dependencies = [
|
||||
"itertools 0.10.0",
|
||||
"js_int",
|
||||
@@ -2242,21 +2135,6 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.25.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57adcf67c8faaf96f3248c2a7b419a0dbc52ebe36ba83dd57fe83827c1ea4eb3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"memchr",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
@@ -2853,18 +2731,6 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-socks"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0"
|
||||
dependencies = [
|
||||
"either",
|
||||
"futures-util",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.6.6"
|
||||
@@ -3128,12 +2994,6 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
|
||||
+4
-9
@@ -17,7 +17,8 @@ edition = "2018"
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests
|
||||
|
||||
# Used for matrix spec type definitions and helpers
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
#ruma = { git = "https://github.com/ruma/ruma", rev = "5a7e2cddcf257e367465cced51442c91e8f557c9", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
ruma = { git = "https://github.com/DevinR528/ruma", branch = "state-closure", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
|
||||
|
||||
# Used for long polling and federation sender, should be the same as rocket::tokio
|
||||
@@ -46,7 +47,7 @@ rand = "0.8.3"
|
||||
# Used to hash passwords
|
||||
rust-argon2 = "0.8.3"
|
||||
# Used to send requests
|
||||
reqwest = { version = "0.11.3", default-features = false, features = ["rustls-tls-native-roots", "socks"] }
|
||||
reqwest = { version = "0.11.3", default-features = false, features = ["rustls-tls-native-roots"] }
|
||||
# Custom TLS verifier
|
||||
rustls = { version = "0.19", features = ["dangerous_configuration"] }
|
||||
rustls-native-certs = "0.5.0"
|
||||
@@ -73,17 +74,11 @@ tracing-opentelemetry = "0.11.0"
|
||||
opentelemetry-jaeger = "0.11.0"
|
||||
pretty_env_logger = "0.4.0"
|
||||
lru-cache = "0.1.2"
|
||||
rusqlite = { version = "0.25.3", optional = true, features = ["bundled"] }
|
||||
parking_lot = { version = "0.11.1", optional = true }
|
||||
crossbeam = { version = "0.8.1", optional = true }
|
||||
num_cpus = { version = "1.13.0", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["conduit_bin", "backend_sqlite"]
|
||||
default = ["conduit_bin", "backend_sled"]
|
||||
backend_sled = ["sled"]
|
||||
backend_rocksdb = ["rocksdb"]
|
||||
backend_sqlite = ["sqlite"]
|
||||
sqlite = ["rusqlite", "parking_lot", "crossbeam", "num_cpus", "tokio/signal"]
|
||||
conduit_bin = [] # TODO: add rocket to this when it is optional
|
||||
|
||||
[[bin]]
|
||||
|
||||
@@ -106,7 +106,7 @@ allow_federation = true
|
||||
|
||||
trusted_servers = ["matrix.org"]
|
||||
|
||||
#db_cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time
|
||||
#workers = 4 # default: cpu core count * 2
|
||||
|
||||
|
||||
@@ -35,11 +35,9 @@ max_request_size = 20_000_000 # in bytes
|
||||
|
||||
trusted_servers = ["matrix.org"]
|
||||
|
||||
#db_cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time
|
||||
#log = "info,state_res=warn,rocket=off,_=off,sled=off"
|
||||
#workers = 4 # default: cpu core count * 2
|
||||
|
||||
address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy
|
||||
|
||||
proxy = "none" # more examples can be found at src/database/proxy.rs:6
|
||||
|
||||
Vendored
+1
-1
@@ -73,7 +73,7 @@ max_request_size = 20_000_000 # in bytes
|
||||
# Enable jaeger to support monitoring and troubleshooting through jaeger.
|
||||
#allow_jaeger = false
|
||||
|
||||
#db_cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#cache_capacity = 1073741824 # in bytes, 1024 * 1024 * 1024
|
||||
#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time
|
||||
#log = "info,state_res=warn,rocket=off,_=off,sled=off"
|
||||
#workers = 4 # default: cpu core count * 2
|
||||
|
||||
+1
-1
@@ -56,4 +56,4 @@ services:
|
||||
# - homeserver
|
||||
|
||||
volumes:
|
||||
db:
|
||||
db:
|
||||
|
||||
@@ -46,7 +46,10 @@ where
|
||||
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
|
||||
|
||||
let url = reqwest_request.url().clone();
|
||||
let mut response = globals.reqwest_client().execute(reqwest_request).await?;
|
||||
let mut response = globals
|
||||
.reqwest_client()
|
||||
.execute(reqwest_request)
|
||||
.await?;
|
||||
|
||||
// reqwest::Response -> http::Response conversion
|
||||
let status = response.status();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{collections::BTreeMap, convert::TryInto, sync::Arc};
|
||||
|
||||
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
|
||||
use super::{State, DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
@@ -42,7 +42,7 @@ const GUEST_NAME_LENGTH: usize = 10;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_register_available_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_username_availability::Request<'_>>,
|
||||
) -> ConduitResult<get_username_availability::Response> {
|
||||
// Validate user id
|
||||
@@ -85,7 +85,7 @@ pub async fn get_register_available_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn register_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<register::Request<'_>>,
|
||||
) -> ConduitResult<register::Response> {
|
||||
if !db.globals.allow_registration() && !body.from_appservice {
|
||||
@@ -236,16 +236,6 @@ pub async fn register_route(
|
||||
|
||||
let room_id = RoomId::new(db.globals.server_name());
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let mut content = ruma::events::room::create::CreateEventContent::new(conduit_user.clone());
|
||||
content.federate = true;
|
||||
content.predecessor = None;
|
||||
@@ -263,7 +253,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 2. Make conduit bot join
|
||||
@@ -285,7 +274,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 3. Power levels
|
||||
@@ -310,7 +298,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4.1 Join Rules
|
||||
@@ -328,7 +315,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4.2 History Visibility
|
||||
@@ -348,7 +334,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4.3 Guest Access
|
||||
@@ -366,7 +351,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 6. Events implied by name and topic
|
||||
@@ -386,7 +370,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
@@ -403,7 +386,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// Room alias
|
||||
@@ -426,7 +408,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
db.rooms.set_alias(&alias, Some(&room_id), &db.globals)?;
|
||||
@@ -450,7 +431,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
@@ -470,7 +450,6 @@ pub async fn register_route(
|
||||
&user_id,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// Send welcome message
|
||||
@@ -489,7 +468,6 @@ pub async fn register_route(
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -518,7 +496,7 @@ pub async fn register_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn change_password_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<change_password::Request<'_>>,
|
||||
) -> ConduitResult<change_password::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -610,7 +588,7 @@ pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn deactivate_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<deactivate::Request<'_>>,
|
||||
) -> ConduitResult<deactivate::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -665,16 +643,6 @@ pub async fn deactivate_route(
|
||||
third_party_invite: None,
|
||||
};
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
@@ -686,7 +654,6 @@ pub async fn deactivate_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use regex::Regex;
|
||||
use ruma::{
|
||||
api::{
|
||||
@@ -21,7 +24,7 @@ use rocket::{delete, get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_alias_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_alias::Request<'_>>,
|
||||
) -> ConduitResult<create_alias::Response> {
|
||||
if db.rooms.id_from_alias(&body.room_alias)?.is_some() {
|
||||
@@ -42,7 +45,7 @@ pub async fn create_alias_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_alias_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_alias::Request<'_>>,
|
||||
) -> ConduitResult<delete_alias::Response> {
|
||||
db.rooms.set_alias(&body.room_alias, None, &db.globals)?;
|
||||
@@ -58,7 +61,7 @@ pub async fn delete_alias_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_alias_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_alias::Request<'_>>,
|
||||
) -> ConduitResult<get_alias::Response> {
|
||||
get_alias_helper(&db, &body.room_alias).await
|
||||
|
||||
+18
-15
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::backup::{
|
||||
@@ -18,7 +21,7 @@ use rocket::{delete, get, post, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_backup_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_backup::Request>,
|
||||
) -> ConduitResult<create_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -37,7 +40,7 @@ pub async fn create_backup_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_backup_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<update_backup::Request<'_>>,
|
||||
) -> ConduitResult<update_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -55,7 +58,7 @@ pub async fn update_backup_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_latest_backup_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_latest_backup::Request>,
|
||||
) -> ConduitResult<get_latest_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -83,7 +86,7 @@ pub async fn get_latest_backup_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_backup::Request<'_>>,
|
||||
) -> ConduitResult<get_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -110,7 +113,7 @@ pub async fn get_backup_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_backup::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -129,7 +132,7 @@ pub async fn delete_backup_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<add_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -163,7 +166,7 @@ pub async fn add_backup_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_sessions_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<add_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -195,7 +198,7 @@ pub async fn add_backup_key_sessions_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn add_backup_key_session_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<add_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<add_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -224,7 +227,7 @@ pub async fn add_backup_key_session_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -240,7 +243,7 @@ pub async fn get_backup_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_sessions_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -258,7 +261,7 @@ pub async fn get_backup_key_sessions_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_backup_key_session_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<get_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -280,7 +283,7 @@ pub async fn get_backup_key_session_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_backup_keys::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -303,7 +306,7 @@ pub async fn delete_backup_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_sessions_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_backup_key_sessions::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_key_sessions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -326,7 +329,7 @@ pub async fn delete_backup_key_sessions_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_backup_key_session_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_backup_key_session::Request<'_>>,
|
||||
) -> ConduitResult<delete_backup_key_session::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -22,7 +25,7 @@ use rocket::{get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_global_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -57,7 +60,7 @@ pub async fn set_global_account_data_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_room_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -89,7 +92,7 @@ pub async fn set_room_account_data_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_global_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -116,7 +119,7 @@ pub async fn get_global_account_data_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{error::ErrorKind, r0::context::get_context};
|
||||
use std::convert::TryFrom;
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::get;
|
||||
@@ -11,7 +12,7 @@ use rocket::get;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_context_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_context::Request<'_>>,
|
||||
) -> ConduitResult<get_context::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::{
|
||||
@@ -17,7 +20,7 @@ use rocket::{delete, get, post, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_devices_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_devices::Request>,
|
||||
) -> ConduitResult<get_devices::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -37,7 +40,7 @@ pub async fn get_devices_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_device_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_device::Request<'_>>,
|
||||
) -> ConduitResult<get_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -56,7 +59,7 @@ pub async fn get_device_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_device_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<update_device::Request<'_>>,
|
||||
) -> ConduitResult<update_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -82,7 +85,7 @@ pub async fn update_device_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_device_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_device::Request<'_>>,
|
||||
) -> ConduitResult<delete_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -136,7 +139,7 @@ pub async fn delete_device_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_devices_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_devices::Request<'_>>,
|
||||
) -> ConduitResult<delete_devices::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Result, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Result, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::{
|
||||
@@ -32,7 +35,7 @@ use rocket::{get, post, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_public_rooms_filtered::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms_filtered::Response> {
|
||||
get_public_rooms_filtered_helper(
|
||||
@@ -52,7 +55,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_public_rooms::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms::Response> {
|
||||
let response = get_public_rooms_filtered_helper(
|
||||
@@ -81,7 +84,7 @@ pub async fn get_public_rooms_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_room_visibility_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_room_visibility::Request<'_>>,
|
||||
) -> ConduitResult<set_room_visibility::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -111,7 +114,7 @@ pub async fn set_room_visibility_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_visibility_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_visibility::Request<'_>>,
|
||||
) -> ConduitResult<get_room_visibility::Response> {
|
||||
Ok(get_room_visibility::Response {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::SESSION_ID_LENGTH;
|
||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Database, Error, Result, Ruma};
|
||||
use super::{State, SESSION_ID_LENGTH};
|
||||
use crate::{utils, ConduitResult, Database, Error, Result, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -14,7 +14,10 @@ use ruma::{
|
||||
encryption::UnsignedDeviceInfo,
|
||||
DeviceId, DeviceKeyAlgorithm, UserId,
|
||||
};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::{get, post};
|
||||
@@ -25,7 +28,7 @@ use rocket::{get, post};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<upload_keys::Request>,
|
||||
) -> ConduitResult<upload_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -74,7 +77,7 @@ pub async fn upload_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_keys::Request<'_>>,
|
||||
) -> ConduitResult<get_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -95,7 +98,7 @@ pub async fn get_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn claim_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<claim_keys::Request>,
|
||||
) -> ConduitResult<claim_keys::Response> {
|
||||
let response = claim_keys_helper(&body.one_time_keys, &db)?;
|
||||
@@ -111,7 +114,7 @@ pub async fn claim_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signing_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<upload_signing_keys::Request<'_>>,
|
||||
) -> ConduitResult<upload_signing_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -174,7 +177,7 @@ pub async fn upload_signing_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upload_signatures_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<upload_signatures::Request>,
|
||||
) -> ConduitResult<upload_signatures::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -235,7 +238,7 @@ pub async fn upload_signatures_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_key_changes_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_key_changes::Request<'_>>,
|
||||
) -> ConduitResult<get_key_changes::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
use crate::{
|
||||
database::media::FileMeta, database::DatabaseGuard, utils, ConduitResult, Error, Ruma,
|
||||
};
|
||||
use super::State;
|
||||
use crate::{database::media::FileMeta, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
r0::media::{create_content, get_content, get_content_thumbnail, get_media_config},
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::{get, post};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
const MXC_LENGTH: usize = 32;
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/media/r0/config"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub async fn get_media_config_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
) -> ConduitResult<get_media_config::Response> {
|
||||
Ok(get_media_config::Response {
|
||||
upload_size: db.globals.max_request_size().into(),
|
||||
@@ -29,7 +28,7 @@ pub async fn get_media_config_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_content_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_content::Request<'_>>,
|
||||
) -> ConduitResult<create_content::Response> {
|
||||
let mxc = format!(
|
||||
@@ -67,7 +66,7 @@ pub async fn create_content_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_content::Request<'_>>,
|
||||
) -> ConduitResult<get_content::Response> {
|
||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||
@@ -120,7 +119,7 @@ pub async fn get_content_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_content_thumbnail_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_content_thumbnail::Request<'_>>,
|
||||
) -> ConduitResult<get_content_thumbnail::Response> {
|
||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::State;
|
||||
use crate::{
|
||||
client_server,
|
||||
database::DatabaseGuard,
|
||||
pdu::{PduBuilder, PduEvent},
|
||||
server_server, utils, ConduitResult, Database, Error, Result, Ruma,
|
||||
};
|
||||
@@ -44,7 +44,7 @@ use rocket::{get, post};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<join_room_by_id::Request<'_>>,
|
||||
) -> ConduitResult<join_room_by_id::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -65,18 +65,14 @@ pub async fn join_room_by_id_route(
|
||||
|
||||
servers.insert(body.room_id.server_name().to_owned());
|
||||
|
||||
let ret = join_room_by_id_helper(
|
||||
join_room_by_id_helper(
|
||||
&db,
|
||||
body.sender_user.as_ref(),
|
||||
&body.room_id,
|
||||
&servers,
|
||||
body.third_party_signed.as_ref(),
|
||||
)
|
||||
.await;
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
ret
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
@@ -85,7 +81,7 @@ pub async fn join_room_by_id_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn join_room_by_id_or_alias_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<join_room_by_id_or_alias::Request<'_>>,
|
||||
) -> ConduitResult<join_room_by_id_or_alias::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -139,7 +135,7 @@ pub async fn join_room_by_id_or_alias_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn leave_room_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<leave_room::Request<'_>>,
|
||||
) -> ConduitResult<leave_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -157,7 +153,7 @@ pub async fn leave_room_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn invite_user_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<invite_user::Request<'_>>,
|
||||
) -> ConduitResult<invite_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -177,7 +173,7 @@ pub async fn invite_user_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn kick_user_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<kick_user::Request<'_>>,
|
||||
) -> ConduitResult<kick_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -203,16 +199,6 @@ pub async fn kick_user_route(
|
||||
event.membership = ruma::events::room::member::MembershipState::Leave;
|
||||
// TODO: reason
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
@@ -224,11 +210,8 @@ pub async fn kick_user_route(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(kick_user::Response::new().into())
|
||||
@@ -240,7 +223,7 @@ pub async fn kick_user_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn ban_user_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<ban_user::Request<'_>>,
|
||||
) -> ConduitResult<ban_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -274,16 +257,6 @@ pub async fn ban_user_route(
|
||||
},
|
||||
)?;
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
@@ -295,11 +268,8 @@ pub async fn ban_user_route(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(ban_user::Response::new().into())
|
||||
@@ -311,7 +281,7 @@ pub async fn ban_user_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn unban_user_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<unban_user::Request<'_>>,
|
||||
) -> ConduitResult<unban_user::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -336,16 +306,6 @@ pub async fn unban_user_route(
|
||||
|
||||
event.membership = ruma::events::room::member::MembershipState::Leave;
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMember,
|
||||
@@ -357,11 +317,8 @@ pub async fn unban_user_route(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(unban_user::Response::new().into())
|
||||
@@ -373,7 +330,7 @@ pub async fn unban_user_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn forget_room_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<forget_room::Request<'_>>,
|
||||
) -> ConduitResult<forget_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -391,7 +348,7 @@ pub async fn forget_room_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_rooms_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<joined_rooms::Request>,
|
||||
) -> ConduitResult<joined_rooms::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -412,7 +369,7 @@ pub async fn joined_rooms_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_member_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_member_events::Request<'_>>,
|
||||
) -> ConduitResult<get_member_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -442,7 +399,7 @@ pub async fn get_member_events_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn joined_members_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<joined_members::Request<'_>>,
|
||||
) -> ConduitResult<joined_members::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -485,16 +442,6 @@ async fn join_room_by_id_helper(
|
||||
) -> ConduitResult<join_room_by_id::Response> {
|
||||
let sender_user = sender_user.expect("user is authenticated");
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
// Ask a remote server if we don't have this room
|
||||
if !db.rooms.exists(&room_id)? && room_id.server_name() != db.globals.server_name() {
|
||||
let mut make_join_response_and_server = Err(Error::BadServerResponse(
|
||||
@@ -698,12 +645,9 @@ async fn join_room_by_id_helper(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(join_room_by_id::Response::new(room_id.clone()).into())
|
||||
@@ -773,23 +717,13 @@ async fn validate_and_add_event_id(
|
||||
Ok((event_id, value))
|
||||
}
|
||||
|
||||
pub async fn invite_helper<'a>(
|
||||
pub async fn invite_helper(
|
||||
sender_user: &UserId,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
db: &Database,
|
||||
is_direct: bool,
|
||||
) -> Result<()> {
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
if user_id.server_name() != db.globals.server_name() {
|
||||
let prev_events = db
|
||||
.rooms
|
||||
@@ -925,8 +859,6 @@ pub async fn invite_helper<'a>(
|
||||
)
|
||||
.expect("event is valid, we just created it");
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
let invite_room_state = db.rooms.calculate_invite_state(&pdu)?;
|
||||
let response = db
|
||||
.sending
|
||||
@@ -966,6 +898,16 @@ pub async fn invite_helper<'a>(
|
||||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Origin field is invalid."))?;
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let pdu_id = server_server::handle_incoming_pdu(
|
||||
&origin,
|
||||
&event_id,
|
||||
@@ -986,6 +928,7 @@ pub async fn invite_helper<'a>(
|
||||
ErrorKind::InvalidParam,
|
||||
"Could not accept incoming PDU as timeline event.",
|
||||
))?;
|
||||
drop(mutex_lock);
|
||||
|
||||
for server in db
|
||||
.rooms
|
||||
@@ -1017,7 +960,6 @@ pub async fn invite_helper<'a>(
|
||||
&sender_user,
|
||||
room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
|
||||
use super::State;
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -22,22 +23,12 @@ use rocket::{get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_message_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<send_message_event::Request<'_>>,
|
||||
) -> ConduitResult<send_message_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_deref();
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
// Check if this is a new transaction id
|
||||
if let Some(response) =
|
||||
db.transaction_ids
|
||||
@@ -75,7 +66,6 @@ pub async fn send_message_event_route(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
db.transaction_ids.add_txnid(
|
||||
@@ -85,8 +75,6 @@ pub async fn send_message_event_route(
|
||||
event_id.as_bytes(),
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(send_message_event::Response::new(event_id).into())
|
||||
@@ -98,7 +86,7 @@ pub async fn send_message_event_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_message_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_message_events::Request<'_>>,
|
||||
) -> ConduitResult<get_message_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -64,7 +64,9 @@ pub use voip::*;
|
||||
use super::State;
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use {
|
||||
crate::ConduitResult, rocket::options, ruma::api::client::r0::to_device::send_event_to_device,
|
||||
crate::ConduitResult,
|
||||
rocket::{options, State},
|
||||
ruma::api::client::r0::to_device::send_event_to_device,
|
||||
};
|
||||
|
||||
pub const DEVICE_ID_LENGTH: usize = 10;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
|
||||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Ruma};
|
||||
use ruma::api::client::r0::presence::{get_presence, set_presence};
|
||||
use std::{convert::TryInto, time::Duration};
|
||||
use std::{convert::TryInto, sync::Arc, time::Duration};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::{get, put};
|
||||
@@ -11,7 +12,7 @@ use rocket::{get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_presence_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_presence::Request<'_>>,
|
||||
) -> ConduitResult<set_presence::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -52,7 +53,7 @@ pub async fn set_presence_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_presence_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_presence::Request<'_>>,
|
||||
) -> ConduitResult<get_presence::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
|
||||
use super::State;
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -9,10 +10,10 @@ use ruma::{
|
||||
events::EventType,
|
||||
serde::Raw,
|
||||
};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::{get, put};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "conduit_bin",
|
||||
@@ -20,7 +21,7 @@ use rocket::{get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_displayname_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_display_name::Request<'_>>,
|
||||
) -> ConduitResult<set_display_name::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -69,19 +70,9 @@ pub async fn set_displayname_route(
|
||||
})
|
||||
.filter_map(|r| r.ok())
|
||||
{
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let _ =
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &mutex_lock);
|
||||
let _ = db
|
||||
.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db);
|
||||
|
||||
// Presence update
|
||||
db.rooms.edus.update_presence(
|
||||
@@ -117,7 +108,7 @@ pub async fn set_displayname_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_displayname_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_display_name::Request<'_>>,
|
||||
) -> ConduitResult<get_display_name::Response> {
|
||||
Ok(get_display_name::Response {
|
||||
@@ -132,7 +123,7 @@ pub async fn get_displayname_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_avatar_url_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_avatar_url::Request<'_>>,
|
||||
) -> ConduitResult<set_avatar_url::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -181,19 +172,9 @@ pub async fn set_avatar_url_route(
|
||||
})
|
||||
.filter_map(|r| r.ok())
|
||||
{
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let _ =
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &mutex_lock);
|
||||
let _ = db
|
||||
.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db);
|
||||
|
||||
// Presence update
|
||||
db.rooms.edus.update_presence(
|
||||
@@ -229,7 +210,7 @@ pub async fn set_avatar_url_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_avatar_url_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_avatar_url::Request<'_>>,
|
||||
) -> ConduitResult<get_avatar_url::Response> {
|
||||
Ok(get_avatar_url::Response {
|
||||
@@ -244,7 +225,7 @@ pub async fn get_avatar_url_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_profile_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_profile::Request<'_>>,
|
||||
) -> ConduitResult<get_profile::Response> {
|
||||
if !db.users.exists(&body.user_id)? {
|
||||
|
||||
+14
-11
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -21,7 +24,7 @@ use rocket::{delete, get, post, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrules_all_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_pushrules_all::Request>,
|
||||
) -> ConduitResult<get_pushrules_all::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -46,7 +49,7 @@ pub async fn get_pushrules_all_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -100,7 +103,7 @@ pub async fn get_pushrule_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, req))]
|
||||
pub async fn set_pushrule_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
req: Ruma<set_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule::Response> {
|
||||
let sender_user = req.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -203,7 +206,7 @@ pub async fn set_pushrule_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_actions_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_pushrule_actions::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule_actions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -262,7 +265,7 @@ pub async fn get_pushrule_actions_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_actions_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_pushrule_actions::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule_actions::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -336,7 +339,7 @@ pub async fn set_pushrule_actions_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushrule_enabled_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_pushrule_enabled::Request<'_>>,
|
||||
) -> ConduitResult<get_pushrule_enabled::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -397,7 +400,7 @@ pub async fn get_pushrule_enabled_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushrule_enabled_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_pushrule_enabled::Request<'_>>,
|
||||
) -> ConduitResult<set_pushrule_enabled::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -476,7 +479,7 @@ pub async fn set_pushrule_enabled_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_pushrule_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_pushrule::Request<'_>>,
|
||||
) -> ConduitResult<delete_pushrule::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -545,7 +548,7 @@ pub async fn delete_pushrule_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_pushers_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_pushers::Request>,
|
||||
) -> ConduitResult<get_pushers::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -562,7 +565,7 @@ pub async fn get_pushers_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_pushers_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_pusher::Request>,
|
||||
) -> ConduitResult<set_pusher::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -8,10 +9,10 @@ use ruma::{
|
||||
receipt::ReceiptType,
|
||||
MilliSecondsSinceUnixEpoch,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::post;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "conduit_bin",
|
||||
@@ -19,7 +20,7 @@ use rocket::post;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn set_read_marker_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<set_read_marker::Request<'_>>,
|
||||
) -> ConduitResult<set_read_marker::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -86,7 +87,7 @@ pub async fn set_read_marker_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_receipt_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_receipt::Request<'_>>,
|
||||
) -> ConduitResult<create_receipt::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Ruma};
|
||||
use super::State;
|
||||
use crate::{pdu::PduBuilder, ConduitResult, Database, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::redact::redact_event,
|
||||
events::{room::redaction, EventType},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::put;
|
||||
@@ -15,21 +15,11 @@ use rocket::put;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn redact_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<redact_event::Request<'_>>,
|
||||
) -> ConduitResult<redact_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let event_id = db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomRedaction,
|
||||
@@ -44,11 +34,8 @@ pub async fn redact_event_route(
|
||||
&sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(redact_event::Response { event_id }.into())
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
client_server::invite_helper, database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Error,
|
||||
Ruma,
|
||||
};
|
||||
use super::State;
|
||||
use crate::{client_server::invite_helper, pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
@@ -26,23 +24,13 @@ use rocket::{get, post};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_room_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_room::Request<'_>>,
|
||||
) -> ConduitResult<create_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let room_id = RoomId::new(db.globals.server_name());
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let alias = body
|
||||
.room_alias_name
|
||||
.as_ref()
|
||||
@@ -79,7 +67,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 2. Let the room creator join
|
||||
@@ -101,7 +88,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 3. Power levels
|
||||
@@ -156,7 +142,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4. Events set by preset
|
||||
@@ -183,7 +168,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4.2 History Visibility
|
||||
@@ -201,7 +185,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 4.3 Guest Access
|
||||
@@ -227,7 +210,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// 5. Events listed in initial_state
|
||||
@@ -243,7 +225,7 @@ pub async fn create_room_route(
|
||||
}
|
||||
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &mutex_lock)?;
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db)?;
|
||||
}
|
||||
|
||||
// 6. Events implied by name and topic
|
||||
@@ -264,7 +246,6 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -283,12 +264,10 @@ pub async fn create_room_route(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
// 7. Events implied by invite (and TODO: invite_3pid)
|
||||
drop(mutex_lock);
|
||||
for user_id in &body.invite {
|
||||
let _ = invite_helper(sender_user, user_id, &room_id, &db, body.is_direct).await;
|
||||
}
|
||||
@@ -315,7 +294,7 @@ pub async fn create_room_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_room_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_event::Request<'_>>,
|
||||
) -> ConduitResult<get_room_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -343,7 +322,7 @@ pub async fn get_room_event_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn upgrade_room_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<upgrade_room::Request<'_>>,
|
||||
_room_id: String,
|
||||
) -> ConduitResult<upgrade_room::Response> {
|
||||
@@ -359,16 +338,6 @@ pub async fn upgrade_room_route(
|
||||
// Create a replacement room
|
||||
let replacement_room = RoomId::new(db.globals.server_name());
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
// Send a m.room.tombstone event to the old room to indicate that it is not intended to be used any further
|
||||
// Fail if the sender does not have the required permissions
|
||||
let tombstone_event_id = db.rooms.build_and_append_pdu(
|
||||
@@ -386,7 +355,6 @@ pub async fn upgrade_room_route(
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// Get the old room federations status
|
||||
@@ -427,7 +395,6 @@ pub async fn upgrade_room_route(
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// Join the new room
|
||||
@@ -449,7 +416,6 @@ pub async fn upgrade_room_route(
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
// Recommended transferable state events list from the specs
|
||||
@@ -483,7 +449,6 @@ pub async fn upgrade_room_route(
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -527,11 +492,8 @@ pub async fn upgrade_room_route(
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
// Return the replacement room id
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::api::client::{error::ErrorKind, r0::search::search_events};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::post;
|
||||
@@ -12,7 +14,7 @@ use std::collections::BTreeMap;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<search_events::Request<'_>>,
|
||||
) -> ConduitResult<search_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{State, DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
@@ -50,7 +52,7 @@ pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response>
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn login_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<login::Request<'_>>,
|
||||
) -> ConduitResult<login::Response> {
|
||||
// Validate login method
|
||||
@@ -167,7 +169,7 @@ pub async fn login_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<logout::Request>,
|
||||
) -> ConduitResult<logout::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -195,7 +197,7 @@ pub async fn logout_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn logout_all_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<logout_all::Request>,
|
||||
) -> ConduitResult<logout_all::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma,
|
||||
};
|
||||
use super::State;
|
||||
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
@@ -28,7 +27,7 @@ use rocket::{get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_key_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<send_state_event::Request<'_>>,
|
||||
) -> ConduitResult<send_state_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -54,7 +53,7 @@ pub async fn send_state_event_for_key_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_state_event_for_empty_key_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<send_state_event::Request<'_>>,
|
||||
) -> ConduitResult<send_state_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -80,7 +79,7 @@ pub async fn send_state_event_for_empty_key_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_state_events::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -127,7 +126,7 @@ pub async fn get_state_events_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_key_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -178,7 +177,7 @@ pub async fn get_state_events_for_key_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_state_events_for_empty_key_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -259,16 +258,6 @@ pub async fn send_state_event_for_key_helper(
|
||||
}
|
||||
}
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let event_id = db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type,
|
||||
@@ -280,7 +269,6 @@ pub async fn send_state_event_for_key_helper(
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
|
||||
Ok(event_id)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Result, Ruma, RumaResponse};
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Result, Ruma, RumaResponse};
|
||||
use log::error;
|
||||
use ruma::{
|
||||
api::client::r0::{sync::sync_events, uiaa::UiaaResponse},
|
||||
@@ -34,15 +35,13 @@ use rocket::{get, tokio};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn sync_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<sync_events::Request<'_>>,
|
||||
) -> std::result::Result<RumaResponse<sync_events::Response>, RumaResponse<UiaaResponse>> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
|
||||
let arc_db = Arc::new(db);
|
||||
|
||||
let mut rx = match arc_db
|
||||
let mut rx = match db
|
||||
.globals
|
||||
.sync_receivers
|
||||
.write()
|
||||
@@ -53,7 +52,7 @@ pub async fn sync_events_route(
|
||||
let (tx, rx) = tokio::sync::watch::channel(None);
|
||||
|
||||
tokio::spawn(sync_helper_wrapper(
|
||||
Arc::clone(&arc_db),
|
||||
Arc::clone(&db),
|
||||
sender_user.clone(),
|
||||
sender_device.clone(),
|
||||
body.since.clone(),
|
||||
@@ -69,7 +68,7 @@ pub async fn sync_events_route(
|
||||
let (tx, rx) = tokio::sync::watch::channel(None);
|
||||
|
||||
tokio::spawn(sync_helper_wrapper(
|
||||
Arc::clone(&arc_db),
|
||||
Arc::clone(&db),
|
||||
sender_user.clone(),
|
||||
sender_device.clone(),
|
||||
body.since.clone(),
|
||||
@@ -107,7 +106,7 @@ pub async fn sync_events_route(
|
||||
}
|
||||
|
||||
pub async fn sync_helper_wrapper(
|
||||
db: Arc<DatabaseGuard>,
|
||||
db: Arc<Database>,
|
||||
sender_user: UserId,
|
||||
sender_device: Box<DeviceId>,
|
||||
since: Option<String>,
|
||||
@@ -145,13 +144,11 @@ pub async fn sync_helper_wrapper(
|
||||
}
|
||||
}
|
||||
|
||||
drop(db);
|
||||
|
||||
let _ = tx.send(Some(r.map(|(r, _)| r.into())));
|
||||
}
|
||||
|
||||
async fn sync_helper(
|
||||
db: Arc<DatabaseGuard>,
|
||||
db: Arc<Database>,
|
||||
sender_user: UserId,
|
||||
sender_device: Box<DeviceId>,
|
||||
since: Option<String>,
|
||||
@@ -189,18 +186,6 @@ async fn sync_helper(
|
||||
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||
let room_id = room_id?;
|
||||
|
||||
// Get and drop the lock to wait for remaining operations to finish
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
drop(mutex_lock);
|
||||
|
||||
let mut non_timeline_pdus = db
|
||||
.rooms
|
||||
.pdus_until(&sender_user, &room_id, u64::MAX)
|
||||
@@ -351,7 +336,7 @@ async fn sync_helper(
|
||||
joined_member_count,
|
||||
invited_member_count,
|
||||
true,
|
||||
state_events,
|
||||
state_events
|
||||
)
|
||||
} else if !pdus_after_since || since_shortstatehash == Some(current_shortstatehash) {
|
||||
// No state changes
|
||||
@@ -653,19 +638,6 @@ async fn sync_helper(
|
||||
let mut left_rooms = BTreeMap::new();
|
||||
for result in db.rooms.rooms_left(&sender_user) {
|
||||
let (room_id, left_state_events) = result?;
|
||||
|
||||
// Get and drop the lock to wait for remaining operations to finish
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
drop(mutex_lock);
|
||||
|
||||
let left_count = db.rooms.get_left_count(&room_id, &sender_user)?;
|
||||
|
||||
// Left before last sync
|
||||
@@ -692,19 +664,6 @@ async fn sync_helper(
|
||||
let mut invited_rooms = BTreeMap::new();
|
||||
for result in db.rooms.rooms_invited(&sender_user) {
|
||||
let (room_id, invite_state_events) = result?;
|
||||
|
||||
// Get and drop the lock to wait for remaining operations to finish
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
drop(mutex_lock);
|
||||
|
||||
let invite_count = db.rooms.get_invite_count(&room_id, &sender_user)?;
|
||||
|
||||
// Invited before last sync
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::tag::{create_tag, delete_tag, get_tags},
|
||||
events::EventType,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::{delete, get, put};
|
||||
@@ -14,7 +15,7 @@ use rocket::{delete, get, put};
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn update_tag_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_tag::Request<'_>>,
|
||||
) -> ConduitResult<create_tag::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -51,7 +52,7 @@ pub async fn update_tag_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn delete_tag_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<delete_tag::Request<'_>>,
|
||||
) -> ConduitResult<delete_tag::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
@@ -85,7 +86,7 @@ pub async fn delete_tag_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_tags_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_tags::Request<'_>>,
|
||||
) -> ConduitResult<get_tags::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::client::{error::ErrorKind, r0::to_device::send_event_to_device},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
@@ -13,7 +16,7 @@ use rocket::put;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_event_to_device_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<send_event_to_device::Request<'_>>,
|
||||
) -> ConduitResult<send_event_to_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Ruma};
|
||||
use create_typing_event::Typing;
|
||||
use ruma::api::client::r0::typing::create_typing_event;
|
||||
|
||||
@@ -11,7 +14,7 @@ use rocket::put;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn create_typing_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_typing_event::Request<'_>>,
|
||||
) -> ConduitResult<create_typing_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::State;
|
||||
use crate::{ConduitResult, Database, Ruma};
|
||||
use ruma::api::client::r0::user_directory::search_users;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
@@ -10,7 +13,7 @@ use rocket::post;
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn search_users_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<search_users::Request<'_>>,
|
||||
) -> ConduitResult<search_users::Response> {
|
||||
let limit = u64::from(body.limit) as usize;
|
||||
|
||||
+96
-267
@@ -6,7 +6,6 @@ pub mod appservice;
|
||||
pub mod globals;
|
||||
pub mod key_backups;
|
||||
pub mod media;
|
||||
pub mod proxy;
|
||||
pub mod pusher;
|
||||
pub mod rooms;
|
||||
pub mod sending;
|
||||
@@ -19,39 +18,23 @@ use abstraction::DatabaseEngine;
|
||||
use directories::ProjectDirs;
|
||||
use log::error;
|
||||
use lru_cache::LruCache;
|
||||
use rocket::{
|
||||
futures::{channel::mpsc, stream::FuturesUnordered, StreamExt},
|
||||
outcome::IntoOutcome,
|
||||
request::{FromRequest, Request},
|
||||
try_outcome, State,
|
||||
};
|
||||
use rocket::futures::{channel::mpsc, stream::FuturesUnordered, StreamExt};
|
||||
use ruma::{DeviceId, ServerName, UserId};
|
||||
use serde::{de::IgnoredAny, Deserialize};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::HashMap,
|
||||
fs::{self, remove_dir_all},
|
||||
io::Write,
|
||||
ops::Deref,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use tokio::sync::{OwnedRwLockReadGuard, RwLock as TokioRwLock, Semaphore};
|
||||
|
||||
use self::proxy::ProxyConfig;
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
server_name: Box<ServerName>,
|
||||
database_path: String,
|
||||
#[serde(default = "default_db_cache_capacity")]
|
||||
db_cache_capacity: u32,
|
||||
#[serde(default = "default_sqlite_read_pool_size")]
|
||||
sqlite_read_pool_size: usize,
|
||||
#[serde(default = "false_fn")]
|
||||
sqlite_wal_clean_timer: bool,
|
||||
#[serde(default = "default_sqlite_wal_clean_second_interval")]
|
||||
sqlite_wal_clean_second_interval: u32,
|
||||
#[serde(default = "default_sqlite_wal_clean_second_timeout")]
|
||||
sqlite_wal_clean_second_timeout: u32,
|
||||
#[serde(default = "default_cache_capacity")]
|
||||
cache_capacity: u32,
|
||||
#[serde(default = "default_max_request_size")]
|
||||
max_request_size: u32,
|
||||
#[serde(default = "default_max_concurrent_requests")]
|
||||
@@ -64,36 +47,11 @@ pub struct Config {
|
||||
allow_federation: bool,
|
||||
#[serde(default = "false_fn")]
|
||||
pub allow_jaeger: bool,
|
||||
#[serde(default)]
|
||||
proxy: ProxyConfig,
|
||||
jwt_secret: Option<String>,
|
||||
#[serde(default = "Vec::new")]
|
||||
trusted_servers: Vec<Box<ServerName>>,
|
||||
#[serde(default = "default_log")]
|
||||
pub log: String,
|
||||
|
||||
#[serde(flatten)]
|
||||
catchall: BTreeMap<String, IgnoredAny>,
|
||||
}
|
||||
|
||||
const DEPRECATED_KEYS: &[&str] = &["cache_capacity"];
|
||||
|
||||
impl Config {
|
||||
pub fn warn_deprecated(&self) {
|
||||
let mut was_deprecated = false;
|
||||
for key in self
|
||||
.catchall
|
||||
.keys()
|
||||
.filter(|key| DEPRECATED_KEYS.iter().any(|s| s == key))
|
||||
{
|
||||
log::warn!("Config parameter {} is deprecated", key);
|
||||
was_deprecated = true;
|
||||
}
|
||||
|
||||
if was_deprecated {
|
||||
log::warn!("Read conduit documentation and check your configuration if any new configuration parameters should be adjusted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn false_fn() -> bool {
|
||||
@@ -104,22 +62,10 @@ fn true_fn() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_db_cache_capacity() -> u32 {
|
||||
fn default_cache_capacity() -> u32 {
|
||||
1024 * 1024 * 1024
|
||||
}
|
||||
|
||||
fn default_sqlite_read_pool_size() -> usize {
|
||||
num_cpus::get().max(1)
|
||||
}
|
||||
|
||||
fn default_sqlite_wal_clean_second_interval() -> u32 {
|
||||
60
|
||||
}
|
||||
|
||||
fn default_sqlite_wal_clean_second_timeout() -> u32 {
|
||||
2
|
||||
}
|
||||
|
||||
fn default_max_request_size() -> u32 {
|
||||
20 * 1024 * 1024 // Default to 20 MB
|
||||
}
|
||||
@@ -133,16 +79,12 @@ fn default_log() -> String {
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled")]
|
||||
pub type Engine = abstraction::sled::Engine;
|
||||
pub type Engine = abstraction::SledEngine;
|
||||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
pub type Engine = abstraction::rocksdb::Engine;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub type Engine = abstraction::sqlite::Engine;
|
||||
pub type Engine = abstraction::RocksDbEngine;
|
||||
|
||||
pub struct Database {
|
||||
_db: Arc<Engine>,
|
||||
pub globals: globals::Globals,
|
||||
pub users: users::Users,
|
||||
pub uiaa: uiaa::Uiaa,
|
||||
@@ -171,7 +113,7 @@ impl Database {
|
||||
}
|
||||
|
||||
/// Load an existing database or create a new one.
|
||||
pub async fn load_or_create(config: Config) -> Result<Arc<TokioRwLock<Self>>> {
|
||||
pub async fn load_or_create(config: Config) -> Result<Arc<Self>> {
|
||||
let builder = Engine::open(&config)?;
|
||||
|
||||
if config.max_request_size < 1024 {
|
||||
@@ -181,8 +123,7 @@ impl Database {
|
||||
let (admin_sender, admin_receiver) = mpsc::unbounded();
|
||||
let (sending_sender, sending_receiver) = mpsc::unbounded();
|
||||
|
||||
let db = Arc::new(TokioRwLock::from(Self {
|
||||
_db: builder.clone(),
|
||||
let db = Arc::new(Self {
|
||||
users: users::Users {
|
||||
userid_password: builder.open_tree("userid_password")?,
|
||||
userid_displayname: builder.open_tree("userid_displayname")?,
|
||||
@@ -249,7 +190,7 @@ impl Database {
|
||||
|
||||
eventid_outlierpdu: builder.open_tree("eventid_outlierpdu")?,
|
||||
prevevent_parent: builder.open_tree("prevevent_parent")?,
|
||||
pdu_cache: RwLock::new(LruCache::new(10_000)),
|
||||
pdu_cache: RwLock::new(LruCache::new(1_000_000)),
|
||||
},
|
||||
account_data: account_data::AccountData {
|
||||
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
||||
@@ -285,112 +226,100 @@ impl Database {
|
||||
globals: globals::Globals::load(
|
||||
builder.open_tree("global")?,
|
||||
builder.open_tree("server_signingkeys")?,
|
||||
config.clone(),
|
||||
config,
|
||||
)?,
|
||||
}));
|
||||
});
|
||||
|
||||
{
|
||||
let db = db.read().await;
|
||||
// MIGRATIONS
|
||||
// TODO: database versions of new dbs should probably not be 0
|
||||
if db.globals.database_version()? < 1 {
|
||||
for (roomserverid, _) in db.rooms.roomserverids.iter() {
|
||||
let mut parts = roomserverid.split(|&b| b == 0xff);
|
||||
let room_id = parts.next().expect("split always returns one element");
|
||||
let servername = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
error!("Migration: Invalid roomserverid in db.");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let mut serverroomid = servername.to_vec();
|
||||
serverroomid.push(0xff);
|
||||
serverroomid.extend_from_slice(room_id);
|
||||
|
||||
db.rooms.serverroomids.insert(&serverroomid, &[])?;
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(1)?;
|
||||
|
||||
println!("Migration: 0 -> 1 finished");
|
||||
}
|
||||
|
||||
if db.globals.database_version()? < 2 {
|
||||
// We accidentally inserted hashed versions of "" into the db instead of just ""
|
||||
for (userid, password) in db.users.userid_password.iter() {
|
||||
let password = utils::string_from_bytes(&password);
|
||||
|
||||
let empty_hashed_password = password.map_or(false, |password| {
|
||||
argon2::verify_encoded(&password, b"").unwrap_or(false)
|
||||
});
|
||||
|
||||
if empty_hashed_password {
|
||||
db.users.userid_password.insert(&userid, b"")?;
|
||||
}
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(2)?;
|
||||
|
||||
println!("Migration: 1 -> 2 finished");
|
||||
}
|
||||
|
||||
if db.globals.database_version()? < 3 {
|
||||
// Move media to filesystem
|
||||
for (key, content) in db.media.mediaid_file.iter() {
|
||||
if content.len() == 0 {
|
||||
// MIGRATIONS
|
||||
// TODO: database versions of new dbs should probably not be 0
|
||||
if db.globals.database_version()? < 1 {
|
||||
for (roomserverid, _) in db.rooms.roomserverids.iter() {
|
||||
let mut parts = roomserverid.split(|&b| b == 0xff);
|
||||
let room_id = parts.next().expect("split always returns one element");
|
||||
let servername = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
error!("Migration: Invalid roomserverid in db.");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let mut serverroomid = servername.to_vec();
|
||||
serverroomid.push(0xff);
|
||||
serverroomid.extend_from_slice(room_id);
|
||||
|
||||
let path = db.globals.get_media_file(&key);
|
||||
let mut file = fs::File::create(path)?;
|
||||
file.write_all(&content)?;
|
||||
db.media.mediaid_file.insert(&key, &[])?;
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(3)?;
|
||||
|
||||
println!("Migration: 2 -> 3 finished");
|
||||
db.rooms.serverroomids.insert(&serverroomid, &[])?;
|
||||
}
|
||||
|
||||
if db.globals.database_version()? < 4 {
|
||||
// Add federated users to db as deactivated
|
||||
for our_user in db.users.iter() {
|
||||
let our_user = our_user?;
|
||||
if db.users.is_deactivated(&our_user)? {
|
||||
continue;
|
||||
}
|
||||
for room in db.rooms.rooms_joined(&our_user) {
|
||||
for user in db.rooms.room_members(&room?) {
|
||||
let user = user?;
|
||||
if user.server_name() != db.globals.server_name() {
|
||||
println!("Migration: Creating user {}", user);
|
||||
db.users.create(&user, None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
db.globals.bump_database_version(1)?;
|
||||
|
||||
db.globals.bump_database_version(4)?;
|
||||
|
||||
println!("Migration: 3 -> 4 finished");
|
||||
}
|
||||
println!("Migration: 0 -> 1 finished");
|
||||
}
|
||||
|
||||
let guard = db.read().await;
|
||||
if db.globals.database_version()? < 2 {
|
||||
// We accidentally inserted hashed versions of "" into the db instead of just ""
|
||||
for (userid, password) in db.users.userid_password.iter() {
|
||||
let password = utils::string_from_bytes(&password);
|
||||
|
||||
let empty_hashed_password = password.map_or(false, |password| {
|
||||
argon2::verify_encoded(&password, b"").unwrap_or(false)
|
||||
});
|
||||
|
||||
if empty_hashed_password {
|
||||
db.users.userid_password.insert(&userid, b"")?;
|
||||
}
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(2)?;
|
||||
|
||||
println!("Migration: 1 -> 2 finished");
|
||||
}
|
||||
|
||||
if db.globals.database_version()? < 3 {
|
||||
// Move media to filesystem
|
||||
for (key, content) in db.media.mediaid_file.iter() {
|
||||
if content.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let path = db.globals.get_media_file(&key);
|
||||
let mut file = fs::File::create(path)?;
|
||||
file.write_all(&content)?;
|
||||
db.media.mediaid_file.insert(&key, &[])?;
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(3)?;
|
||||
|
||||
println!("Migration: 2 -> 3 finished");
|
||||
}
|
||||
|
||||
if db.globals.database_version()? < 4 {
|
||||
// Add federated users to db as deactivated
|
||||
for our_user in db.users.iter() {
|
||||
let our_user = our_user?;
|
||||
if db.users.is_deactivated(&our_user)? {
|
||||
continue;
|
||||
}
|
||||
for room in db.rooms.rooms_joined(&our_user) {
|
||||
for user in db.rooms.room_members(&room?) {
|
||||
let user = user?;
|
||||
if user.server_name() != db.globals.server_name() {
|
||||
println!("Migration: Creating user {}", user);
|
||||
db.users.create(&user, None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(4)?;
|
||||
|
||||
println!("Migration: 3 -> 4 finished");
|
||||
}
|
||||
|
||||
// This data is probably outdated
|
||||
guard.rooms.edus.presenceid_presence.clear()?;
|
||||
db.rooms.edus.presenceid_presence.clear()?;
|
||||
|
||||
guard.admin.start_handler(Arc::clone(&db), admin_receiver);
|
||||
guard
|
||||
.sending
|
||||
.start_handler(Arc::clone(&db), sending_receiver);
|
||||
|
||||
drop(guard);
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
Self::start_wal_clean_task(&db, &config).await;
|
||||
db.admin.start_handler(Arc::clone(&db), admin_receiver);
|
||||
db.sending.start_handler(Arc::clone(&db), sending_receiver);
|
||||
|
||||
Ok(db)
|
||||
}
|
||||
@@ -479,113 +408,13 @@ impl Database {
|
||||
.watch_prefix(&userid_bytes),
|
||||
);
|
||||
|
||||
futures.push(Box::pin(self.globals.rotate.watch()));
|
||||
|
||||
// Wait until one of them finds something
|
||||
futures.next().await;
|
||||
}
|
||||
|
||||
pub async fn flush(&self) -> Result<()> {
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
let res = self._db.flush();
|
||||
|
||||
log::debug!("flush: took {:?}", start.elapsed());
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub fn flush_wal(&self) -> Result<()> {
|
||||
self._db.flush_wal()
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub async fn start_wal_clean_task(lock: &Arc<TokioRwLock<Self>>, config: &Config) {
|
||||
use tokio::{
|
||||
select,
|
||||
signal::unix::{signal, SignalKind},
|
||||
time::{interval, timeout},
|
||||
};
|
||||
|
||||
use std::{
|
||||
sync::Weak,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
let weak: Weak<TokioRwLock<Database>> = Arc::downgrade(&lock);
|
||||
|
||||
let lock_timeout = Duration::from_secs(config.sqlite_wal_clean_second_timeout as u64);
|
||||
let timer_interval = Duration::from_secs(config.sqlite_wal_clean_second_interval as u64);
|
||||
let do_timer = config.sqlite_wal_clean_timer;
|
||||
|
||||
tokio::spawn(async move {
|
||||
let mut i = interval(timer_interval);
|
||||
let mut s = signal(SignalKind::hangup()).unwrap();
|
||||
|
||||
loop {
|
||||
select! {
|
||||
_ = i.tick(), if do_timer => {
|
||||
log::info!(target: "wal-trunc", "Timer ticked")
|
||||
}
|
||||
_ = s.recv() => {
|
||||
log::info!(target: "wal-trunc", "Received SIGHUP")
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(arc) = Weak::upgrade(&weak) {
|
||||
log::info!(target: "wal-trunc", "Rotating sync helpers...");
|
||||
// This actually creates a very small race condition between firing this and trying to acquire the subsequent write lock.
|
||||
// Though it is not a huge deal if the write lock doesn't "catch", as it'll harmlessly time out.
|
||||
arc.read().await.globals.rotate.fire();
|
||||
|
||||
log::info!(target: "wal-trunc", "Locking...");
|
||||
let guard = {
|
||||
if let Ok(guard) = timeout(lock_timeout, arc.write()).await {
|
||||
guard
|
||||
} else {
|
||||
log::info!(target: "wal-trunc", "Lock failed in timeout, canceled.");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
log::info!(target: "wal-trunc", "Locked, flushing...");
|
||||
let start = Instant::now();
|
||||
if let Err(e) = guard.flush_wal() {
|
||||
log::error!(target: "wal-trunc", "Errored: {}", e);
|
||||
} else {
|
||||
log::info!(target: "wal-trunc", "Flushed in {:?}", start.elapsed());
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DatabaseGuard(OwnedRwLockReadGuard<Database>);
|
||||
|
||||
impl Deref for DatabaseGuard {
|
||||
type Target = OwnedRwLockReadGuard<Database>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for DatabaseGuard {
|
||||
type Error = ();
|
||||
|
||||
async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
|
||||
let db = try_outcome!(req.guard::<State<'_, Arc<TokioRwLock<Database>>>>().await);
|
||||
|
||||
Ok(DatabaseGuard(Arc::clone(&db).read_owned().await)).or_forward(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<DatabaseGuard> for OwnedRwLockReadGuard<Database> {
|
||||
fn into(self) -> DatabaseGuard {
|
||||
DatabaseGuard(self)
|
||||
// noop while we don't use sled 1.0
|
||||
//self._db.flush_async().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+287
-10
@@ -1,21 +1,28 @@
|
||||
use super::Config;
|
||||
use crate::Result;
|
||||
|
||||
use crate::{utils, Result};
|
||||
use log::warn;
|
||||
use std::{future::Future, pin::Pin, sync::Arc};
|
||||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
pub mod rocksdb;
|
||||
use std::{collections::BTreeMap, sync::RwLock};
|
||||
|
||||
#[cfg(feature = "sled")]
|
||||
pub mod sled;
|
||||
pub struct SledEngine(sled::Db);
|
||||
#[cfg(feature = "sled")]
|
||||
pub struct SledEngineTree(sled::Tree);
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub mod sqlite;
|
||||
#[cfg(feature = "rocksdb")]
|
||||
pub struct RocksDbEngine(rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>);
|
||||
#[cfg(feature = "rocksdb")]
|
||||
pub struct RocksDbEngineTree<'a> {
|
||||
db: Arc<RocksDbEngine>,
|
||||
name: &'a str,
|
||||
watchers: RwLock<BTreeMap<Vec<u8>, Vec<tokio::sync::oneshot::Sender<()>>>>,
|
||||
}
|
||||
|
||||
pub trait DatabaseEngine: Sized {
|
||||
fn open(config: &Config) -> Result<Arc<Self>>;
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>>;
|
||||
fn flush(self: &Arc<Self>) -> Result<()>;
|
||||
}
|
||||
|
||||
pub trait Tree: Send + Sync {
|
||||
@@ -25,20 +32,20 @@ pub trait Tree: Send + Sync {
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()>;
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a>;
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a>;
|
||||
|
||||
fn iter_from<'a>(
|
||||
&'a self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a>;
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>;
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a>;
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a>;
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
|
||||
|
||||
@@ -50,3 +57,273 @@ pub trait Tree: Send + Sync {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled")]
|
||||
impl DatabaseEngine for SledEngine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(SledEngine(
|
||||
sled::Config::default()
|
||||
.path(&config.database_path)
|
||||
.cache_capacity(config.cache_capacity as u64)
|
||||
.use_compression(true)
|
||||
.open()?,
|
||||
)))
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> {
|
||||
Ok(Arc::new(SledEngineTree(self.0.open_tree(name)?)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled")]
|
||||
impl Tree for SledEngineTree {
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(self.0.get(key)?.map(|v| v.to_vec()))
|
||||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
self.0.insert(key, value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
self.0.remove(key)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a> {
|
||||
Box::new(
|
||||
self.0
|
||||
.iter()
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into())),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_from(
|
||||
&self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)>> {
|
||||
let iter = if backwards {
|
||||
self.0.range(..=from)
|
||||
} else {
|
||||
self.0.range(from..)
|
||||
};
|
||||
|
||||
let iter = iter
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into()));
|
||||
|
||||
if backwards {
|
||||
Box::new(iter.rev())
|
||||
} else {
|
||||
Box::new(iter)
|
||||
}
|
||||
}
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||
Ok(self
|
||||
.0
|
||||
.update_and_fetch(key, utils::increment)
|
||||
.map(|o| o.expect("increment always sets a value").to_vec())?)
|
||||
}
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a> {
|
||||
let iter = self
|
||||
.0
|
||||
.scan_prefix(prefix)
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into()));
|
||||
|
||||
Box::new(iter)
|
||||
}
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||
let prefix = prefix.to_vec();
|
||||
Box::pin(async move {
|
||||
self.0.watch_prefix(prefix).await;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
impl DatabaseEngine for RocksDbEngine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
let mut db_opts = rocksdb::Options::default();
|
||||
db_opts.create_if_missing(true);
|
||||
db_opts.set_max_open_files(16);
|
||||
db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
|
||||
db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy);
|
||||
db_opts.set_target_file_size_base(256 << 20);
|
||||
db_opts.set_write_buffer_size(256 << 20);
|
||||
|
||||
let mut block_based_options = rocksdb::BlockBasedOptions::default();
|
||||
block_based_options.set_block_size(512 << 10);
|
||||
db_opts.set_block_based_table_factory(&block_based_options);
|
||||
|
||||
let cfs = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::list_cf(
|
||||
&db_opts,
|
||||
&config.database_path,
|
||||
)
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut options = rocksdb::Options::default();
|
||||
options.set_merge_operator_associative("increment", utils::increment_rocksdb);
|
||||
|
||||
let db = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::open_cf_descriptors(
|
||||
&db_opts,
|
||||
&config.database_path,
|
||||
cfs.iter()
|
||||
.map(|name| rocksdb::ColumnFamilyDescriptor::new(name, options.clone())),
|
||||
)?;
|
||||
|
||||
Ok(Arc::new(RocksDbEngine(db)))
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> {
|
||||
let mut options = rocksdb::Options::default();
|
||||
options.set_merge_operator_associative("increment", utils::increment_rocksdb);
|
||||
|
||||
// Create if it doesn't exist
|
||||
let _ = self.0.create_cf(name, &options);
|
||||
|
||||
Ok(Arc::new(RocksDbEngineTree {
|
||||
name,
|
||||
db: Arc::clone(self),
|
||||
watchers: RwLock::new(BTreeMap::new()),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
impl RocksDbEngineTree<'_> {
|
||||
fn cf(&self) -> rocksdb::BoundColumnFamily<'_> {
|
||||
self.db.0.cf_handle(self.name).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rocksdb")]
|
||||
impl Tree for RocksDbEngineTree<'_> {
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(self.db.0.get_cf(self.cf(), key)?)
|
||||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
let watchers = self.watchers.read().unwrap();
|
||||
let mut triggered = Vec::new();
|
||||
|
||||
for length in 0..=key.len() {
|
||||
if watchers.contains_key(&key[..length]) {
|
||||
triggered.push(&key[..length]);
|
||||
}
|
||||
}
|
||||
|
||||
drop(watchers);
|
||||
|
||||
if !triggered.is_empty() {
|
||||
let mut watchers = self.watchers.write().unwrap();
|
||||
for prefix in triggered {
|
||||
if let Some(txs) = watchers.remove(prefix) {
|
||||
for tx in txs {
|
||||
let _ = tx.send(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(self.db.0.put_cf(self.cf(), key, value)?)
|
||||
}
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
Ok(self.db.0.delete_cf(self.cf(), key)?)
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a> {
|
||||
Box::new(
|
||||
self.db
|
||||
.0
|
||||
.iterator_cf(self.cf(), rocksdb::IteratorMode::Start),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_from<'a>(
|
||||
&'a self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a> {
|
||||
Box::new(self.db.0.iterator_cf(
|
||||
self.cf(),
|
||||
rocksdb::IteratorMode::From(
|
||||
from,
|
||||
if backwards {
|
||||
rocksdb::Direction::Reverse
|
||||
} else {
|
||||
rocksdb::Direction::Forward
|
||||
},
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||
let stats = rocksdb::perf::get_memory_usage_stats(Some(&[&self.db.0]), None).unwrap();
|
||||
dbg!(stats.mem_table_total);
|
||||
dbg!(stats.mem_table_unflushed);
|
||||
dbg!(stats.mem_table_readers_total);
|
||||
dbg!(stats.cache_total);
|
||||
// TODO: atomic?
|
||||
let old = self.get(key)?;
|
||||
let new = utils::increment(old.as_deref()).unwrap();
|
||||
self.insert(key, &new)?;
|
||||
Ok(new)
|
||||
}
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a> {
|
||||
Box::new(
|
||||
self.db
|
||||
.0
|
||||
.iterator_cf(
|
||||
self.cf(),
|
||||
rocksdb::IteratorMode::From(&prefix, rocksdb::Direction::Forward),
|
||||
)
|
||||
.take_while(move |(k, _)| k.starts_with(&prefix)),
|
||||
)
|
||||
}
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
|
||||
self.watchers
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(prefix.to_vec())
|
||||
.or_default()
|
||||
.push(tx);
|
||||
|
||||
Box::pin(async move {
|
||||
// Tx is never destroyed
|
||||
rx.await.unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
use super::super::Config;
|
||||
use crate::{utils, Result};
|
||||
|
||||
use std::{future::Future, pin::Pin, sync::Arc};
|
||||
|
||||
use super::{DatabaseEngine, Tree};
|
||||
|
||||
use std::{collections::BTreeMap, sync::RwLock};
|
||||
|
||||
pub struct Engine(rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>);
|
||||
|
||||
pub struct RocksDbEngineTree<'a> {
|
||||
db: Arc<Engine>,
|
||||
name: &'a str,
|
||||
watchers: RwLock<BTreeMap<Vec<u8>, Vec<tokio::sync::oneshot::Sender<()>>>>,
|
||||
}
|
||||
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
let mut db_opts = rocksdb::Options::default();
|
||||
db_opts.create_if_missing(true);
|
||||
db_opts.set_max_open_files(16);
|
||||
db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
|
||||
db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy);
|
||||
db_opts.set_target_file_size_base(256 << 20);
|
||||
db_opts.set_write_buffer_size(256 << 20);
|
||||
|
||||
let mut block_based_options = rocksdb::BlockBasedOptions::default();
|
||||
block_based_options.set_block_size(512 << 10);
|
||||
db_opts.set_block_based_table_factory(&block_based_options);
|
||||
|
||||
let cfs = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::list_cf(
|
||||
&db_opts,
|
||||
&config.database_path,
|
||||
)
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut options = rocksdb::Options::default();
|
||||
options.set_merge_operator_associative("increment", utils::increment_rocksdb);
|
||||
|
||||
let db = rocksdb::DBWithThreadMode::<rocksdb::MultiThreaded>::open_cf_descriptors(
|
||||
&db_opts,
|
||||
&config.database_path,
|
||||
cfs.iter()
|
||||
.map(|name| rocksdb::ColumnFamilyDescriptor::new(name, options.clone())),
|
||||
)?;
|
||||
|
||||
Ok(Arc::new(Engine(db)))
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> {
|
||||
let mut options = rocksdb::Options::default();
|
||||
options.set_merge_operator_associative("increment", utils::increment_rocksdb);
|
||||
|
||||
// Create if it doesn't exist
|
||||
let _ = self.0.create_cf(name, &options);
|
||||
|
||||
Ok(Arc::new(RocksDbEngineTree {
|
||||
name,
|
||||
db: Arc::clone(self),
|
||||
watchers: RwLock::new(BTreeMap::new()),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl RocksDbEngineTree<'_> {
|
||||
fn cf(&self) -> rocksdb::BoundColumnFamily<'_> {
|
||||
self.db.0.cf_handle(self.name).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Tree for RocksDbEngineTree<'_> {
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(self.db.0.get_cf(self.cf(), key)?)
|
||||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
let watchers = self.watchers.read().unwrap();
|
||||
let mut triggered = Vec::new();
|
||||
|
||||
for length in 0..=key.len() {
|
||||
if watchers.contains_key(&key[..length]) {
|
||||
triggered.push(&key[..length]);
|
||||
}
|
||||
}
|
||||
|
||||
drop(watchers);
|
||||
|
||||
if !triggered.is_empty() {
|
||||
let mut watchers = self.watchers.write().unwrap();
|
||||
for prefix in triggered {
|
||||
if let Some(txs) = watchers.remove(prefix) {
|
||||
for tx in txs {
|
||||
let _ = tx.send(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(self.db.0.put_cf(self.cf(), key, value)?)
|
||||
}
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
Ok(self.db.0.delete_cf(self.cf(), key)?)
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + Sync + 'a> {
|
||||
Box::new(
|
||||
self.db
|
||||
.0
|
||||
.iterator_cf(self.cf(), rocksdb::IteratorMode::Start),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_from<'a>(
|
||||
&'a self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a> {
|
||||
Box::new(self.db.0.iterator_cf(
|
||||
self.cf(),
|
||||
rocksdb::IteratorMode::From(
|
||||
from,
|
||||
if backwards {
|
||||
rocksdb::Direction::Reverse
|
||||
} else {
|
||||
rocksdb::Direction::Forward
|
||||
},
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||
let stats = rocksdb::perf::get_memory_usage_stats(Some(&[&self.db.0]), None).unwrap();
|
||||
dbg!(stats.mem_table_total);
|
||||
dbg!(stats.mem_table_unflushed);
|
||||
dbg!(stats.mem_table_readers_total);
|
||||
dbg!(stats.cache_total);
|
||||
// TODO: atomic?
|
||||
let old = self.get(key)?;
|
||||
let new = utils::increment(old.as_deref()).unwrap();
|
||||
self.insert(key, &new)?;
|
||||
Ok(new)
|
||||
}
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> {
|
||||
Box::new(
|
||||
self.db
|
||||
.0
|
||||
.iterator_cf(
|
||||
self.cf(),
|
||||
rocksdb::IteratorMode::From(&prefix, rocksdb::Direction::Forward),
|
||||
)
|
||||
.take_while(move |(k, _)| k.starts_with(&prefix)),
|
||||
)
|
||||
}
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
|
||||
self.watchers
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(prefix.to_vec())
|
||||
.or_default()
|
||||
.push(tx);
|
||||
|
||||
Box::pin(async move {
|
||||
// Tx is never destroyed
|
||||
rx.await.unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
use super::super::Config;
|
||||
use crate::{utils, Result};
|
||||
use log::warn;
|
||||
use std::{future::Future, pin::Pin, sync::Arc};
|
||||
|
||||
use super::{DatabaseEngine, Tree};
|
||||
|
||||
pub struct Engine(sled::Db);
|
||||
|
||||
pub struct SledEngineTree(sled::Tree);
|
||||
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(Engine(
|
||||
sled::Config::default()
|
||||
.path(&config.database_path)
|
||||
.cache_capacity(config.db_cache_capacity as u64)
|
||||
.use_compression(true)
|
||||
.open()?,
|
||||
)))
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> {
|
||||
Ok(Arc::new(SledEngineTree(self.0.open_tree(name)?)))
|
||||
}
|
||||
|
||||
fn flush(self: &Arc<Self>) -> Result<()> {
|
||||
Ok(()) // noop
|
||||
}
|
||||
}
|
||||
|
||||
impl Tree for SledEngineTree {
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(self.0.get(key)?.map(|v| v.to_vec()))
|
||||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
self.0.insert(key, value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
self.0.remove(key)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> {
|
||||
Box::new(
|
||||
self.0
|
||||
.iter()
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into())),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_from(
|
||||
&self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send> {
|
||||
let iter = if backwards {
|
||||
self.0.range(..=from)
|
||||
} else {
|
||||
self.0.range(from..)
|
||||
};
|
||||
|
||||
let iter = iter
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into()));
|
||||
|
||||
if backwards {
|
||||
Box::new(iter.rev())
|
||||
} else {
|
||||
Box::new(iter)
|
||||
}
|
||||
}
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||
Ok(self
|
||||
.0
|
||||
.update_and_fetch(key, utils::increment)
|
||||
.map(|o| o.expect("increment always sets a value").to_vec())?)
|
||||
}
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> {
|
||||
let iter = self
|
||||
.0
|
||||
.scan_prefix(prefix)
|
||||
.filter_map(|r| {
|
||||
if let Err(e) = &r {
|
||||
warn!("Error: {}", e);
|
||||
}
|
||||
r.ok()
|
||||
})
|
||||
.map(|(k, v)| (k.to_vec().into(), v.to_vec().into()));
|
||||
|
||||
Box::new(iter)
|
||||
}
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||
let prefix = prefix.to_vec();
|
||||
Box::pin(async move {
|
||||
self.0.watch_prefix(prefix).await;
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,438 +0,0 @@
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
future::Future,
|
||||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crate::{database::Config, Result};
|
||||
|
||||
use super::{DatabaseEngine, Tree};
|
||||
|
||||
use log::debug;
|
||||
|
||||
use crossbeam::channel::{bounded, Sender as ChannelSender};
|
||||
use parking_lot::{Mutex, MutexGuard, RwLock};
|
||||
use rusqlite::{params, Connection, DatabaseName::Main, OptionalExtension};
|
||||
|
||||
use tokio::sync::oneshot::Sender;
|
||||
|
||||
// const SQL_CREATE_TABLE: &str =
|
||||
// "CREATE TABLE IF NOT EXISTS {} {{ \"key\" BLOB PRIMARY KEY, \"value\" BLOB NOT NULL }}";
|
||||
// const SQL_SELECT: &str = "SELECT value FROM {} WHERE key = ?";
|
||||
// const SQL_INSERT: &str = "INSERT OR REPLACE INTO {} (key, value) VALUES (?, ?)";
|
||||
// const SQL_DELETE: &str = "DELETE FROM {} WHERE key = ?";
|
||||
// const SQL_SELECT_ITER: &str = "SELECT key, value FROM {}";
|
||||
// const SQL_SELECT_PREFIX: &str = "SELECT key, value FROM {} WHERE key LIKE ?||'%' ORDER BY key ASC";
|
||||
// const SQL_SELECT_ITER_FROM_FORWARDS: &str = "SELECT key, value FROM {} WHERE key >= ? ORDER BY ASC";
|
||||
// const SQL_SELECT_ITER_FROM_BACKWARDS: &str =
|
||||
// "SELECT key, value FROM {} WHERE key <= ? ORDER BY DESC";
|
||||
|
||||
struct Pool {
|
||||
writer: Mutex<Connection>,
|
||||
readers: Vec<Mutex<Connection>>,
|
||||
spill_tracker: Arc<()>,
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
pub const MILLI: Duration = Duration::from_millis(1);
|
||||
|
||||
enum HoldingConn<'a> {
|
||||
FromGuard(MutexGuard<'a, Connection>),
|
||||
FromOwned(Connection, Arc<()>),
|
||||
}
|
||||
|
||||
impl<'a> Deref for HoldingConn<'a> {
|
||||
type Target = Connection;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
HoldingConn::FromGuard(guard) => guard.deref(),
|
||||
HoldingConn::FromOwned(conn, _) => conn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Pool {
|
||||
fn new<P: AsRef<Path>>(path: P, num_readers: usize, cache_size: u32) -> Result<Self> {
|
||||
let writer = Mutex::new(Self::prepare_conn(&path, Some(cache_size))?);
|
||||
|
||||
let mut readers = Vec::new();
|
||||
|
||||
for _ in 0..num_readers {
|
||||
readers.push(Mutex::new(Self::prepare_conn(&path, Some(cache_size))?))
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
writer,
|
||||
readers,
|
||||
spill_tracker: Arc::new(()),
|
||||
path: path.as_ref().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
fn prepare_conn<P: AsRef<Path>>(path: P, cache_size: Option<u32>) -> Result<Connection> {
|
||||
let conn = Connection::open(path)?;
|
||||
|
||||
conn.pragma_update(Some(Main), "journal_mode", &"WAL".to_owned())?;
|
||||
|
||||
// conn.pragma_update(Some(Main), "wal_autocheckpoint", &250)?;
|
||||
|
||||
// conn.pragma_update(Some(Main), "wal_checkpoint", &"FULL".to_owned())?;
|
||||
|
||||
conn.pragma_update(Some(Main), "synchronous", &"OFF".to_owned())?;
|
||||
|
||||
if let Some(cache_kib) = cache_size {
|
||||
conn.pragma_update(Some(Main), "cache_size", &(-Into::<i64>::into(cache_kib)))?;
|
||||
}
|
||||
|
||||
Ok(conn)
|
||||
}
|
||||
|
||||
fn write_lock(&self) -> MutexGuard<'_, Connection> {
|
||||
self.writer.lock()
|
||||
}
|
||||
|
||||
fn read_lock(&self) -> HoldingConn<'_> {
|
||||
for r in &self.readers {
|
||||
if let Some(reader) = r.try_lock() {
|
||||
return HoldingConn::FromGuard(reader);
|
||||
}
|
||||
}
|
||||
|
||||
let spill_arc = self.spill_tracker.clone();
|
||||
let now_count = Arc::strong_count(&spill_arc) - 1 /* because one is held by the pool */;
|
||||
|
||||
log::warn!("read_lock: all readers locked, creating spillover reader...");
|
||||
|
||||
if now_count > 1 {
|
||||
log::warn!("read_lock: now {} spillover readers exist", now_count);
|
||||
}
|
||||
|
||||
let spilled = Self::prepare_conn(&self.path, None).unwrap();
|
||||
|
||||
return HoldingConn::FromOwned(spilled, spill_arc);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Engine {
|
||||
pool: Pool,
|
||||
}
|
||||
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
let pool = Pool::new(
|
||||
Path::new(&config.database_path).join("conduit.db"),
|
||||
config.sqlite_read_pool_size,
|
||||
config.db_cache_capacity / 1024, // bytes -> kb
|
||||
)?;
|
||||
|
||||
pool.write_lock()
|
||||
.execute("CREATE TABLE IF NOT EXISTS _noop (\"key\" INT)", params![])?;
|
||||
|
||||
let arc = Arc::new(Engine { pool });
|
||||
|
||||
Ok(arc)
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &str) -> Result<Arc<dyn Tree>> {
|
||||
self.pool.write_lock().execute(format!("CREATE TABLE IF NOT EXISTS {} ( \"key\" BLOB PRIMARY KEY, \"value\" BLOB NOT NULL )", name).as_str(), [])?;
|
||||
|
||||
Ok(Arc::new(SqliteTable {
|
||||
engine: Arc::clone(self),
|
||||
name: name.to_owned(),
|
||||
watchers: RwLock::new(BTreeMap::new()),
|
||||
}))
|
||||
}
|
||||
|
||||
fn flush(self: &Arc<Self>) -> Result<()> {
|
||||
self.pool
|
||||
.write_lock()
|
||||
.execute_batch(
|
||||
"
|
||||
PRAGMA synchronous=FULL;
|
||||
BEGIN;
|
||||
DELETE FROM _noop;
|
||||
INSERT INTO _noop VALUES (1);
|
||||
COMMIT;
|
||||
PRAGMA synchronous=OFF;
|
||||
",
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl Engine {
|
||||
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
||||
self.pool
|
||||
.write_lock()
|
||||
.execute_batch(
|
||||
"
|
||||
PRAGMA synchronous=FULL; PRAGMA wal_checkpoint=TRUNCATE;
|
||||
BEGIN;
|
||||
DELETE FROM _noop;
|
||||
INSERT INTO _noop VALUES (1);
|
||||
COMMIT;
|
||||
PRAGMA wal_checkpoint=PASSIVE; PRAGMA synchronous=OFF;
|
||||
",
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SqliteTable {
|
||||
engine: Arc<Engine>,
|
||||
name: String,
|
||||
watchers: RwLock<BTreeMap<Vec<u8>, Vec<Sender<()>>>>,
|
||||
}
|
||||
|
||||
type TupleOfBytes = (Vec<u8>, Vec<u8>);
|
||||
|
||||
impl SqliteTable {
|
||||
fn get_with_guard(&self, guard: &Connection, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(guard
|
||||
.prepare(format!("SELECT value FROM {} WHERE key = ?", self.name).as_str())?
|
||||
.query_row([key], |row| row.get(0))
|
||||
.optional()?)
|
||||
}
|
||||
|
||||
fn insert_with_guard(&self, guard: &Connection, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
guard.execute(
|
||||
format!(
|
||||
"INSERT INTO {} (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
||||
self.name
|
||||
)
|
||||
.as_str(),
|
||||
[key, value],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _iter_from_thread<F>(&self, f: F) -> Box<dyn Iterator<Item = TupleOfBytes> + Send>
|
||||
where
|
||||
F: (for<'a> FnOnce(&'a Connection, ChannelSender<TupleOfBytes>)) + Send + 'static,
|
||||
{
|
||||
let (s, r) = bounded::<TupleOfBytes>(5);
|
||||
|
||||
let engine = self.engine.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
let _ = f(&engine.pool.read_lock(), s);
|
||||
});
|
||||
|
||||
Box::new(r.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! iter_from_thread {
|
||||
($self:expr, $sql:expr, $param:expr) => {
|
||||
$self._iter_from_thread(move |guard, s| {
|
||||
let _ = guard
|
||||
.prepare($sql)
|
||||
.unwrap()
|
||||
.query_map($param, |row| Ok((row.get_unwrap(0), row.get_unwrap(1))))
|
||||
.unwrap()
|
||||
.map(|r| r.unwrap())
|
||||
.try_for_each(|bob| s.send(bob));
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
impl Tree for SqliteTable {
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
let guard = self.engine.pool.read_lock();
|
||||
|
||||
// let start = Instant::now();
|
||||
|
||||
let val = self.get_with_guard(&guard, key);
|
||||
|
||||
// debug!("get: took {:?}", start.elapsed());
|
||||
// debug!("get key: {:?}", &key)
|
||||
|
||||
val
|
||||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
let guard = self.engine.pool.write_lock();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
self.insert_with_guard(&guard, key, value)?;
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
if elapsed > MILLI {
|
||||
debug!("insert: took {:012?} : {}", elapsed, &self.name);
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
let watchers = self.watchers.read();
|
||||
let mut triggered = Vec::new();
|
||||
|
||||
for length in 0..=key.len() {
|
||||
if watchers.contains_key(&key[..length]) {
|
||||
triggered.push(&key[..length]);
|
||||
}
|
||||
}
|
||||
|
||||
drop(watchers);
|
||||
|
||||
if !triggered.is_empty() {
|
||||
let mut watchers = self.watchers.write();
|
||||
for prefix in triggered {
|
||||
if let Some(txs) = watchers.remove(prefix) {
|
||||
for tx in txs {
|
||||
let _ = tx.send(());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, key: &[u8]) -> Result<()> {
|
||||
let guard = self.engine.pool.write_lock();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
guard.execute(
|
||||
format!("DELETE FROM {} WHERE key = ?", self.name).as_str(),
|
||||
[key],
|
||||
)?;
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
if elapsed > MILLI {
|
||||
debug!("remove: took {:012?} : {}", elapsed, &self.name);
|
||||
}
|
||||
// debug!("remove key: {:?}", &key);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = TupleOfBytes> + Send + 'a> {
|
||||
let name = self.name.clone();
|
||||
iter_from_thread!(
|
||||
self,
|
||||
format!("SELECT key, value FROM {}", name).as_str(),
|
||||
params![]
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_from<'a>(
|
||||
&'a self,
|
||||
from: &[u8],
|
||||
backwards: bool,
|
||||
) -> Box<dyn Iterator<Item = TupleOfBytes> + Send + 'a> {
|
||||
let name = self.name.clone();
|
||||
let from = from.to_vec(); // TODO change interface?
|
||||
if backwards {
|
||||
iter_from_thread!(
|
||||
self,
|
||||
format!(
|
||||
"SELECT key, value FROM {} WHERE key <= ? ORDER BY key DESC",
|
||||
name
|
||||
)
|
||||
.as_str(),
|
||||
[from]
|
||||
)
|
||||
} else {
|
||||
iter_from_thread!(
|
||||
self,
|
||||
format!(
|
||||
"SELECT key, value FROM {} WHERE key >= ? ORDER BY key ASC",
|
||||
name
|
||||
)
|
||||
.as_str(),
|
||||
[from]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> {
|
||||
let guard = self.engine.pool.write_lock();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let old = self.get_with_guard(&guard, key)?;
|
||||
|
||||
let new =
|
||||
crate::utils::increment(old.as_deref()).expect("utils::increment always returns Some");
|
||||
|
||||
self.insert_with_guard(&guard, key, &new)?;
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
if elapsed > MILLI {
|
||||
debug!("increment: took {:012?} : {}", elapsed, &self.name);
|
||||
}
|
||||
// debug!("increment key: {:?}", &key);
|
||||
|
||||
Ok(new)
|
||||
}
|
||||
|
||||
fn scan_prefix<'a>(
|
||||
&'a self,
|
||||
prefix: Vec<u8>,
|
||||
) -> Box<dyn Iterator<Item = TupleOfBytes> + Send + 'a> {
|
||||
// let name = self.name.clone();
|
||||
// iter_from_thread!(
|
||||
// self,
|
||||
// format!(
|
||||
// "SELECT key, value FROM {} WHERE key BETWEEN ?1 AND ?1 || X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' ORDER BY key ASC",
|
||||
// name
|
||||
// )
|
||||
// .as_str(),
|
||||
// [prefix]
|
||||
// )
|
||||
Box::new(
|
||||
self.iter_from(&prefix, false)
|
||||
.take_while(move |(key, _)| key.starts_with(&prefix)),
|
||||
)
|
||||
}
|
||||
|
||||
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
|
||||
self.watchers
|
||||
.write()
|
||||
.entry(prefix.to_vec())
|
||||
.or_default()
|
||||
.push(tx);
|
||||
|
||||
Box::pin(async move {
|
||||
// Tx is never destroyed
|
||||
rx.await.unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
fn clear(&self) -> Result<()> {
|
||||
debug!("clear: running");
|
||||
self.engine
|
||||
.pool
|
||||
.write_lock()
|
||||
.execute(format!("DELETE FROM {}", self.name).as_str(), [])?;
|
||||
debug!("clear: ran");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// struct Pool<const NUM_READERS: usize> {
|
||||
// writer: Mutex<Connection>,
|
||||
// readers: [Mutex<Connection>; NUM_READERS],
|
||||
// }
|
||||
|
||||
// // then, to pick a reader:
|
||||
// for r in &pool.readers {
|
||||
// if let Ok(reader) = r.try_lock() {
|
||||
// // use reader
|
||||
// }
|
||||
// }
|
||||
// // none unlocked, pick the next reader
|
||||
// pool.readers[pool.counter.fetch_add(1, Relaxed) % NUM_READERS].lock()
|
||||
@@ -127,7 +127,7 @@ impl AccountData {
|
||||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
kind: &EventType,
|
||||
) -> Result<Option<(Vec<u8>, Vec<u8>)>> {
|
||||
) -> Result<Option<(Box<[u8]>, Box<[u8]>)>> {
|
||||
let mut prefix = room_id
|
||||
.map(|r| r.to_string())
|
||||
.unwrap_or_default()
|
||||
|
||||
+31
-56
@@ -10,7 +10,6 @@ use ruma::{
|
||||
events::{room::message, EventType},
|
||||
UserId,
|
||||
};
|
||||
use tokio::sync::{MutexGuard, RwLock, RwLockReadGuard};
|
||||
|
||||
pub enum AdminCommand {
|
||||
RegisterAppservice(serde_yaml::Value),
|
||||
@@ -26,97 +25,73 @@ pub struct Admin {
|
||||
impl Admin {
|
||||
pub fn start_handler(
|
||||
&self,
|
||||
db: Arc<RwLock<Database>>,
|
||||
db: Arc<Database>,
|
||||
mut receiver: mpsc::UnboundedReceiver<AdminCommand>,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
// TODO: Use futures when we have long admin commands
|
||||
//let mut futures = FuturesUnordered::new();
|
||||
|
||||
let guard = db.read().await;
|
||||
let conduit_user = UserId::try_from(format!("@conduit:{}", db.globals.server_name()))
|
||||
.expect("@conduit:server_name is valid");
|
||||
|
||||
let conduit_user =
|
||||
UserId::try_from(format!("@conduit:{}", guard.globals.server_name()))
|
||||
.expect("@conduit:server_name is valid");
|
||||
|
||||
let conduit_room = guard
|
||||
let conduit_room = db
|
||||
.rooms
|
||||
.id_from_alias(
|
||||
&format!("#admins:{}", guard.globals.server_name())
|
||||
&format!("#admins:{}", db.globals.server_name())
|
||||
.try_into()
|
||||
.expect("#admins:server_name is a valid room alias"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let conduit_room = match conduit_room {
|
||||
None => {
|
||||
warn!("Conduit instance does not have an #admins room. Logging to that room will not work. Restart Conduit after creating a user to fix this.");
|
||||
return;
|
||||
if conduit_room.is_none() {
|
||||
warn!("Conduit instance does not have an #admins room. Logging to that room will not work. Restart Conduit after creating a user to fix this.");
|
||||
}
|
||||
|
||||
let send_message = |message: message::MessageEventContent| {
|
||||
if let Some(conduit_room) = &conduit_room {
|
||||
db.rooms
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
content: serde_json::to_value(message)
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: None,
|
||||
redacts: None,
|
||||
},
|
||||
&conduit_user,
|
||||
&conduit_room,
|
||||
&db,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
Some(r) => r,
|
||||
};
|
||||
|
||||
drop(guard);
|
||||
|
||||
let send_message = |message: message::MessageEventContent,
|
||||
guard: RwLockReadGuard<'_, Database>,
|
||||
mutex_lock: &MutexGuard<'_, ()>| {
|
||||
guard
|
||||
.rooms
|
||||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: EventType::RoomMessage,
|
||||
content: serde_json::to_value(message)
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: None,
|
||||
redacts: None,
|
||||
},
|
||||
&conduit_user,
|
||||
&conduit_room,
|
||||
&guard,
|
||||
mutex_lock,
|
||||
)
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(event) = receiver.next() => {
|
||||
let guard = db.read().await;
|
||||
let mutex = Arc::clone(
|
||||
guard.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(conduit_room.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
match event {
|
||||
AdminCommand::RegisterAppservice(yaml) => {
|
||||
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||
db.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||
}
|
||||
AdminCommand::ListAppservices => {
|
||||
if let Ok(appservices) = guard.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||
if let Ok(appservices) = db.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||
let count = appservices.len();
|
||||
let output = format!(
|
||||
"Appservices ({}): {}",
|
||||
count,
|
||||
appservices.into_iter().filter_map(|r| r.ok()).collect::<Vec<_>>().join(", ")
|
||||
);
|
||||
send_message(message::MessageEventContent::text_plain(output), guard, &mutex_lock);
|
||||
send_message(message::MessageEventContent::text_plain(output));
|
||||
} else {
|
||||
send_message(message::MessageEventContent::text_plain("Failed to get appservices."), guard, &mutex_lock);
|
||||
send_message(message::MessageEventContent::text_plain("Failed to get appservices."));
|
||||
}
|
||||
}
|
||||
AdminCommand::SendMessage(message) => {
|
||||
send_message(message, guard, &mutex_lock);
|
||||
send_message(message);
|
||||
}
|
||||
}
|
||||
|
||||
drop(mutex_lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Appservice {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn iter_ids(&self) -> Result<impl Iterator<Item = Result<String>> + Send + '_> {
|
||||
pub fn iter_ids(&self) -> Result<impl Iterator<Item = Result<String>> + Send + Sync + '_> {
|
||||
Ok(self.id_appserviceregistrations.iter().map(|(id, _)| {
|
||||
utils::string_from_bytes(&id)
|
||||
.map_err(|_| Error::bad_database("Invalid id bytes in id_appserviceregistrations."))
|
||||
@@ -58,7 +58,7 @@ impl Appservice {
|
||||
|
||||
pub fn iter_all(
|
||||
&self,
|
||||
) -> Result<impl Iterator<Item = Result<(String, serde_yaml::Value)>> + '_ + Send> {
|
||||
) -> Result<impl Iterator<Item = Result<(String, serde_yaml::Value)>> + '_ + Send + Sync> {
|
||||
Ok(self.iter_ids()?.filter_map(|id| id.ok()).map(move |id| {
|
||||
Ok((
|
||||
id.clone(),
|
||||
|
||||
+7
-39
@@ -1,22 +1,18 @@
|
||||
use crate::{database::Config, utils, ConduitResult, Error, Result};
|
||||
use log::{error, info};
|
||||
use ruma::{
|
||||
api::{
|
||||
use ruma::{DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, UserId, api::{
|
||||
client::r0::sync::sync_events,
|
||||
federation::discovery::{ServerSigningKeys, VerifyKey},
|
||||
},
|
||||
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, ServerSigningKeyId, UserId,
|
||||
};
|
||||
}};
|
||||
use rustls::{ServerCertVerifier, WebPKIVerifier};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
fs,
|
||||
future::Future,
|
||||
path::PathBuf,
|
||||
sync::{Arc, RwLock},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use tokio::sync::{broadcast, Mutex, Semaphore};
|
||||
use tokio::sync::{Mutex, Semaphore};
|
||||
use trust_dns_resolver::TokioAsyncResolver;
|
||||
|
||||
use super::abstraction::Tree;
|
||||
@@ -40,7 +36,6 @@ pub struct Globals {
|
||||
pub bad_signature_ratelimiter: Arc<RwLock<BTreeMap<Vec<String>, RateLimitState>>>,
|
||||
pub servername_ratelimiter: Arc<RwLock<BTreeMap<Box<ServerName>, Arc<Semaphore>>>>,
|
||||
pub roomid_mutex: RwLock<BTreeMap<RoomId, Arc<Mutex<()>>>>,
|
||||
pub roomid_mutex_federation: RwLock<BTreeMap<RoomId, Arc<Mutex<()>>>>, // this lock will be held longer
|
||||
pub sync_receivers: RwLock<
|
||||
BTreeMap<
|
||||
(UserId, Box<DeviceId>),
|
||||
@@ -50,7 +45,6 @@ pub struct Globals {
|
||||
), // since, rx
|
||||
>,
|
||||
>,
|
||||
pub rotate: RotationHandler,
|
||||
}
|
||||
|
||||
struct MatrixServerVerifier {
|
||||
@@ -86,28 +80,6 @@ impl ServerCertVerifier for MatrixServerVerifier {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>);
|
||||
|
||||
impl RotationHandler {
|
||||
pub fn new() -> Self {
|
||||
let (s, r) = broadcast::channel::<()>(1);
|
||||
|
||||
Self(s, r)
|
||||
}
|
||||
|
||||
pub fn watch(&self) -> impl Future<Output = ()> {
|
||||
let mut r = self.0.subscribe();
|
||||
|
||||
async move {
|
||||
let _ = r.recv().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fire(&self) {
|
||||
let _ = self.0.send(());
|
||||
}
|
||||
}
|
||||
|
||||
impl Globals {
|
||||
pub fn load(
|
||||
globals: Arc<dyn Tree>,
|
||||
@@ -163,15 +135,13 @@ impl Globals {
|
||||
tlsconfig.root_store =
|
||||
rustls_native_certs::load_native_certs().expect("Error loading system certificates");
|
||||
|
||||
let mut reqwest_client_builder = reqwest::Client::builder()
|
||||
let reqwest_client = reqwest::Client::builder()
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.timeout(Duration::from_secs(60 * 3))
|
||||
.pool_max_idle_per_host(1)
|
||||
.use_preconfigured_tls(tlsconfig);
|
||||
if let Some(proxy) = config.proxy.to_proxy()? {
|
||||
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
|
||||
}
|
||||
let reqwest_client = reqwest_client_builder.build().unwrap();
|
||||
.use_preconfigured_tls(tlsconfig)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let jwt_decoding_key = config
|
||||
.jwt_secret
|
||||
@@ -194,9 +164,7 @@ impl Globals {
|
||||
bad_signature_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
|
||||
servername_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
|
||||
roomid_mutex: RwLock::new(BTreeMap::new()),
|
||||
roomid_mutex_federation: RwLock::new(BTreeMap::new()),
|
||||
sync_receivers: RwLock::new(BTreeMap::new()),
|
||||
rotate: RotationHandler::new(),
|
||||
};
|
||||
|
||||
fs::create_dir_all(s.get_media_folder())?;
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
use reqwest::{Proxy, Url};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Result;
|
||||
|
||||
/// ## Examples:
|
||||
/// - No proxy (default):
|
||||
/// ```toml
|
||||
/// proxy ="none"
|
||||
/// ```
|
||||
/// - Global proxy
|
||||
/// ```toml
|
||||
/// [proxy]
|
||||
/// global = { url = "socks5h://localhost:9050" }
|
||||
/// ```
|
||||
/// - Proxy some domains
|
||||
/// ```toml
|
||||
/// [proxy]
|
||||
/// [[proxy.by_domain]]
|
||||
/// url = "socks5h://localhost:9050"
|
||||
/// include = ["*.onion", "matrix.myspecial.onion"]
|
||||
/// exclude = ["*.myspecial.onion"]
|
||||
/// ```
|
||||
/// ## Include vs. Exclude
|
||||
/// If include is an empty list, it is assumed to be `["*"]`.
|
||||
///
|
||||
/// If a domain matches both the exclude and include list, the proxy will only be used if it was
|
||||
/// included because of a more specific rule than it was excluded. In the above example, the proxy
|
||||
/// would be used for `ordinary.onion`, `matrix.myspecial.onion`, but not `hello.myspecial.onion`.
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ProxyConfig {
|
||||
None,
|
||||
Global {
|
||||
#[serde(deserialize_with = "crate::utils::deserialize_from_str")]
|
||||
url: Url,
|
||||
},
|
||||
ByDomain(Vec<PartialProxyConfig>),
|
||||
}
|
||||
impl ProxyConfig {
|
||||
pub fn to_proxy(&self) -> Result<Option<Proxy>> {
|
||||
Ok(match self.clone() {
|
||||
ProxyConfig::None => None,
|
||||
ProxyConfig::Global { url } => Some(Proxy::all(url)?),
|
||||
ProxyConfig::ByDomain(proxies) => Some(Proxy::custom(move |url| {
|
||||
proxies.iter().find_map(|proxy| proxy.for_url(url)).cloned() // first matching proxy
|
||||
})),
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Default for ProxyConfig {
|
||||
fn default() -> Self {
|
||||
ProxyConfig::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct PartialProxyConfig {
|
||||
#[serde(deserialize_with = "crate::utils::deserialize_from_str")]
|
||||
url: Url,
|
||||
#[serde(default)]
|
||||
include: Vec<WildCardedDomain>,
|
||||
#[serde(default)]
|
||||
exclude: Vec<WildCardedDomain>,
|
||||
}
|
||||
impl PartialProxyConfig {
|
||||
pub fn for_url(&self, url: &Url) -> Option<&Url> {
|
||||
let domain = url.domain()?;
|
||||
let mut included_because = None; // most specific reason it was included
|
||||
let mut excluded_because = None; // most specific reason it was excluded
|
||||
if self.include.is_empty() {
|
||||
// treat empty include list as `*`
|
||||
included_because = Some(&WildCardedDomain::WildCard)
|
||||
}
|
||||
for wc_domain in &self.include {
|
||||
if wc_domain.matches(domain) {
|
||||
match included_because {
|
||||
Some(prev) if !wc_domain.more_specific_than(prev) => (),
|
||||
_ => included_because = Some(wc_domain),
|
||||
}
|
||||
}
|
||||
}
|
||||
for wc_domain in &self.exclude {
|
||||
if wc_domain.matches(domain) {
|
||||
match excluded_because {
|
||||
Some(prev) if !wc_domain.more_specific_than(prev) => (),
|
||||
_ => excluded_because = Some(wc_domain),
|
||||
}
|
||||
}
|
||||
}
|
||||
match (included_because, excluded_because) {
|
||||
(Some(a), Some(b)) if a.more_specific_than(b) => Some(&self.url), // included for a more specific reason than excluded
|
||||
(Some(_), None) => Some(&self.url),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A domain name, that optionally allows a * as its first subdomain.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum WildCardedDomain {
|
||||
WildCard,
|
||||
WildCarded(String),
|
||||
Exact(String),
|
||||
}
|
||||
impl WildCardedDomain {
|
||||
pub fn matches(&self, domain: &str) -> bool {
|
||||
match self {
|
||||
WildCardedDomain::WildCard => true,
|
||||
WildCardedDomain::WildCarded(d) => domain.ends_with(d),
|
||||
WildCardedDomain::Exact(d) => domain == d,
|
||||
}
|
||||
}
|
||||
pub fn more_specific_than(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(WildCardedDomain::WildCard, WildCardedDomain::WildCard) => false,
|
||||
(_, WildCardedDomain::WildCard) => true,
|
||||
(WildCardedDomain::Exact(a), WildCardedDomain::WildCarded(_)) => other.matches(a),
|
||||
(WildCardedDomain::WildCarded(a), WildCardedDomain::WildCarded(b)) => {
|
||||
a != b && a.ends_with(b)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::str::FromStr for WildCardedDomain {
|
||||
type Err = std::convert::Infallible;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
// maybe do some domain validation?
|
||||
Ok(if s.starts_with("*.") {
|
||||
WildCardedDomain::WildCarded(s[1..].to_owned())
|
||||
} else if s == "*" {
|
||||
WildCardedDomain::WildCarded("".to_owned())
|
||||
} else {
|
||||
WildCardedDomain::Exact(s.to_owned())
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<'de> serde::de::Deserialize<'de> for WildCardedDomain {
|
||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||
where
|
||||
D: serde::de::Deserializer<'de>,
|
||||
{
|
||||
crate::utils::deserialize_from_str(deserializer)
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ impl PushData {
|
||||
pub fn get_pusher_senderkeys<'a>(
|
||||
&'a self,
|
||||
sender: &UserId,
|
||||
) -> impl Iterator<Item = Vec<u8>> + 'a {
|
||||
) -> impl Iterator<Item = Box<[u8]>> + 'a {
|
||||
let mut prefix = sender.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
||||
|
||||
+8
-25
@@ -2,7 +2,6 @@ mod edus;
|
||||
|
||||
pub use edus::RoomEdus;
|
||||
use member::MembershipState;
|
||||
use tokio::sync::MutexGuard;
|
||||
|
||||
use crate::{pdu::PduBuilder, utils, Database, Error, PduEvent, Result};
|
||||
use log::{debug, error, warn};
|
||||
@@ -21,12 +20,7 @@ use ruma::{
|
||||
state_res::{self, Event, RoomVersion, StateMap},
|
||||
uint, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
mem,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, convert::{TryFrom, TryInto}, mem, sync::{Arc, RwLock}};
|
||||
|
||||
use super::{abstraction::Tree, admin::AdminCommand, pusher};
|
||||
|
||||
@@ -1088,13 +1082,13 @@ impl Rooms {
|
||||
.scan_prefix(old_shortstatehash.clone())
|
||||
// Chop the old_shortstatehash out leaving behind the short state key
|
||||
.map(|(k, v)| (k[old_shortstatehash.len()..].to_vec(), v))
|
||||
.collect::<HashMap<Vec<u8>, Vec<u8>>>()
|
||||
.collect::<HashMap<Vec<u8>, Box<[u8]>>>()
|
||||
} else {
|
||||
HashMap::new()
|
||||
};
|
||||
|
||||
if let Some(state_key) = &new_pdu.state_key {
|
||||
let mut new_state: HashMap<Vec<u8>, Vec<u8>> = old_state;
|
||||
let mut new_state: HashMap<Vec<u8>, Box<[u8]>> = old_state;
|
||||
|
||||
let mut new_state_key = new_pdu.kind.as_ref().as_bytes().to_vec();
|
||||
new_state_key.push(0xff);
|
||||
@@ -1210,7 +1204,6 @@ impl Rooms {
|
||||
sender: &UserId,
|
||||
room_id: &RoomId,
|
||||
db: &Database,
|
||||
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room mutex
|
||||
) -> Result<EventId> {
|
||||
let PduBuilder {
|
||||
event_type,
|
||||
@@ -1220,6 +1213,7 @@ impl Rooms {
|
||||
redacts,
|
||||
} = pdu_builder;
|
||||
|
||||
// TODO: Make sure this isn't called twice in parallel
|
||||
let prev_events = self
|
||||
.get_pdu_leaves(&room_id)?
|
||||
.into_iter()
|
||||
@@ -1459,7 +1453,7 @@ impl Rooms {
|
||||
&'a self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> impl Iterator<Item = Result<(Vec<u8>, PduEvent)>> + 'a {
|
||||
) -> impl Iterator<Item = Result<(Box<[u8]>, PduEvent)>> + 'a {
|
||||
self.pdus_since(user_id, room_id, 0)
|
||||
}
|
||||
|
||||
@@ -1471,7 +1465,7 @@ impl Rooms {
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
since: u64,
|
||||
) -> impl Iterator<Item = Result<(Vec<u8>, PduEvent)>> + 'a {
|
||||
) -> impl Iterator<Item = Result<(Box<[u8]>, PduEvent)>> + 'a {
|
||||
let mut prefix = room_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
||||
@@ -1500,7 +1494,7 @@ impl Rooms {
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
until: u64,
|
||||
) -> impl Iterator<Item = Result<(Vec<u8>, PduEvent)>> + 'a {
|
||||
) -> impl Iterator<Item = Result<(Box<[u8]>, PduEvent)>> + 'a {
|
||||
// Create the first part of the full pdu id
|
||||
let mut prefix = room_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
@@ -1532,7 +1526,7 @@ impl Rooms {
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
from: u64,
|
||||
) -> impl Iterator<Item = Result<(Vec<u8>, PduEvent)>> + 'a {
|
||||
) -> impl Iterator<Item = Result<(Box<[u8]>, PduEvent)>> + 'a {
|
||||
// Create the first part of the full pdu id
|
||||
let mut prefix = room_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
@@ -1793,16 +1787,6 @@ impl Rooms {
|
||||
db,
|
||||
)?;
|
||||
} else {
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
self.room_state_get(room_id, &EventType::RoomMember, &user_id.to_string())?
|
||||
.ok_or(Error::BadRequest(
|
||||
@@ -1830,7 +1814,6 @@ impl Rooms {
|
||||
user_id,
|
||||
room_id,
|
||||
db,
|
||||
&mutex_lock,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
||||
+16
-41
@@ -30,10 +30,7 @@ use ruma::{
|
||||
receipt::ReceiptType,
|
||||
MilliSecondsSinceUnixEpoch, ServerName, UInt, UserId,
|
||||
};
|
||||
use tokio::{
|
||||
select,
|
||||
sync::{RwLock, Semaphore},
|
||||
};
|
||||
use tokio::{select, sync::Semaphore};
|
||||
|
||||
use super::abstraction::Tree;
|
||||
|
||||
@@ -93,11 +90,7 @@ enum TransactionStatus {
|
||||
}
|
||||
|
||||
impl Sending {
|
||||
pub fn start_handler(
|
||||
&self,
|
||||
db: Arc<RwLock<Database>>,
|
||||
mut receiver: mpsc::UnboundedReceiver<Vec<u8>>,
|
||||
) {
|
||||
pub fn start_handler(&self, db: Arc<Database>, mut receiver: mpsc::UnboundedReceiver<Vec<u8>>) {
|
||||
tokio::spawn(async move {
|
||||
let mut futures = FuturesUnordered::new();
|
||||
|
||||
@@ -105,12 +98,8 @@ impl Sending {
|
||||
|
||||
// Retry requests we could not finish yet
|
||||
let mut initial_transactions = HashMap::<OutgoingKind, Vec<SendingEventType>>::new();
|
||||
|
||||
let guard = db.read().await;
|
||||
|
||||
for (key, outgoing_kind, event) in
|
||||
guard
|
||||
.sending
|
||||
db.sending
|
||||
.servercurrentevents
|
||||
.iter()
|
||||
.filter_map(|(key, _)| {
|
||||
@@ -128,23 +117,17 @@ impl Sending {
|
||||
"Dropping some current events: {:?} {:?} {:?}",
|
||||
key, outgoing_kind, event
|
||||
);
|
||||
guard.sending.servercurrentevents.remove(&key).unwrap();
|
||||
db.sending.servercurrentevents.remove(&key).unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
entry.push(event);
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
for (outgoing_kind, events) in initial_transactions {
|
||||
current_transaction_status
|
||||
.insert(outgoing_kind.get_prefix(), TransactionStatus::Running);
|
||||
futures.push(Self::handle_events(
|
||||
outgoing_kind.clone(),
|
||||
events,
|
||||
Arc::clone(&db),
|
||||
));
|
||||
futures.push(Self::handle_events(outgoing_kind.clone(), events, &db));
|
||||
}
|
||||
|
||||
loop {
|
||||
@@ -152,17 +135,15 @@ impl Sending {
|
||||
Some(response) = futures.next() => {
|
||||
match response {
|
||||
Ok(outgoing_kind) => {
|
||||
let guard = db.read().await;
|
||||
|
||||
let prefix = outgoing_kind.get_prefix();
|
||||
for (key, _) in guard.sending.servercurrentevents
|
||||
for (key, _) in db.sending.servercurrentevents
|
||||
.scan_prefix(prefix.clone())
|
||||
{
|
||||
guard.sending.servercurrentevents.remove(&key).unwrap();
|
||||
db.sending.servercurrentevents.remove(&key).unwrap();
|
||||
}
|
||||
|
||||
// Find events that have been added since starting the last request
|
||||
let new_events = guard.sending.servernamepduids
|
||||
let new_events = db.sending.servernamepduids
|
||||
.scan_prefix(prefix.clone())
|
||||
.map(|(k, _)| {
|
||||
SendingEventType::Pdu(k[prefix.len()..].to_vec())
|
||||
@@ -180,19 +161,17 @@ impl Sending {
|
||||
SendingEventType::Pdu(b) |
|
||||
SendingEventType::Edu(b) => {
|
||||
current_key.extend_from_slice(&b);
|
||||
guard.sending.servercurrentevents.insert(¤t_key, &[]).unwrap();
|
||||
guard.sending.servernamepduids.remove(¤t_key).unwrap();
|
||||
db.sending.servercurrentevents.insert(¤t_key, &[]).unwrap();
|
||||
db.sending.servernamepduids.remove(¤t_key).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
futures.push(
|
||||
Self::handle_events(
|
||||
outgoing_kind.clone(),
|
||||
new_events,
|
||||
Arc::clone(&db),
|
||||
&db,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
@@ -213,15 +192,13 @@ impl Sending {
|
||||
},
|
||||
Some(key) = receiver.next() => {
|
||||
if let Ok((outgoing_kind, event)) = Self::parse_servercurrentevent(&key) {
|
||||
let guard = db.read().await;
|
||||
|
||||
if let Ok(Some(events)) = Self::select_events(
|
||||
&outgoing_kind,
|
||||
vec![(event, key)],
|
||||
&mut current_transaction_status,
|
||||
&guard
|
||||
&db
|
||||
) {
|
||||
futures.push(Self::handle_events(outgoing_kind, events, Arc::clone(&db)));
|
||||
futures.push(Self::handle_events(outgoing_kind, events, &db));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +357,7 @@ impl Sending {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn send_push_pdu(&self, pdu_id: &[u8], senderkey: Vec<u8>) -> Result<()> {
|
||||
pub fn send_push_pdu(&self, pdu_id: &[u8], senderkey: Box<[u8]>) -> Result<()> {
|
||||
let mut key = b"$".to_vec();
|
||||
key.extend_from_slice(&senderkey);
|
||||
key.push(0xff);
|
||||
@@ -426,10 +403,8 @@ impl Sending {
|
||||
async fn handle_events(
|
||||
kind: OutgoingKind,
|
||||
events: Vec<SendingEventType>,
|
||||
db: Arc<RwLock<Database>>,
|
||||
db: &Database,
|
||||
) -> std::result::Result<OutgoingKind, (OutgoingKind, Error)> {
|
||||
let db = db.read().await;
|
||||
|
||||
match &kind {
|
||||
OutgoingKind::Appservice(server) => {
|
||||
let mut pdu_jsons = Vec::new();
|
||||
@@ -568,7 +543,7 @@ impl Sending {
|
||||
&pusher,
|
||||
rules_for_user,
|
||||
&pdu,
|
||||
&db,
|
||||
db,
|
||||
)
|
||||
.await
|
||||
.map(|_response| kind.clone())
|
||||
|
||||
@@ -35,12 +35,6 @@ pub enum Error {
|
||||
#[from]
|
||||
source: rocksdb::Error,
|
||||
},
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[error("There was a problem with the connection to the sqlite database: {source}")]
|
||||
SqliteError {
|
||||
#[from]
|
||||
source: rusqlite::Error,
|
||||
},
|
||||
#[error("Could not generate an image.")]
|
||||
ImageError {
|
||||
#[from]
|
||||
|
||||
+13
-18
@@ -30,11 +30,10 @@ use rocket::{
|
||||
},
|
||||
routes, Request,
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::span;
|
||||
use tracing_subscriber::{prelude::*, Registry};
|
||||
|
||||
fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<rocket::Build> {
|
||||
fn setup_rocket(config: Figment, data: Arc<Database>) -> rocket::Rocket<rocket::Build> {
|
||||
rocket::custom(config)
|
||||
.manage(data)
|
||||
.mount(
|
||||
@@ -194,14 +193,13 @@ async fn main() {
|
||||
)
|
||||
.merge(Env::prefixed("CONDUIT_").global());
|
||||
|
||||
std::env::set_var("RUST_LOG", "warn");
|
||||
|
||||
let config = raw_config
|
||||
.extract::<Config>()
|
||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||
|
||||
let mut _span: Option<span::Span> = None;
|
||||
let mut _enter: Option<span::Entered<'_>> = None;
|
||||
let db = Database::load_or_create(config.clone())
|
||||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
if config.allow_jaeger {
|
||||
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||
@@ -211,21 +209,18 @@ async fn main() {
|
||||
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||
Registry::default().with(telemetry).try_init().unwrap();
|
||||
|
||||
_span = Some(span!(tracing::Level::INFO, "app_start", work_units = 2));
|
||||
_enter = Some(_span.as_ref().unwrap().enter());
|
||||
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||
let _enter = root.enter();
|
||||
|
||||
let rocket = setup_rocket(raw_config, db);
|
||||
rocket.launch().await.unwrap();
|
||||
} else {
|
||||
std::env::set_var("RUST_LOG", &config.log);
|
||||
std::env::set_var("RUST_LOG", config.log);
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let rocket = setup_rocket(raw_config, db);
|
||||
rocket.launch().await.unwrap();
|
||||
}
|
||||
|
||||
config.warn_deprecated();
|
||||
|
||||
let db = Database::load_or_create(config)
|
||||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
let rocket = setup_rocket(raw_config, db);
|
||||
rocket.launch().await.unwrap();
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
use crate::{database::DatabaseGuard, Error};
|
||||
use crate::Error;
|
||||
use ruma::{
|
||||
api::{client::r0::uiaa::UiaaResponse, OutgoingResponse},
|
||||
identifiers::{DeviceId, UserId},
|
||||
@@ -9,7 +9,7 @@ use std::ops::Deref;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use {
|
||||
crate::server_server,
|
||||
crate::{server_server, Database},
|
||||
log::{debug, warn},
|
||||
rocket::{
|
||||
data::{self, ByteUnit, Data, FromData},
|
||||
@@ -17,12 +17,13 @@ use {
|
||||
outcome::Outcome::*,
|
||||
response::{self, Responder},
|
||||
tokio::io::AsyncReadExt,
|
||||
Request,
|
||||
Request, State,
|
||||
},
|
||||
ruma::api::{AuthScheme, IncomingRequest},
|
||||
std::collections::BTreeMap,
|
||||
std::convert::TryFrom,
|
||||
std::io::Cursor,
|
||||
std::sync::Arc,
|
||||
};
|
||||
|
||||
/// This struct converts rocket requests into ruma structs by converting them into http requests
|
||||
@@ -48,7 +49,7 @@ where
|
||||
async fn from_data(request: &'a Request<'_>, data: Data) -> data::Outcome<Self, Self::Error> {
|
||||
let metadata = T::Incoming::METADATA;
|
||||
let db = request
|
||||
.guard::<DatabaseGuard>()
|
||||
.guard::<State<'_, Arc<Database>>>()
|
||||
.await
|
||||
.expect("database was loaded");
|
||||
|
||||
|
||||
+57
-59
@@ -1,13 +1,12 @@
|
||||
use crate::{
|
||||
client_server::{self, claim_keys_helper, get_keys_helper},
|
||||
database::DatabaseGuard,
|
||||
utils, ConduitResult, Database, Error, PduEvent, Result, Ruma,
|
||||
};
|
||||
use get_profile_information::v1::ProfileField;
|
||||
use http::header::{HeaderValue, AUTHORIZATION, HOST};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use regex::Regex;
|
||||
use rocket::response::content::Json;
|
||||
use rocket::{response::content::Json, State};
|
||||
use ruma::{
|
||||
api::{
|
||||
client::error::{Error as RumaError, ErrorKind},
|
||||
@@ -46,7 +45,7 @@ use ruma::{
|
||||
receipt::ReceiptType,
|
||||
serde::Raw,
|
||||
signatures::{CanonicalJsonObject, CanonicalJsonValue},
|
||||
state_res::{self, RoomVersion, StateMap},
|
||||
state_res::{self, Event, RoomVersion, StateMap},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName,
|
||||
ServerSigningKeyId, UserId,
|
||||
@@ -433,7 +432,7 @@ pub async fn request_well_known(
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/federation/v1/version"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_version_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
) -> ConduitResult<get_server_version::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
@@ -451,7 +450,7 @@ pub fn get_server_version_route(
|
||||
// Response type for this endpoint is Json because we need to calculate a signature for the response
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_keys_route(db: DatabaseGuard) -> Json<String> {
|
||||
pub fn get_server_keys_route(db: State<'_, Arc<Database>>) -> Json<String> {
|
||||
if !db.globals.allow_federation() {
|
||||
// TODO: Use proper types
|
||||
return Json("Federation is disabled.".to_owned());
|
||||
@@ -498,7 +497,7 @@ pub fn get_server_keys_route(db: DatabaseGuard) -> Json<String> {
|
||||
|
||||
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server/<_>"))]
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub fn get_server_keys_deprecated_route(db: DatabaseGuard) -> Json<String> {
|
||||
pub fn get_server_keys_deprecated_route(db: State<'_, Arc<Database>>) -> Json<String> {
|
||||
get_server_keys_route(db)
|
||||
}
|
||||
|
||||
@@ -508,7 +507,7 @@ pub fn get_server_keys_deprecated_route(db: DatabaseGuard) -> Json<String> {
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_filtered_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms_filtered::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -552,7 +551,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_public_rooms_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_public_rooms::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_public_rooms::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -596,7 +595,7 @@ pub async fn get_public_rooms_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn send_transaction_message_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
||||
) -> ConduitResult<send_transaction_message::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -640,7 +639,7 @@ pub async fn send_transaction_message_route(
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex_federation
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
@@ -807,8 +806,6 @@ pub async fn send_transaction_message_route(
|
||||
}
|
||||
}
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(send_transaction_message::v1::Response { pdus: resolved_map }.into())
|
||||
}
|
||||
|
||||
@@ -1257,10 +1254,24 @@ pub fn handle_incoming_pdu<'a>(
|
||||
|
||||
let mut auth_events = vec![];
|
||||
for map in &fork_states {
|
||||
let state_auth = map
|
||||
.values()
|
||||
.flat_map(|pdu| pdu.auth_events.clone())
|
||||
.collect();
|
||||
let mut state_auth = vec![];
|
||||
for auth_id in map.values().flat_map(|pdu| &pdu.auth_events) {
|
||||
match fetch_and_handle_events(
|
||||
&db,
|
||||
origin,
|
||||
&[auth_id.clone()],
|
||||
&room_id,
|
||||
pub_key_map,
|
||||
)
|
||||
.await
|
||||
{
|
||||
// This should always contain exactly one element when Ok
|
||||
Ok(events) => state_auth.extend_from_slice(&events),
|
||||
Err(e) => {
|
||||
debug!("Event was not present: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
auth_events.push(state_auth);
|
||||
}
|
||||
|
||||
@@ -1275,7 +1286,10 @@ pub fn handle_incoming_pdu<'a>(
|
||||
.collect::<StateMap<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
auth_events,
|
||||
auth_events
|
||||
.into_iter()
|
||||
.map(|pdus| pdus.into_iter().map(|pdu| pdu.event_id().clone()).collect())
|
||||
.collect(),
|
||||
&|id| {
|
||||
let res = db.rooms.get_pdu(id);
|
||||
if let Err(e) = &res {
|
||||
@@ -1309,13 +1323,11 @@ pub fn handle_incoming_pdu<'a>(
|
||||
pdu_id = Some(
|
||||
append_incoming_pdu(
|
||||
&db,
|
||||
&room_id,
|
||||
&incoming_pdu,
|
||||
val,
|
||||
extremities,
|
||||
&state_at_incoming_event,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| "Failed to add pdu to db.".to_owned())?,
|
||||
);
|
||||
debug!("Appended incoming pdu.");
|
||||
@@ -1344,10 +1356,14 @@ pub fn handle_incoming_pdu<'a>(
|
||||
/// Find the event and auth it. Once the event is validated (steps 1 - 8)
|
||||
/// it is appended to the outliers Tree.
|
||||
///
|
||||
/// a. Look in the main timeline (pduid_pdu tree)
|
||||
/// b. Look at outlier pdu tree
|
||||
/// c. Ask origin server over federation
|
||||
/// d. TODO: Ask other servers over federation?
|
||||
/// a. Look in the auth_cache
|
||||
/// b. Look in the main timeline (pduid_pdu tree)
|
||||
/// c. Look at outlier pdu tree
|
||||
/// d. Ask origin server over federation
|
||||
/// e. TODO: Ask other servers over federation?
|
||||
///
|
||||
/// If the event is unknown to the `auth_cache` it is added. This guarantees that any
|
||||
/// event we need to know of will be present.
|
||||
//#[tracing::instrument(skip(db, key_map, auth_cache))]
|
||||
pub(crate) fn fetch_and_handle_events<'a>(
|
||||
db: &'a Database,
|
||||
@@ -1614,24 +1630,13 @@ pub(crate) async fn fetch_signing_keys(
|
||||
/// Append the incoming event setting the state snapshot to the state from the
|
||||
/// server that sent the event.
|
||||
#[tracing::instrument(skip(db))]
|
||||
async fn append_incoming_pdu(
|
||||
pub(crate) fn append_incoming_pdu(
|
||||
db: &Database,
|
||||
room_id: &RoomId,
|
||||
pdu: &PduEvent,
|
||||
pdu_json: CanonicalJsonObject,
|
||||
new_room_leaves: HashSet<EventId>,
|
||||
state: &StateMap<Arc<PduEvent>>,
|
||||
) -> Result<Vec<u8>> {
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
||||
// We append to state before appending the pdu, so we don't have a moment in time with the
|
||||
// pdu without it's state. This is okay because append_pdu can't fail.
|
||||
db.rooms
|
||||
@@ -1644,8 +1649,6 @@ async fn append_incoming_pdu(
|
||||
&db,
|
||||
)?;
|
||||
|
||||
drop(mutex_lock);
|
||||
|
||||
for appservice in db.appservice.iter_all()?.filter_map(|r| r.ok()) {
|
||||
if let Some(namespaces) = appservice.1.get("namespaces") {
|
||||
let users = namespaces
|
||||
@@ -1699,7 +1702,8 @@ async fn append_incoming_pdu(
|
||||
.filter_map(|r| r.ok())
|
||||
.any(|member| users.iter().any(|regex| regex.is_match(member.as_str())))
|
||||
{
|
||||
db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
||||
db.sending
|
||||
.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1713,7 +1717,7 @@ async fn append_incoming_pdu(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_event::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_event::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -1738,7 +1742,7 @@ pub fn get_event_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_missing_events_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_missing_events::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_missing_events::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -1787,7 +1791,7 @@ pub fn get_missing_events_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_event_authorization_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_event_authorization::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_event_authorization::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -1831,7 +1835,7 @@ pub fn get_event_authorization_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_state_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_state::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_state::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -1894,7 +1898,7 @@ pub fn get_room_state_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_state_ids_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_state_ids::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_state_ids::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -1950,7 +1954,7 @@ pub fn get_room_state_ids_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn create_join_event_template_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_join_event_template::v1::Request<'_>>,
|
||||
) -> ConduitResult<create_join_event_template::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2119,7 +2123,7 @@ pub fn create_join_event_template_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_join_event_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_join_event::v2::Request<'_>>,
|
||||
) -> ConduitResult<create_join_event::v2::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2161,7 +2165,7 @@ pub async fn create_join_event_route(
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex_federation
|
||||
.roomid_mutex
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(body.room_id.clone())
|
||||
@@ -2222,8 +2226,6 @@ pub async fn create_join_event_route(
|
||||
db.sending.send_pdu(&server, &pdu_id)?;
|
||||
}
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(create_join_event::v2::Response {
|
||||
room_state: RoomState {
|
||||
auth_chain: auth_chain_ids
|
||||
@@ -2247,7 +2249,7 @@ pub async fn create_join_event_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn create_invite_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<create_invite::v2::Request>,
|
||||
) -> ConduitResult<create_invite::v2::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2340,8 +2342,6 @@ pub async fn create_invite_route(
|
||||
)?;
|
||||
}
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(create_invite::v2::Response {
|
||||
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
||||
}
|
||||
@@ -2354,7 +2354,7 @@ pub async fn create_invite_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_devices_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_devices::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_devices::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2394,7 +2394,7 @@ pub fn get_devices_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_room_information_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_room_information::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_room_information::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2422,7 +2422,7 @@ pub fn get_room_information_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_profile_information_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_profile_information::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_profile_information::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2455,8 +2455,8 @@ pub fn get_profile_information_route(
|
||||
post("/_matrix/federation/v1/user/keys/query", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn get_keys_route(
|
||||
db: DatabaseGuard,
|
||||
pub fn get_keys_route(
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<get_keys::v1::Request>,
|
||||
) -> ConduitResult<get_keys::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
@@ -2470,8 +2470,6 @@ pub async fn get_keys_route(
|
||||
&db,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(get_keys::v1::Response {
|
||||
device_keys: result.device_keys,
|
||||
master_keys: result.master_keys,
|
||||
@@ -2486,7 +2484,7 @@ pub async fn get_keys_route(
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub async fn claim_keys_route(
|
||||
db: DatabaseGuard,
|
||||
db: State<'_, Arc<Database>>,
|
||||
body: Ruma<claim_keys::v1::Request>,
|
||||
) -> ConduitResult<claim_keys::v1::Response> {
|
||||
if !db.globals.allow_federation() {
|
||||
|
||||
@@ -5,7 +5,6 @@ use ruma::serde::{try_from_json_map, CanonicalJsonError, CanonicalJsonObject};
|
||||
use std::{
|
||||
cmp,
|
||||
convert::TryInto,
|
||||
str::FromStr,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@@ -116,29 +115,3 @@ pub fn to_canonical_object<T: serde::Serialize>(
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_from_str<
|
||||
'de,
|
||||
D: serde::de::Deserializer<'de>,
|
||||
T: FromStr<Err = E>,
|
||||
E: std::fmt::Display,
|
||||
>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<T, D::Error> {
|
||||
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);
|
||||
impl<'de, T: FromStr<Err = Err>, Err: std::fmt::Display> serde::de::Visitor<'de>
|
||||
for Visitor<T, Err>
|
||||
{
|
||||
type Value = T;
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(formatter, "a parsable string")
|
||||
}
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
v.parse().map_err(|e| serde::de::Error::custom(e))
|
||||
}
|
||||
}
|
||||
deserializer.deserialize_str(Visitor(std::marker::PhantomData))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user