summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Platte <jplatte+git@posteo.de>2022-01-20 11:51:31 +0100
committerJonas Platte <jplatte+git@posteo.de>2022-02-12 12:56:07 +0100
commit1f7b3fa4acd13ea4962ba93c5bc96bd8aa9f44b3 (patch)
treee86e6df88bdf4c478caccf8b832150884002682d
parent8709c3ae7ba104a5bb14930124161bd83f23d937 (diff)
downloadconduit-1f7b3fa4acd13ea4962ba93c5bc96bd8aa9f44b3.zip
Port from Rocket to axum
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock775
-rw-r--r--Cargo.toml20
-rw-r--r--README.md2
-rw-r--r--conduit-example.toml2
-rw-r--r--debian/postinst2
-rw-r--r--docker-compose.yml2
-rw-r--r--docker/docker-compose.traefik.yml2
-rw-r--r--src/client_server/account.rs26
-rw-r--r--src/client_server/alias.rs15
-rw-r--r--src/client_server/backup.rs59
-rw-r--r--src/client_server/capabilities.rs7
-rw-r--r--src/client_server/config.rs25
-rw-r--r--src/client_server/context.rs7
-rw-r--r--src/client_server/device.rs22
-rw-r--r--src/client_server/directory.rs19
-rw-r--r--src/client_server/filter.rs11
-rw-r--r--src/client_server/keys.rs29
-rw-r--r--src/client_server/media.rs23
-rw-r--r--src/client_server/membership.rs47
-rw-r--r--src/client_server/message.rs11
-rw-r--r--src/client_server/mod.rs17
-rw-r--r--src/client_server/presence.rs11
-rw-r--r--src/client_server/profile.rs23
-rw-r--r--src/client_server/push.rs43
-rw-r--r--src/client_server/read_marker.rs11
-rw-r--r--src/client_server/redact.rs6
-rw-r--r--src/client_server/report.rs11
-rw-r--r--src/client_server/room.rs19
-rw-r--r--src/client_server/search.rs6
-rw-r--r--src/client_server/session.rs22
-rw-r--r--src/client_server/state.rs23
-rw-r--r--src/client_server/sync.rs7
-rw-r--r--src/client_server/tag.rs15
-rw-r--r--src/client_server/thirdparty.rs14
-rw-r--r--src/client_server/to_device.rs7
-rw-r--r--src/client_server/typing.rs9
-rw-r--r--src/client_server/unversioned.rs12
-rw-r--r--src/client_server/user_directory.rs7
-rw-r--r--src/client_server/voip.rs9
-rw-r--r--src/config.rs19
-rw-r--r--src/database.rs48
-rw-r--r--src/database/admin.rs51
-rw-r--r--src/database/sending.rs19
-rw-r--r--src/error.rs45
-rw-r--r--src/lib.rs14
-rw-r--r--src/main.rs505
-rw-r--r--src/ruma_wrapper.rs362
-rw-r--r--src/ruma_wrapper/axum.rs338
-rw-r--r--src/server_server.rs113
-rw-r--r--src/utils.rs39
-rw-r--r--tests/Complement.Dockerfile7
52 files changed, 1059 insertions, 1880 deletions
diff --git a/.gitignore b/.gitignore
index 1f5f395..f5e9505 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,7 +57,6 @@ $RECYCLE.BIN/
*.lnk
# Conduit
-Rocket.toml
conduit.toml
conduit.db
diff --git a/Cargo.lock b/Cargo.lock
index 632b4ce..f84c982 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,12 @@
version = 3
[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -29,6 +35,21 @@ dependencies = [
]
[[package]]
+name = "alloc-no-stdlib"
+version = "2.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35ef4730490ad1c4eae5c4325b2a95f521d023e5c885853ff7aca0a6a1631db3"
+
+[[package]]
+name = "alloc-stdlib"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "697ed7edc0f1711de49ce108c541623a0af97c6c60b2f6e2b65229847ac843c2"
+dependencies = [
+ "alloc-no-stdlib",
+]
+
+[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -56,24 +77,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002"
[[package]]
-name = "async-stream"
-version = "0.3.2"
+name = "async-compression"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625"
+checksum = "5443ccbb270374a2b1055fc72da40e1f237809cd6bb0e97e66d264cd138473a6"
dependencies = [
- "async-stream-impl",
+ "brotli",
+ "flate2",
"futures-core",
-]
-
-[[package]]
-name = "async-stream-impl"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
+ "memchr",
+ "pin-project-lite",
+ "tokio",
]
[[package]]
@@ -97,27 +111,56 @@ dependencies = [
]
[[package]]
-name = "atty"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
-dependencies = [
- "hermit-abi",
- "libc",
- "winapi",
-]
-
-[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
-name = "base-x"
-version = "0.2.8"
+name = "axum"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "310a147401c66e79fc78636e4db63ac68cd6acb9ece056de806ea173a15bce32"
+dependencies = [
+ "async-trait",
+ "axum-core",
+ "bitflags",
+ "bytes",
+ "futures-util",
+ "headers",
+ "http",
+ "http-body",
+ "hyper",
+ "matchit",
+ "memchr",
+ "mime",
+ "percent-encoding",
+ "pin-project-lite",
+ "serde",
+ "serde_json",
+ "serde_urlencoded",
+ "sync_wrapper",
+ "tokio",
+ "tokio-util",
+ "tower",
+ "tower-http",
+ "tower-layer",
+ "tower-service",
+]
+
+[[package]]
+name = "axum-core"
+version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
+checksum = "1ca6c0b218388a7ed6a8d25e94f7dea5498daaa4fd8c711fb3ff166041b06fda"
+dependencies = [
+ "async-trait",
+ "bytes",
+ "futures-util",
+ "http",
+ "http-body",
+ "mime",
+]
[[package]]
name = "base64"
@@ -132,12 +175,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
-name = "binascii"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72"
-
-[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -192,6 +229,27 @@ dependencies = [
]
[[package]]
+name = "brotli"
+version = "3.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f838e47a451d5a8fa552371f80024dd6ace9b7acdf25c4c3d0f9bc6816fb1c39"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+ "brotli-decompressor",
+]
+
+[[package]]
+name = "brotli-decompressor"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59ad2d4653bf5ca36ae797b1f4bb4dbddb60ce49ca4aed8a2ce4829f60425b80"
+dependencies = [
+ "alloc-no-stdlib",
+ "alloc-stdlib",
+]
+
+[[package]]
name = "bumpalo"
version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -254,7 +312,7 @@ dependencies = [
"libc",
"num-integer",
"num-traits",
- "time 0.1.43",
+ "time",
"winapi",
]
@@ -306,18 +364,21 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
name = "conduit"
version = "0.3.0"
dependencies = [
+ "axum",
"base64 0.13.0",
"bytes",
"clap",
"crossbeam",
"directories",
+ "figment",
+ "futures-util",
"heed",
"hmac",
"http",
+ "hyper",
"image",
"jsonwebtoken",
"lru-cache",
- "maplit",
"num_cpus",
"opentelemetry",
"opentelemetry-jaeger",
@@ -327,7 +388,6 @@ dependencies = [
"regex",
"reqwest",
"ring",
- "rocket",
"rocksdb",
"ruma",
"rusqlite",
@@ -343,9 +403,11 @@ dependencies = [
"tikv-jemalloc-ctl",
"tikv-jemallocator",
"tokio",
+ "tower",
+ "tower-http",
"tracing",
"tracing-flame",
- "tracing-subscriber 0.2.25",
+ "tracing-subscriber",
"trust-dns-resolver",
]
@@ -356,29 +418,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b"
[[package]]
-name = "const_fn"
-version = "0.4.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935"
-
-[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
-name = "cookie"
-version = "0.15.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d5f1c7727e460397e56abc4bddc1d49e07a1ad78fc98eb2e1c8f032a58a2f80d"
-dependencies = [
- "percent-encoding",
- "time 0.2.27",
- "version_check",
-]
-
-[[package]]
name = "cpufeatures"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -547,39 +592,6 @@ dependencies = [
]
[[package]]
-name = "devise"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50c7580b072f1c8476148f16e0a0d5dedddab787da98d86c5082c5e9ed8ab595"
-dependencies = [
- "devise_codegen",
- "devise_core",
-]
-
-[[package]]
-name = "devise_codegen"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "123c73e7a6e51b05c75fe1a1b2f4e241399ea5740ed810b0e3e6cacd9db5e7b2"
-dependencies = [
- "devise_core",
- "quote",
-]
-
-[[package]]
-name = "devise_core"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0"
-dependencies = [
- "bitflags",
- "proc-macro2",
- "proc-macro2-diagnostics",
- "quote",
- "syn",
-]
-
-[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -609,12 +621,6 @@ dependencies = [
]
[[package]]
-name = "discard"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
-
-[[package]]
name = "ed25519"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -677,15 +683,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
-name = "fastrand"
-version = "1.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2"
-dependencies = [
- "instant",
-]
-
-[[package]]
name = "figment"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -700,6 +697,18 @@ dependencies = [
]
[[package]]
+name = "flate2"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f"
+dependencies = [
+ "cfg-if 1.0.0",
+ "crc32fast",
+ "libc",
+ "miniz_oxide 0.4.4",
+]
+
+[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -830,19 +839,6 @@ dependencies = [
]
[[package]]
-name = "generator"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1d9279ca822891c1a4dae06d185612cf8fc6acfe5dff37781b41297811b12ee"
-dependencies = [
- "cc",
- "libc",
- "log",
- "rustversion",
- "winapi",
-]
-
-[[package]]
name = "generic-array"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -928,6 +924,31 @@ dependencies = [
]
[[package]]
+name = "headers"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4c4eb0471fcb85846d8b0690695ef354f9afb11cb03cac2e1d7c9253351afb0"
+dependencies = [
+ "base64 0.13.0",
+ "bitflags",
+ "bytes",
+ "headers-core",
+ "http",
+ "httpdate",
+ "mime",
+ "sha-1",
+]
+
+[[package]]
+name = "headers-core"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429"
+dependencies = [
+ "http",
+]
+
+[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1031,6 +1052,12 @@ dependencies = [
]
[[package]]
+name = "http-range-header"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29"
+
+[[package]]
name = "httparse"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1074,9 +1101,9 @@ checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac"
dependencies = [
"http",
"hyper",
- "rustls 0.20.2",
+ "rustls",
"tokio",
- "tokio-rustls 0.23.2",
+ "tokio-rustls",
]
[[package]]
@@ -1321,21 +1348,6 @@ dependencies = [
]
[[package]]
-name = "loom"
-version = "0.5.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "edc5c7d328e32cc4954e8e01193d7f0ef5ab257b5090b70a964e099a36034309"
-dependencies = [
- "cfg-if 1.0.0",
- "generator",
- "scoped-tls",
- "serde",
- "serde_json",
- "tracing",
- "tracing-subscriber 0.3.6",
-]
-
-[[package]]
name = "lru-cache"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1366,21 +1378,18 @@ dependencies = [
]
[[package]]
-name = "matchers"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
-dependencies = [
- "regex-automata",
-]
-
-[[package]]
name = "matches"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
+name = "matchit"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "58b6f41fdfbec185dd3dff58b51e323f5bc61692c0de38419a957b0dcfccca3c"
+
+[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1417,6 +1426,16 @@ dependencies = [
]
[[package]]
+name = "miniz_oxide"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
+dependencies = [
+ "adler",
+ "autocfg",
+]
+
+[[package]]
name = "mio"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1439,26 +1458,6 @@ dependencies = [
]
[[package]]
-name = "multer"
-version = "2.0.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5f8f35e687561d5c1667590911e6698a8cb714a134a7505718a182e7bc9d3836"
-dependencies = [
- "bytes",
- "encoding_rs",
- "futures-util",
- "http",
- "httparse",
- "log",
- "memchr",
- "mime",
- "spin 0.9.2",
- "tokio",
- "tokio-util",
- "version_check",
-]
-
-[[package]]
name = "nom"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1774,7 +1773,7 @@ dependencies = [
"bitflags",
"crc32fast",
"deflate",
- "miniz_oxide",
+ "miniz_oxide 0.3.7",
]
[[package]]
@@ -1818,12 +1817,6 @@ dependencies = [
]
[[package]]
-name = "proc-macro-hack"
-version = "0.5.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
-
-[[package]]
name = "proc-macro2"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1961,26 +1954,6 @@ dependencies = [
]
[[package]]
-name = "ref-cast"
-version = "1.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da"
-dependencies = [
- "ref-cast-impl",
-]
-
-[[package]]
-name = "ref-cast-impl"
-version = "1.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2007,15 +1980,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
-name = "remove_dir_all"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
-dependencies = [
- "winapi",
-]
-
-[[package]]
name = "reqwest"
version = "0.11.9"
source = "git+https://github.com/timokoesters/reqwest?rev=57b7cf4feb921573dfafad7d34b9ac6e44ead0bd#57b7cf4feb921573dfafad7d34b9ac6e44ead0bd"
@@ -2037,13 +2001,13 @@ dependencies = [
"mime",
"percent-encoding",
"pin-project-lite",
- "rustls 0.20.2",
+ "rustls",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
- "tokio-rustls 0.23.2",
+ "tokio-rustls",
"tokio-socks",
"url",
"wasm-bindgen",
@@ -2072,96 +2036,13 @@ dependencies = [
"cc",
"libc",
"once_cell",
- "spin 0.5.2",
+ "spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]]
-name = "rocket"
-version = "0.5.0-rc.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a71c18c42a0eb15bf3816831caf0dad11e7966f2a41aaf486a701979c4dd1f2"
-dependencies = [
- "async-stream",
- "async-trait",
- "atomic",
- "atty",
- "binascii",
- "bytes",
- "either",
- "figment",
- "futures",
- "indexmap",
- "log",
- "memchr",
- "multer",
- "num_cpus",
- "parking_lot",
- "pin-project-lite",
- "rand 0.8.4",
- "ref-cast",
- "rocket_codegen",
- "rocket_http",
- "serde",
- "state",
- "tempfile",
- "time 0.2.27",
- "tokio",
- "tokio-stream",
- "tokio-util",
- "ubyte",
- "version_check",
- "yansi",
-]
-
-[[package]]
-name = "rocket_codegen"
-version = "0.5.0-rc.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "66f5fa462f7eb958bba8710c17c5d774bbbd59809fa76fb1957af7e545aea8bb"
-dependencies = [
- "devise",
- "glob",
- "indexmap",
- "proc-macro2",
- "quote",
- "rocket_http",
- "syn",
- "unicode-xid",
-]
-
-[[package]]
-name = "rocket_http"
-version = "0.5.0-rc.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "23c8b7d512d2fcac2316ebe590cde67573844b99e6cc9ee0f53375fa16e25ebd"
-dependencies = [
- "cookie",
- "either",
- "http",
- "hyper",
- "indexmap",
- "log",
- "memchr",
- "mime",
- "parking_lot",
- "pear",
- "percent-encoding",
- "pin-project-lite",
- "ref-cast",
- "serde",
- "smallvec",
- "stable-pattern",
- "state",
- "time 0.2.27",
- "tokio",
- "tokio-rustls 0.22.0",
- "uncased",
-]
-
-[[package]]
name = "rocksdb"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2466,28 +2347,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
-name = "rustc_version"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
-dependencies = [
- "semver",
-]
-
-[[package]]
-name = "rustls"
-version = "0.19.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7"
-dependencies = [
- "base64 0.13.0",
- "log",
- "ring",
- "sct 0.6.1",
- "webpki 0.21.4",
-]
-
-[[package]]
name = "rustls"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2495,8 +2354,8 @@ checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84"
dependencies = [
"log",
"ring",
- "sct 0.7.0",
- "webpki 0.22.0",
+ "sct",
+ "webpki",
]
[[package]]
@@ -2509,24 +2368,12 @@ dependencies = [
]
[[package]]
-name = "rustversion"
-version = "1.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
-
-[[package]]
name = "ryu"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
-name = "scoped-tls"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
-
-[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2534,16 +2381,6 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "sct"
-version = "0.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce"
-dependencies = [
- "ring",
- "untrusted",
-]
-
-[[package]]
-name = "sct"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
@@ -2553,21 +2390,6 @@ dependencies = [
]
[[package]]
-name = "semver"
-version = "0.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
-dependencies = [
- "semver-parser",
-]
-
-[[package]]
-name = "semver-parser"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
-
-[[package]]
name = "serde"
version = "1.0.134"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2636,21 +2458,6 @@ dependencies = [
]
[[package]]
-name = "sha1"
-version = "0.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770"
-dependencies = [
- "sha1_smol",
-]
-
-[[package]]
-name = "sha1_smol"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
-
-[[package]]
name = "sha2"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2761,12 +2568,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
-name = "spin"
-version = "0.9.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5"
-
-[[package]]
name = "spki"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2776,82 +2577,6 @@ dependencies = [
]
[[package]]
-name = "stable-pattern"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4564168c00635f88eaed410d5efa8131afa8d8699a612c80c455a0ba05c21045"
-dependencies = [
- "memchr",
-]
-
-[[package]]
-name = "standback"
-version = "0.2.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff"
-dependencies = [
- "version_check",
-]
-
-[[package]]
-name = "state"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87cf4f5369e6d3044b5e365c9690f451516ac8f0954084622b49ea3fde2f6de5"
-dependencies = [
- "loom",
-]
-
-[[package]]
-name = "stdweb"
-version = "0.4.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
-dependencies = [
- "discard",
- "rustc_version",
- "stdweb-derive",
- "stdweb-internal-macros",
- "stdweb-internal-runtime",
- "wasm-bindgen",
-]
-
-[[package]]
-name = "stdweb-derive"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
-dependencies = [
- "proc-macro2",
- "quote",
- "serde",
- "serde_derive",
- "syn",
-]
-
-[[package]]
-name = "stdweb-internal-macros"
-version = "0.2.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
-dependencies = [
- "base-x",
- "proc-macro2",
- "quote",
- "serde",
- "serde_derive",
- "serde_json",
- "sha1",
- "syn",
-]
-
-[[package]]
-name = "stdweb-internal-runtime"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
-
-[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2869,6 +2594,12 @@ dependencies = [
]
[[package]]
+name = "sync_wrapper"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8"
+
+[[package]]
name = "synchronoise"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2890,20 +2621,6 @@ dependencies = [
]
[[package]]
-name = "tempfile"
-version = "3.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
-dependencies = [
- "cfg-if 1.0.0",
- "fastrand",
- "libc",
- "redox_syscall",
- "remove_dir_all",
- "winapi",
-]
-
-[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3003,44 +2720,6 @@ dependencies = [
]
[[package]]
-name = "time"
-version = "0.2.27"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242"
-dependencies = [
- "const_fn",
- "libc",
- "standback",
- "stdweb",
- "time-macros",
- "version_check",
- "winapi",
-]
-
-[[package]]
-name = "time-macros"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1"
-dependencies = [
- "proc-macro-hack",
- "time-macros-impl",
-]
-
-[[package]]
-name = "time-macros-impl"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f"
-dependencies = [
- "proc-macro-hack",
- "proc-macro2",
- "quote",
- "standback",
- "syn",
-]
-
-[[package]]
name = "tinyvec"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3086,24 +2765,13 @@ dependencies = [
[[package]]
name = "tokio-rustls"
-version = "0.22.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6"
-dependencies = [
- "rustls 0.19.1",
- "tokio",
- "webpki 0.21.4",
-]
-
-[[package]]
-name = "tokio-rustls"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b"
dependencies = [
- "rustls 0.20.2",
+ "rustls",
"tokio",
- "webpki 0.22.0",
+ "webpki",
]
[[package]]
@@ -3153,6 +2821,52 @@ dependencies = [
]
[[package]]
+name = "tower"
+version = "0.4.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5651b5f6860a99bd1adb59dbfe1db8beb433e73709d9032b413a77e2fb7c066a"
+dependencies = [
+ "futures-core",
+ "futures-util",
+ "pin-project",
+ "pin-project-lite",
+ "tokio",
+ "tokio-util",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "tower-http"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03650267ad175b51c47d02ed9547fc7d4ba2c7e5cb76df0bed67edd1825ae297"
+dependencies = [
+ "async-compression",
+ "bitflags",
+ "bytes",
+ "futures-core",
+ "futures-util",
+ "http",
+ "http-body",
+ "http-range-header",
+ "pin-project-lite",
+ "tokio",
+ "tokio-util",
+ "tower",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "tower-layer"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62"
+
+[[package]]
name = "tower-service"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3165,6 +2879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if 1.0.0",
+ "log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@@ -3198,7 +2913,7 @@ checksum = "bd520fe41c667b437952383f3a1ec14f1fa45d653f719a77eedd6e6a02d8fa54"
dependencies = [
"lazy_static",
"tracing",
- "tracing-subscriber 0.2.25",
+ "tracing-subscriber",
]
[[package]]
@@ -3231,7 +2946,7 @@ dependencies = [
"ansi_term",
"chrono",
"lazy_static",
- "matchers 0.0.1",
+ "matchers",
"regex",
"serde",
"serde_json",
@@ -3245,24 +2960,6 @@ dependencies = [
]
[[package]]
-name = "tracing-subscriber"
-version = "0.3.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "77be66445c4eeebb934a7340f227bfe7b338173d3f8c00a60a5a58005c9faecf"
-dependencies = [
- "ansi_term",
- "lazy_static",
- "matchers 0.1.0",
- "regex",
- "sharded-slab",
- "smallvec",
- "thread_local",
- "tracing",
- "tracing-core",
- "tracing-log",
-]
-
-[[package]]
name = "trust-dns-proto"
version = "0.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3320,21 +3017,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
-name = "ubyte"
-version = "0.10.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42756bb9e708855de2f8a98195643dff31a97f0485d90d8467b39dc24be9e8fe"
-dependencies = [
- "serde",
-]
-
-[[package]]
name = "uncased"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0"
dependencies = [
- "serde",
"version_check",
]
@@ -3516,16 +3203,6 @@ dependencies = [
[[package]]
name = "webpki"
-version = "0.21.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea"
-dependencies = [
- "ring",
- "untrusted",
-]
-
-[[package]]
-name = "webpki"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
@@ -3540,7 +3217,7 @@ version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449"
dependencies = [
- "webpki 0.22.0",
+ "webpki",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 7f84343..5fb75dc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,10 +13,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-# Used to handle requests
-# TODO: This can become optional as soon as proper configs are supported
-# rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests
-rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests
+# Web framework
+axum = { version = "0.4.4", features = ["headers"], optional = true }
+hyper = "0.14.16"
+tower = { version = "0.4.11", features = ["util"] }
+tower-http = { version = "0.2.1", features = ["add-extension", "cors", "compression-full", "sensitive-headers", "trace", "util"] }
# Used for matrix spec type definitions and helpers
#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
@@ -24,8 +25,8 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "f7a10a7e471b59d3096be2695c
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", 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
-tokio = "1.11.0"
+# Async runtime and utilities
+tokio = { version = "1.11.0", features = ["fs", "macros", "signal", "sync"] }
# Used for storing data permanently
sled = { version = "0.34.6", features = ["compression", "no_metrics"], optional = true }
#sled = { git = "https://github.com/spacejam/sled.git", rev = "e4640e0773595229f398438886f19bca6f7326a2", features = ["compression"] }
@@ -33,7 +34,6 @@ persy = { version = "1.2" , optional = true, features=["background_ops"] }
# Used for the http request / response body type for Ruma endpoints used with reqwest
bytes = "1.1.0"
-# Used for rocket<->ruma conversions
http = "0.2.4"
# Used to find data directory for default db path
directories = "3.0.2"
@@ -84,7 +84,9 @@ hmac = "0.11.0"
sha-1 = "0.9.8"
# used for conduit's CLI and admin room command parsing
clap = { version = "3.0.10", default-features = false, features = ["std", "derive"] }
-maplit = "1.0.2"
+futures-util = { version = "0.3.19", default-features = false }
+# Used for reading the configuration from conduit.toml & environment variables
+figment = { version = "0.10.6", features = ["env", "toml"] }
tikv-jemalloc-ctl = { version = "0.4.2", features = ["use_std"], optional = true }
tikv-jemallocator = { version = "0.4.1", features = ["unprefixed_malloc_on_supported_platforms"], optional = true }
@@ -98,7 +100,7 @@ backend_heed = ["heed", "crossbeam"]
backend_rocksdb = ["rocksdb"]
jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator"]
sqlite = ["rusqlite", "parking_lot", "tokio/signal"]
-conduit_bin = [] # TODO: add rocket to this when it is optional
+conduit_bin = ["axum"]
[[bin]]
name = "conduit"
diff --git a/README.md b/README.md
index a4f0929..45b16fd 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Thanks to Famedly, Prototype Fund (DLR and German BMBF) and all other individual
Thanks to the contributors to Conduit and all libraries we use, for example:
- Ruma: A clean library for the Matrix Spec in Rust
-- Rocket: A flexible web framework
+- axum: A modular web framework
#### Donate
diff --git a/conduit-example.toml b/conduit-example.toml
index f157807..c22c862 100644
--- a/conduit-example.toml
+++ b/conduit-example.toml
@@ -42,7 +42,7 @@ allow_registration = true
trusted_servers = ["matrix.org"]
#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"
+#log = "info,state_res=warn,_=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
diff --git a/debian/postinst b/debian/postinst
index 6bd1a3a..29a9367 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -74,7 +74,7 @@ allow_registration = true
#allow_jaeger = false
#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"
+#log = "info,state_res=warn,_=off,sled=off"
#workers = 4 # default: cpu core count * 2
# The total amount of memory that the database will use.
diff --git a/docker-compose.yml b/docker-compose.yml
index 530fc19..88d5c3f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -33,7 +33,7 @@ services:
# CONDUIT_PORT: 6167
# CONDUIT_CONFIG: '/srv/conduit/conduit.toml' # if you want to configure purely by env vars, set this to an empty string ''
# Available levels are: error, warn, info, debug, trace - more info at: https://docs.rs/env_logger/*/env_logger/#enabling-logging
- # CONDUIT_LOG: info # default is: "info,rocket=off,_=off,sled=off"
+ # CONDUIT_LOG: info # default is: "info,_=off,sled=off"
# CONDUIT_ALLOW_JAEGER: 'false'
# CONDUIT_ALLOW_ENCRYPTION: 'false'
# CONDUIT_ALLOW_FEDERATION: 'false'
diff --git a/docker/docker-compose.traefik.yml b/docker/docker-compose.traefik.yml
index 392b382..f625080 100644
--- a/docker/docker-compose.traefik.yml
+++ b/docker/docker-compose.traefik.yml
@@ -33,7 +33,7 @@ services:
# CONDUIT_PORT: 6167
# CONDUIT_CONFIG: '/srv/conduit/conduit.toml' # if you want to configure purely by env vars, set this to an empty string ''
# Available levels are: error, warn, info, debug, trace - more info at: https://docs.rs/env_logger/*/env_logger/#enabling-logging
- # CONDUIT_LOG: info # default is: "info,rocket=off,_=off,sled=off"
+ # CONDUIT_LOG: info # default is: "info,_=off,sled=off"
# CONDUIT_ALLOW_JAEGER: 'false'
# CONDUIT_ALLOW_ENCRYPTION: 'false'
# CONDUIT_ALLOW_FEDERATION: 'false'
diff --git a/src/client_server/account.rs b/src/client_server/account.rs
index a210e8a..bf1a74d 100644
--- a/src/client_server/account.rs
+++ b/src/client_server/account.rs
@@ -27,8 +27,6 @@ use serde_json::value::to_raw_value;
use tracing::{info, warn};
use register::RegistrationKind;
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
const GUEST_NAME_LENGTH: usize = 10;
@@ -42,10 +40,6 @@ const GUEST_NAME_LENGTH: usize = 10;
/// - No user or appservice on this server already claimed this username
///
/// Note: This will not reserve the username, so the username might become invalid when trying to register
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/register/available", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_register_available_route(
db: DatabaseGuard,
@@ -90,10 +84,6 @@ pub async fn get_register_available_route(
/// - If type is not guest and no username is given: Always fails after UIAA check
/// - Creates a new account and populates it with default account data
/// - If `inhibit_login` is false: Creates a device and returns device id and access_token
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/register", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn register_route(
db: DatabaseGuard,
@@ -279,10 +269,6 @@ pub async fn register_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events
/// - Triggers device list updates
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/account/password", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn change_password_route(
db: DatabaseGuard,
@@ -348,10 +334,6 @@ pub async fn change_password_route(
/// Get user_id of the sender user.
///
/// Note: Also works for Application Services
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/account/whoami", data = "<body>")
-)]
#[tracing::instrument(skip(body))]
pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
@@ -371,10 +353,6 @@ pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::
/// - Forgets all to-device events
/// - Triggers device list updates
/// - Removes ability to log in again
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/account/deactivate", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn deactivate_route(
db: DatabaseGuard,
@@ -483,10 +461,6 @@ pub async fn deactivate_route(
/// Get a list of third party identifiers associated with this account.
///
/// - Currently always returns empty list
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/account/3pid", data = "<body>")
-)]
pub async fn third_party_route(
body: Ruma<get_3pids::Request>,
) -> ConduitResult<get_3pids::Response> {
diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs
index 129ac16..6e1b43e 100644
--- a/src/client_server/alias.rs
+++ b/src/client_server/alias.rs
@@ -12,16 +12,9 @@ use ruma::{
RoomAliasId,
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{delete, get, put};
-
/// # `PUT /_matrix/client/r0/directory/room/{roomAlias}`
///
/// Creates a new room alias on this server.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/directory/room/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_alias_route(
db: DatabaseGuard,
@@ -52,10 +45,6 @@ pub async fn create_alias_route(
///
/// - TODO: additional access control checks
/// - TODO: Update canonical alias event
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/r0/directory/room/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_alias_route(
db: DatabaseGuard,
@@ -82,10 +71,6 @@ pub async fn delete_alias_route(
/// Resolve an alias locally or over federation.
///
/// - TODO: Suggest more servers to join via
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/directory/room/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_alias_route(
db: DatabaseGuard,
diff --git a/src/client_server/backup.rs b/src/client_server/backup.rs
index bbb8672..cc2d7c4 100644
--- a/src/client_server/backup.rs
+++ b/src/client_server/backup.rs
@@ -9,16 +9,9 @@ use ruma::api::client::{
},
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{delete, get, post, put};
-
/// # `POST /_matrix/client/r0/room_keys/version`
///
/// Creates a new backup.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/unstable/room_keys/version", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_backup_route(
db: DatabaseGuard,
@@ -37,10 +30,6 @@ pub async fn create_backup_route(
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
///
/// Update information about an existing backup. Only `auth_data` can be modified.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn update_backup_route(
db: DatabaseGuard,
@@ -58,10 +47,6 @@ pub async fn update_backup_route(
/// # `GET /_matrix/client/r0/room_keys/version`
///
/// Get information about the latest backup version.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/unstable/room_keys/version", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_latest_backup_route(
db: DatabaseGuard,
@@ -89,10 +74,6 @@ pub async fn get_latest_backup_route(
/// # `GET /_matrix/client/r0/room_keys/version`
///
/// Get information about an existing backup.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_backup_route(
db: DatabaseGuard,
@@ -121,10 +102,6 @@ pub async fn get_backup_route(
/// Delete an existing key backup.
///
/// - Deletes both information about the backup, as well as all key data related to the backup
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_backup_route(
db: DatabaseGuard,
@@ -146,10 +123,6 @@ pub async fn delete_backup_route(
/// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/unstable/room_keys/keys", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn add_backup_keys_route(
db: DatabaseGuard,
@@ -198,10 +171,6 @@ pub async fn add_backup_keys_route(
/// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn add_backup_key_sessions_route(
db: DatabaseGuard,
@@ -248,10 +217,6 @@ pub async fn add_backup_key_sessions_route(
/// - Only manipulating the most recently created version of the backup is allowed
/// - Adds the keys to the backup
/// - Returns the new number of keys in this backup and the etag
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn add_backup_key_session_route(
db: DatabaseGuard,
@@ -292,10 +257,6 @@ pub async fn add_backup_key_session_route(
/// # `GET /_matrix/client/r0/room_keys/keys`
///
/// Retrieves all keys from the backup.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/unstable/room_keys/keys", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_backup_keys_route(
db: DatabaseGuard,
@@ -311,10 +272,6 @@ pub async fn get_backup_keys_route(
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
///
/// Retrieves all keys from the backup for a given room.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_backup_key_sessions_route(
db: DatabaseGuard,
@@ -332,10 +289,6 @@ pub async fn get_backup_key_sessions_route(
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
///
/// Retrieves a key from the backup.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_backup_key_session_route(
db: DatabaseGuard,
@@ -357,10 +310,6 @@ pub async fn get_backup_key_session_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys`
///
/// Delete the keys from the backup.
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/unstable/room_keys/keys", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_backup_keys_route(
db: DatabaseGuard,
@@ -382,10 +331,6 @@ pub async fn delete_backup_keys_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
///
/// Delete the keys from the backup for a given room.
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_backup_key_sessions_route(
db: DatabaseGuard,
@@ -408,10 +353,6 @@ pub async fn delete_backup_key_sessions_route(
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
///
/// Delete a key from the backup.
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_backup_key_session_route(
db: DatabaseGuard,
diff --git a/src/client_server/capabilities.rs b/src/client_server/capabilities.rs
index c69b7cb..8da6855 100644
--- a/src/client_server/capabilities.rs
+++ b/src/client_server/capabilities.rs
@@ -7,16 +7,9 @@ use ruma::{
};
use std::collections::BTreeMap;
-#[cfg(feature = "conduit_bin")]
-use rocket::get;
-
/// # `GET /_matrix/client/r0/capabilities`
///
/// Get information on the supported feature set and other relevent capabilities of this server.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/capabilities", data = "<_body>")
-)]
#[tracing::instrument(skip(_body))]
pub async fn get_capabilities_route(
_body: Ruma<get_capabilities::Request>,
diff --git a/src/client_server/config.rs b/src/client_server/config.rs
index 0c668ff..0df0dec 100644
--- a/src/client_server/config.rs
+++ b/src/client_server/config.rs
@@ -13,16 +13,9 @@ use ruma::{
use serde::Deserialize;
use serde_json::{json, value::RawValue as RawJsonValue};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, put};
-
/// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}`
///
/// Sets some account data for the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_global_account_data_route(
db: DatabaseGuard,
@@ -54,13 +47,6 @@ pub async fn set_global_account_data_route(
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
///
/// Sets some room account data for the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- put(
- "/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>",
- data = "<body>"
- )
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_room_account_data_route(
db: DatabaseGuard,
@@ -92,10 +78,6 @@ pub async fn set_room_account_data_route(
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
///
/// Gets some account data for the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_global_account_data_route(
db: DatabaseGuard,
@@ -118,13 +100,6 @@ pub async fn get_global_account_data_route(
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
///
/// Gets some room account data for the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- get(
- "/_matrix/client/r0/user/<_>/rooms/<_>/account_data/<_>",
- data = "<body>"
- )
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_room_account_data_route(
db: DatabaseGuard,
diff --git a/src/client_server/context.rs b/src/client_server/context.rs
index 02148f4..1fbfee9 100644
--- a/src/client_server/context.rs
+++ b/src/client_server/context.rs
@@ -9,19 +9,12 @@ use ruma::{
use std::{collections::HashSet, convert::TryFrom};
use tracing::error;
-#[cfg(feature = "conduit_bin")]
-use rocket::get;
-
/// # `GET /_matrix/client/r0/rooms/{roomId}/context`
///
/// Allows loading room history around an event.
///
/// - Only works if the user is joined (TODO: always allow, but only show events if the user was
/// joined, depending on history_visibility)
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/context/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_context_route(
db: DatabaseGuard,
diff --git a/src/client_server/device.rs b/src/client_server/device.rs
index f240f2e..82d1168 100644
--- a/src/client_server/device.rs
+++ b/src/client_server/device.rs
@@ -8,16 +8,10 @@ use ruma::api::client::{
};
use super::SESSION_ID_LENGTH;
-#[cfg(feature = "conduit_bin")]
-use rocket::{delete, get, post, put};
/// # `GET /_matrix/client/r0/devices`
///
/// Get metadata on all devices of the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/devices", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_devices_route(
db: DatabaseGuard,
@@ -37,10 +31,6 @@ pub async fn get_devices_route(
/// # `GET /_matrix/client/r0/devices/{deviceId}`
///
/// Get metadata on a single device of the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/devices/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_device_route(
db: DatabaseGuard,
@@ -59,10 +49,6 @@ pub async fn get_device_route(
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
///
/// Updates the metadata on a given device of the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/devices/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn update_device_route(
db: DatabaseGuard,
@@ -94,10 +80,6 @@ pub async fn update_device_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events
/// - Triggers device list updates
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/r0/devices/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_device_route(
db: DatabaseGuard,
@@ -157,10 +139,6 @@ pub async fn delete_device_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events
/// - Triggers device list updates
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/delete_devices", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_devices_route(
db: DatabaseGuard,
diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs
index 719d9af..06d7a27 100644
--- a/src/client_server/directory.rs
+++ b/src/client_server/directory.rs
@@ -29,18 +29,11 @@ use ruma::{
};
use tracing::{info, warn};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post, put};
-
/// # `POST /_matrix/client/r0/publicRooms`
///
/// Lists the public rooms on this server.
///
/// - Rooms are ordered by the number of joined members
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/publicRooms", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_public_rooms_filtered_route(
db: DatabaseGuard,
@@ -62,10 +55,6 @@ pub async fn get_public_rooms_filtered_route(
/// Lists the public rooms on this server.
///
/// - Rooms are ordered by the number of joined members
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/publicRooms", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_public_rooms_route(
db: DatabaseGuard,
@@ -96,10 +85,6 @@ pub async fn get_public_rooms_route(
/// Sets the visibility of a given room in the room directory.
///
/// - TODO: Access control checks
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/directory/list/room/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_room_visibility_route(
db: DatabaseGuard,
@@ -129,10 +114,6 @@ pub async fn set_room_visibility_route(
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
///
/// Gets the visibility of a given room in the room directory.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/directory/list/room/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_room_visibility_route(
db: DatabaseGuard,
diff --git a/src/client_server/filter.rs b/src/client_server/filter.rs
index f8845f1..6c42edd 100644
--- a/src/client_server/filter.rs
+++ b/src/client_server/filter.rs
@@ -4,18 +4,11 @@ use ruma::api::client::{
r0::filter::{create_filter, get_filter},
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
///
/// Loads a filter that was previously created.
///
/// - A user can only access their own filters
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/user/<_>/filter/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_filter_route(
db: DatabaseGuard,
@@ -33,10 +26,6 @@ pub async fn get_filter_route(
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
///
/// Creates a new filter to be used by other endpoints.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/user/<_>/filter", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_filter_route(
db: DatabaseGuard,
diff --git a/src/client_server/keys.rs b/src/client_server/keys.rs
index e7aec26..9a7a4e7 100644
--- a/src/client_server/keys.rs
+++ b/src/client_server/keys.rs
@@ -1,6 +1,6 @@
use super::SESSION_ID_LENGTH;
use crate::{database::DatabaseGuard, utils, ConduitResult, Database, Error, Result, Ruma};
-use rocket::futures::{prelude::*, stream::FuturesUnordered};
+use futures_util::{stream::FuturesUnordered, StreamExt};
use ruma::{
api::{
client::{
@@ -21,19 +21,12 @@ use ruma::{
use serde_json::json;
use std::collections::{BTreeMap, HashMap, HashSet};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
/// # `POST /_matrix/client/r0/keys/upload`
///
/// Publish end-to-end encryption keys for the sender device.
///
/// - Adds one time keys
/// - If there are no device keys yet: Adds device keys (TODO: merge with existing keys?)
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/keys/upload", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn upload_keys_route(
db: DatabaseGuard,
@@ -80,10 +73,6 @@ pub async fn upload_keys_route(
/// - Always fetches users from other servers over federation
/// - Gets master keys, self-signing keys, user signing keys and device keys.
/// - The master and self-signing keys contain signatures that the user is allowed to see
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/keys/query", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_keys_route(
db: DatabaseGuard,
@@ -105,10 +94,6 @@ pub async fn get_keys_route(
/// # `POST /_matrix/client/r0/keys/claim`
///
/// Claims one-time keys
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/keys/claim", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn claim_keys_route(
db: DatabaseGuard,
@@ -126,10 +111,6 @@ pub async fn claim_keys_route(
/// Uploads end-to-end key information for the sender user.
///
/// - Requires UIAA to verify password
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/unstable/keys/device_signing/upload", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn upload_signing_keys_route(
db: DatabaseGuard,
@@ -190,10 +171,6 @@ pub async fn upload_signing_keys_route(
/// # `POST /_matrix/client/r0/keys/signatures/upload`
///
/// Uploads end-to-end key signatures from the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/unstable/keys/signatures/upload", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn upload_signatures_route(
db: DatabaseGuard,
@@ -256,10 +233,6 @@ pub async fn upload_signatures_route(
/// Gets a list of users who have updated their device identity keys since the previous sync token.
///
/// - TODO: left users
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/keys/changes", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_key_changes_route(
db: DatabaseGuard,
diff --git a/src/client_server/media.rs b/src/client_server/media.rs
index deea319..5eba17b 100644
--- a/src/client_server/media.rs
+++ b/src/client_server/media.rs
@@ -10,18 +10,15 @@ use ruma::api::client::{
},
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
const MXC_LENGTH: usize = 32;
/// # `GET /_matrix/media/r0/config`
///
/// Returns max upload size.
-#[cfg_attr(feature = "conduit_bin", get("/_matrix/media/r0/config"))]
-#[tracing::instrument(skip(db))]
+#[tracing::instrument(skip(db, _body))]
pub async fn get_media_config_route(
db: DatabaseGuard,
+ _body: Ruma<get_media_config::Request>,
) -> ConduitResult<get_media_config::Response> {
Ok(get_media_config::Response {
upload_size: db.globals.max_request_size().into(),
@@ -35,10 +32,6 @@ pub async fn get_media_config_route(
///
/// - Some metadata will be saved in the database
/// - Media will be saved in the media/ directory
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/media/r0/upload", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_content_route(
db: DatabaseGuard,
@@ -110,10 +103,6 @@ pub async fn get_remote_content(
/// Load media from our server or over federation.
///
/// - Only allows federation if `allow_remote` is true
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/media/r0/download/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_content_route(
db: DatabaseGuard,
@@ -147,10 +136,6 @@ pub async fn get_content_route(
/// Load media from our server or over federation, permitting desired filename.
///
/// - Only allows federation if `allow_remote` is true
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/media/r0/download/<_>/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_content_as_filename_route(
db: DatabaseGuard,
@@ -190,10 +175,6 @@ pub async fn get_content_as_filename_route(
/// Load media thumbnail from our server or over federation.
///
/// - Only allows federation if `allow_remote` is true
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/media/r0/thumbnail/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_content_thumbnail_route(
db: DatabaseGuard,
diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs
index e855dba..c16065e 100644
--- a/src/client_server/membership.rs
+++ b/src/client_server/membership.rs
@@ -36,19 +36,12 @@ use std::{
};
use tracing::{debug, error, warn};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
/// # `POST /_matrix/client/r0/rooms/{roomId}/join`
///
/// Tries to join the sender user into a room.
///
/// - If the server knowns about this room: creates the join event and does auth rules locally
/// - If the server does not know about the room: asks other servers over federation
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/join", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn join_room_by_id_route(
db: DatabaseGuard,
@@ -90,10 +83,6 @@ pub async fn join_room_by_id_route(
///
/// - If the server knowns about this room: creates the join event and does auth rules locally
/// - If the server does not know about the room: asks other servers over federation
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/join/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn join_room_by_id_or_alias_route(
db: DatabaseGuard,
@@ -148,10 +137,6 @@ pub async fn join_room_by_id_or_alias_route(
/// Tries to leave the sender user from a room.
///
/// - This should always work if the user is currently joined.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/leave", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn leave_room_route(
db: DatabaseGuard,
@@ -169,10 +154,6 @@ pub async fn leave_room_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
///
/// Tries to send an invite event into the room.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/invite", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn invite_user_route(
db: DatabaseGuard,
@@ -192,10 +173,6 @@ pub async fn invite_user_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/kick`
///
/// Tries to send a kick event into the room.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/kick", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn kick_user_route(
db: DatabaseGuard,
@@ -256,10 +233,6 @@ pub async fn kick_user_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
///
/// Tries to send a ban event into the room.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/ban", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn ban_user_route(
db: DatabaseGuard,
@@ -331,10 +304,6 @@ pub async fn ban_user_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
///
/// Tries to send an unban event into the room.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/unban", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn unban_user_route(
db: DatabaseGuard,
@@ -399,10 +368,6 @@ pub async fn unban_user_route(
///
/// Note: Other devices of the user have no way of knowing the room was forgotten, so this has to
/// be called from every device
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/forget", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn forget_room_route(
db: DatabaseGuard,
@@ -420,10 +385,6 @@ pub async fn forget_room_route(
/// # `POST /_matrix/client/r0/joined_rooms`
///
/// Lists all rooms the user has joined.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/joined_rooms", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn joined_rooms_route(
db: DatabaseGuard,
@@ -446,10 +407,6 @@ pub async fn joined_rooms_route(
/// Lists all joined users in a room (TODO: at a specific point in time, with a specific membership).
///
/// - Only works if the user is currently joined
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/members", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_member_events_route(
db: DatabaseGuard,
@@ -483,10 +440,6 @@ pub async fn get_member_events_route(
///
/// - The sender user must be in the room
/// - TODO: An appservice just needs a puppet joined
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/joined_members", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn joined_members_route(
db: DatabaseGuard,
diff --git a/src/client_server/message.rs b/src/client_server/message.rs
index cf4f0cb..4fb8771 100644
--- a/src/client_server/message.rs
+++ b/src/client_server/message.rs
@@ -11,9 +11,6 @@ use std::{
sync::Arc,
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, put};
-
/// # `PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}`
///
/// Send a message event into the room.
@@ -21,10 +18,6 @@ use rocket::{get, put};
/// - Is a NOOP if the txn id was already used before and returns the same event id again
/// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/rooms/<_>/send/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn send_message_event_route(
db: DatabaseGuard,
@@ -110,10 +103,6 @@ pub async fn send_message_event_route(
///
/// - Only works if the user is joined (TODO: always allow, but only show events where the user was
/// joined, depending on history_visibility)
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/messages", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_message_events_route(
db: DatabaseGuard,
diff --git a/src/client_server/mod.rs b/src/client_server/mod.rs
index 115ddaf..a7241b0 100644
--- a/src/client_server/mod.rs
+++ b/src/client_server/mod.rs
@@ -62,23 +62,6 @@ pub use unversioned::*;
pub use user_directory::*;
pub use voip::*;
-#[cfg(not(feature = "conduit_bin"))]
-use super::State;
-#[cfg(feature = "conduit_bin")]
-use {
- crate::ConduitResult, rocket::options, ruma::api::client::r0::to_device::send_event_to_device,
-};
-
pub const DEVICE_ID_LENGTH: usize = 10;
pub const TOKEN_LENGTH: usize = 256;
pub const SESSION_ID_LENGTH: usize = 256;
-
-/// # `OPTIONS`
-///
-/// Web clients use this to get CORS headers.
-#[cfg(feature = "conduit_bin")]
-#[options("/<_..>")]
-#[tracing::instrument]
-pub async fn options_route() -> ConduitResult<send_event_to_device::Response> {
- Ok(send_event_to_device::Response {}.into())
-}
diff --git a/src/client_server/presence.rs b/src/client_server/presence.rs
index cdc1e1f..0d58ebf 100644
--- a/src/client_server/presence.rs
+++ b/src/client_server/presence.rs
@@ -2,16 +2,9 @@ use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
use ruma::api::client::r0::presence::{get_presence, set_presence};
use std::time::Duration;
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, put};
-
/// # `PUT /_matrix/client/r0/presence/{userId}/status`
///
/// Sets the presence state of the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/presence/<_>/status", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_presence_route(
db: DatabaseGuard,
@@ -54,10 +47,6 @@ pub async fn set_presence_route(
/// Gets the presence state of the given user.
///
/// - Only works if you share a room with the user
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/presence/<_>/status", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_presence_route(
db: DatabaseGuard,
diff --git a/src/client_server/profile.rs b/src/client_server/profile.rs
index ef58a98..bb13b44 100644
--- a/src/client_server/profile.rs
+++ b/src/client_server/profile.rs
@@ -14,18 +14,11 @@ use ruma::{
use serde_json::value::to_raw_value;
use std::sync::Arc;
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, put};
-
/// # `PUT /_matrix/client/r0/profile/{userId}/displayname`
///
/// Updates the displayname.
///
/// - Also makes sure other users receive the update using presence EDUs
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/profile/<_>/displayname", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_displayname_route(
db: DatabaseGuard,
@@ -124,10 +117,6 @@ pub async fn set_displayname_route(
/// Returns the displayname of the user.
///
/// - If user is on another server: Fetches displayname over federation
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/profile/<_>/displayname", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_displayname_route(
db: DatabaseGuard,
@@ -163,10 +152,6 @@ pub async fn get_displayname_route(
/// Updates the avatar_url and blurhash.
///
/// - Also makes sure other users receive the update using presence EDUs
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/profile/<_>/avatar_url", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_avatar_url_route(
db: DatabaseGuard,
@@ -267,10 +252,6 @@ pub async fn set_avatar_url_route(
/// Returns the avatar_url and blurhash of the user.
///
/// - If user is on another server: Fetches avatar_url and blurhash over federation
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/profile/<_>/avatar_url", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_avatar_url_route(
db: DatabaseGuard,
@@ -308,10 +289,6 @@ pub async fn get_avatar_url_route(
/// Returns the displayname, avatar_url and blurhash of the user.
///
/// - If user is on another server: Fetches profile over federation
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/profile/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_profile_route(
db: DatabaseGuard,
diff --git a/src/client_server/push.rs b/src/client_server/push.rs
index a8ba1a2..322cf89 100644
--- a/src/client_server/push.rs
+++ b/src/client_server/push.rs
@@ -12,16 +12,9 @@ use ruma::{
push::{ConditionalPushRuleInit, PatternedPushRuleInit, SimplePushRuleInit},
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{delete, get, post, put};
-
/// # `GET /_matrix/client/r0/pushrules`
///
/// Retrieves the push rules event for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/pushrules", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_pushrules_all_route(
db: DatabaseGuard,
@@ -46,10 +39,6 @@ pub async fn get_pushrules_all_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
///
/// Retrieves a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_pushrule_route(
db: DatabaseGuard,
@@ -103,10 +92,6 @@ pub async fn get_pushrule_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
///
/// Creates a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_pushrule_route(
db: DatabaseGuard,
@@ -204,10 +189,6 @@ pub async fn set_pushrule_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
///
/// Gets the actions of a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/pushrules/<_>/<_>/<_>/actions", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_pushrule_actions_route(
db: DatabaseGuard,
@@ -266,10 +247,6 @@ pub async fn get_pushrule_actions_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
///
/// Sets the actions of a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/actions", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_pushrule_actions_route(
db: DatabaseGuard,
@@ -338,10 +315,6 @@ pub async fn set_pushrule_actions_route(
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
///
/// Gets the enabled status of a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_pushrule_enabled_route(
db: DatabaseGuard,
@@ -402,10 +375,6 @@ pub async fn get_pushrule_enabled_route(
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
///
/// Sets the enabled status of a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_pushrule_enabled_route(
db: DatabaseGuard,
@@ -479,10 +448,6 @@ pub async fn set_pushrule_enabled_route(
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
///
/// Deletes a single specified push rule for this user.
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_pushrule_route(
db: DatabaseGuard,
@@ -546,10 +511,6 @@ pub async fn delete_pushrule_route(
/// # `GET /_matrix/client/r0/pushers`
///
/// Gets all currently active pushers for the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/pushers", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_pushers_route(
db: DatabaseGuard,
@@ -568,10 +529,6 @@ pub async fn get_pushers_route(
/// Adds a pusher for the sender user.
///
/// - TODO: Handle `append`
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/pushers/set", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_pushers_route(
db: DatabaseGuard,
diff --git a/src/client_server/read_marker.rs b/src/client_server/read_marker.rs
index 502a612..c9480f0 100644
--- a/src/client_server/read_marker.rs
+++ b/src/client_server/read_marker.rs
@@ -10,19 +10,12 @@ use ruma::{
};
use std::collections::BTreeMap;
-#[cfg(feature = "conduit_bin")]
-use rocket::post;
-
/// # `POST /_matrix/client/r0/rooms/{roomId}/read_markers`
///
/// Sets different types of read markers.
///
/// - Updates fully-read account data event to `fully_read`
/// - If `read_receipt` is set: Update private marker and public read receipt EDU
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/read_markers", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn set_read_marker_route(
db: DatabaseGuard,
@@ -89,10 +82,6 @@ pub async fn set_read_marker_route(
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
///
/// Sets private read marker and public read receipt EDU.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/receipt/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_receipt_route(
db: DatabaseGuard,
diff --git a/src/client_server/redact.rs b/src/client_server/redact.rs
index 85de233..2b442fc 100644
--- a/src/client_server/redact.rs
+++ b/src/client_server/redact.rs
@@ -6,8 +6,6 @@ use ruma::{
events::{room::redaction::RoomRedactionEventContent, EventType},
};
-#[cfg(feature = "conduit_bin")]
-use rocket::put;
use serde_json::value::to_raw_value;
/// # `PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}`
@@ -15,10 +13,6 @@ use serde_json::value::to_raw_value;
/// Tries to send a redaction event into the room.
///
/// - TODO: Handle txn id
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/rooms/<_>/redact/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn redact_event_route(
db: DatabaseGuard,
diff --git a/src/client_server/report.rs b/src/client_server/report.rs
index 032e446..441e33d 100644
--- a/src/client_server/report.rs
+++ b/src/client_server/report.rs
@@ -1,21 +1,14 @@
-use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
+use crate::{database::DatabaseGuard, utils::HtmlEscape, ConduitResult, Error, Ruma};
use ruma::{
api::client::{error::ErrorKind, r0::room::report_content},
events::room::message,
int,
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{http::RawStr, post};
-
/// # `POST /_matrix/client/r0/rooms/{roomId}/report/{eventId}`
///
/// Reports an inappropriate event to homeserver admins
///
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/report/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn report_event_route(
db: DatabaseGuard,
@@ -70,7 +63,7 @@ pub async fn report_event_route(
pdu.room_id,
pdu.sender,
body.score,
- RawStr::new(&body.reason).html_escape()
+ HtmlEscape(&body.reason)
),
));
diff --git a/src/client_server/room.rs b/src/client_server/room.rs
index 7ea31d8..475c5b4 100644
--- a/src/client_server/room.rs
+++ b/src/client_server/room.rs
@@ -30,9 +30,6 @@ use serde_json::{json, value::to_raw_value};
use std::{cmp::max, collections::BTreeMap, sync::Arc};
use tracing::{info, warn};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
/// # `POST /_matrix/client/r0/createRoom`
///
/// Creates a new room.
@@ -49,10 +46,6 @@ use rocket::{get, post};
/// - Send events listed in initial state
/// - Send events implied by `name` and `topic`
/// - Send invite events
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/createRoom", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_room_route(
db: DatabaseGuard,
@@ -425,10 +418,6 @@ pub async fn create_room_route(
/// Gets a single event.
///
/// - You have to currently be joined to the room (TODO: Respect history visibility)
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/event/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_room_event_route(
db: DatabaseGuard,
@@ -458,10 +447,6 @@ pub async fn get_room_event_route(
/// Lists all aliases of the room.
///
/// - Only users joined to the room are allowed to call this TODO: Allow any user to call it if history_visibility is world readable
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/aliases", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_room_aliases_route(
db: DatabaseGuard,
@@ -496,10 +481,6 @@ pub async fn get_room_aliases_route(
/// - Transfers some state events
/// - Moves local aliases
/// - Modifies old room power levels to prevent users from speaking
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/rooms/<_>/upgrade", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn upgrade_room_route(
db: DatabaseGuard,
diff --git a/src/client_server/search.rs b/src/client_server/search.rs
index f492292..3f8a701 100644
--- a/src/client_server/search.rs
+++ b/src/client_server/search.rs
@@ -1,8 +1,6 @@
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
use ruma::api::client::{error::ErrorKind, r0::search::search_events};
-#[cfg(feature = "conduit_bin")]
-use rocket::post;
use search_events::{EventContextResult, ResultCategories, ResultRoomEvents, SearchResult};
use std::collections::BTreeMap;
@@ -11,10 +9,6 @@ use std::collections::BTreeMap;
/// Searches rooms for messages.
///
/// - Only works if the user is currently joined to the room (TODO: Respect history visibility)
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/search", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn search_events_route(
db: DatabaseGuard,
diff --git a/src/client_server/session.rs b/src/client_server/session.rs
index 61e5519..264eac0 100644
--- a/src/client_server/session.rs
+++ b/src/client_server/session.rs
@@ -19,16 +19,14 @@ struct Claims {
exp: usize,
}
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post};
-
/// # `GET /_matrix/client/r0/login`
///
/// Get the supported login types of this server. One of these should be used as the `type` field
/// when logging in.
-#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))]
-#[tracing::instrument]
-pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
+#[tracing::instrument(skip(_body))]
+pub async fn get_login_types_route(
+ _body: Ruma<get_login_types::Request>,
+) -> ConduitResult<get_login_types::Response> {
Ok(
get_login_types::Response::new(vec![get_login_types::LoginType::Password(
Default::default(),
@@ -48,10 +46,6 @@ pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response>
///
/// Note: You can use [`GET /_matrix/client/r0/login`](fn.get_supported_versions_route.html) to see
/// supported login types.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/login", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn login_route(
db: DatabaseGuard,
@@ -173,10 +167,6 @@ pub async fn login_route(
/// - Deletes device metadata (device id, device display name, last seen ip, last seen ts)
/// - Forgets to-device events
/// - Triggers device list updates
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/logout", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn logout_route(
db: DatabaseGuard,
@@ -203,10 +193,6 @@ pub async fn logout_route(
///
/// Note: This is equivalent to calling [`GET /_matrix/client/r0/logout`](fn.logout_route.html)
/// from each device of this user.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/logout/all", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn logout_all_route(
db: DatabaseGuard,
diff --git a/src/client_server/state.rs b/src/client_server/state.rs
index c07d482..96b2184 100644
--- a/src/client_server/state.rs
+++ b/src/client_server/state.rs
@@ -19,9 +19,6 @@ use ruma::{
EventId, RoomId, UserId,
};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, put};
-
/// # `PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}`
///
/// Sends a state event into the room.
@@ -29,10 +26,6 @@ use rocket::{get, put};
/// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed
/// - If event is new canonical_alias: Rejects if alias is incorrect
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn send_state_event_for_key_route(
db: DatabaseGuard,
@@ -63,10 +56,6 @@ pub async fn send_state_event_for_key_route(
/// - The only requirement for the content is that it has to be valid json
/// - Tries to send the event into the room, auth rules will determine if it is allowed
/// - If event is new canonical_alias: Rejects if alias is incorrect
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn send_state_event_for_empty_key_route(
db: DatabaseGuard,
@@ -103,10 +92,6 @@ pub async fn send_state_event_for_empty_key_route(
/// Get all state events for a room.
///
/// - If not joined: Only works if current room history visibility is world readable
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/state", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_state_events_route(
db: DatabaseGuard,
@@ -155,10 +140,6 @@ pub async fn get_state_events_route(
/// Get single state event of a room.
///
/// - If not joined: Only works if current room history visibility is world readable
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_state_events_for_key_route(
db: DatabaseGuard,
@@ -211,10 +192,6 @@ pub async fn get_state_events_for_key_route(
/// Get single state event of a room.
///
/// - If not joined: Only works if current room history visibility is world readable
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_state_events_for_empty_key_route(
db: DatabaseGuard,
diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs
index 2b814f5..6ba68b0 100644
--- a/src/client_server/sync.rs
+++ b/src/client_server/sync.rs
@@ -20,9 +20,6 @@ use std::{
use tokio::sync::watch::Sender;
use tracing::error;
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, tokio};
-
/// # `GET /_matrix/client/r0/sync`
///
/// Synchronize the client's state with the latest state on the server.
@@ -57,10 +54,6 @@ use rocket::{get, tokio};
///
/// - Sync is handled in an async task, multiple requests from the same device with the same
/// `since` will be cached
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/sync", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn sync_events_route(
db: DatabaseGuard,
diff --git a/src/client_server/tag.rs b/src/client_server/tag.rs
index 42bad4c..cad3421 100644
--- a/src/client_server/tag.rs
+++ b/src/client_server/tag.rs
@@ -8,18 +8,11 @@ use ruma::{
};
use std::collections::BTreeMap;
-#[cfg(feature = "conduit_bin")]
-use rocket::{delete, get, put};
-
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
///
/// Adds a tag to the room.
///
/// - Inserts the tag into the tag event of the room account data.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn update_tag_route(
db: DatabaseGuard,
@@ -58,10 +51,6 @@ pub async fn update_tag_route(
/// Deletes a tag from the room.
///
/// - Removes the tag from the tag event of the room account data.
-#[cfg_attr(
- feature = "conduit_bin",
- delete("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn delete_tag_route(
db: DatabaseGuard,
@@ -97,10 +86,6 @@ pub async fn delete_tag_route(
/// Returns tags on the room.
///
/// - Gets the tag event of the room account data.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/user/<_>/rooms/<_>/tags", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_tags_route(
db: DatabaseGuard,
diff --git a/src/client_server/thirdparty.rs b/src/client_server/thirdparty.rs
index 4305902..d8b7972 100644
--- a/src/client_server/thirdparty.rs
+++ b/src/client_server/thirdparty.rs
@@ -1,19 +1,15 @@
-use crate::ConduitResult;
+use crate::{ConduitResult, Ruma};
use ruma::api::client::r0::thirdparty::get_protocols;
-#[cfg(feature = "conduit_bin")]
-use rocket::get;
use std::collections::BTreeMap;
/// # `GET /_matrix/client/r0/thirdparty/protocols`
///
/// TODO: Fetches all metadata about protocols supported by the homeserver.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/thirdparty/protocols")
-)]
-#[tracing::instrument]
-pub async fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
+#[tracing::instrument(skip(_body))]
+pub async fn get_protocols_route(
+ _body: Ruma<get_protocols::Request>,
+) -> ConduitResult<get_protocols::Response> {
// TODO
Ok(get_protocols::Response {
protocols: BTreeMap::new(),
diff --git a/src/client_server/to_device.rs b/src/client_server/to_device.rs
index e0aa9e9..1269118 100644
--- a/src/client_server/to_device.rs
+++ b/src/client_server/to_device.rs
@@ -10,16 +10,9 @@ use ruma::{
to_device::DeviceIdOrAllDevices,
};
-#[cfg(feature = "conduit_bin")]
-use rocket::put;
-
/// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}`
///
/// Send a to-device event to a set of client devices.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/sendToDevice/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn send_event_to_device_route(
db: DatabaseGuard,
diff --git a/src/client_server/typing.rs b/src/client_server/typing.rs
index 15e74b3..3a61c58 100644
--- a/src/client_server/typing.rs
+++ b/src/client_server/typing.rs
@@ -2,18 +2,11 @@ use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
use create_typing_event::Typing;
use ruma::api::client::r0::typing::create_typing_event;
-#[cfg(feature = "conduit_bin")]
-use rocket::put;
-
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
///
/// Sets the typing state of the sender user.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/client/r0/rooms/<_>/typing/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn create_typing_event_route(
+pub async fn create_typing_event_route(
db: DatabaseGuard,
body: Ruma<create_typing_event::Request<'_>>,
) -> ConduitResult<create_typing_event::Response> {
diff --git a/src/client_server/unversioned.rs b/src/client_server/unversioned.rs
index ea685b4..8b1b66f 100644
--- a/src/client_server/unversioned.rs
+++ b/src/client_server/unversioned.rs
@@ -1,11 +1,8 @@
use std::{collections::BTreeMap, iter::FromIterator};
-use crate::ConduitResult;
+use crate::{ConduitResult, Ruma};
use ruma::api::client::unversioned::get_supported_versions;
-#[cfg(feature = "conduit_bin")]
-use rocket::get;
-
/// # `GET /_matrix/client/versions`
///
/// Get the versions of the specification and unstable features supported by this server.
@@ -16,9 +13,10 @@ use rocket::get;
///
/// Note: Unstable features are used while developing new features. Clients should avoid using
/// unstable features in their stable releases
-#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/versions"))]
-#[tracing::instrument]
-pub async fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
+#[tracing::instrument(skip(_body))]
+pub async fn get_supported_versions_route(
+ _body: Ruma<get_supported_versions::Request>,
+) -> ConduitResult<get_supported_versions::Response> {
let resp = get_supported_versions::Response {
versions: vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()],
unstable_features: BTreeMap::from_iter([("org.matrix.e2e_cross_signing".to_owned(), true)]),
diff --git a/src/client_server/user_directory.rs b/src/client_server/user_directory.rs
index cfcb9bb..c923cee 100644
--- a/src/client_server/user_directory.rs
+++ b/src/client_server/user_directory.rs
@@ -1,18 +1,11 @@
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
use ruma::api::client::r0::user_directory::search_users;
-#[cfg(feature = "conduit_bin")]
-use rocket::post;
-
/// # `POST /_matrix/client/r0/user_directory/search`
///
/// Searches all known users for a match.
///
/// - TODO: Hide users that are not in any public rooms?
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/client/r0/user_directory/search", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn search_users_route(
db: DatabaseGuard,
diff --git a/src/client_server/voip.rs b/src/client_server/voip.rs
index 66a85f0..6abebdc 100644
--- a/src/client_server/voip.rs
+++ b/src/client_server/voip.rs
@@ -7,20 +7,13 @@ use std::time::{Duration, SystemTime};
type HmacSha1 = Hmac<Sha1>;
-#[cfg(feature = "conduit_bin")]
-use rocket::get;
-
/// # `GET /_matrix/client/r0/voip/turnServer`
///
/// TODO: Returns information about the recommended turn server.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/client/r0/voip/turnServer", data = "<body>")
-)]
#[tracing::instrument(skip(body, db))]
pub async fn turn_server_route(
- body: Ruma<get_turn_server_info::Request>,
db: DatabaseGuard,
+ body: Ruma<get_turn_server_info::Request>,
) -> ConduitResult<get_turn_server_info::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
diff --git a/src/config.rs b/src/config.rs
index 4c0fcc2..48ac981 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,4 +1,7 @@
-use std::collections::BTreeMap;
+use std::{
+ collections::BTreeMap,
+ net::{IpAddr, Ipv4Addr},
+};
use ruma::ServerName;
use serde::{de::IgnoredAny, Deserialize};
@@ -10,6 +13,10 @@ use self::proxy::ProxyConfig;
#[derive(Clone, Debug, Deserialize)]
pub struct Config {
+ #[serde(default = "default_address")]
+ pub address: IpAddr,
+ #[serde(default = "default_port")]
+ pub port: u16,
pub server_name: Box<ServerName>,
#[serde(default = "default_database_backend")]
pub database_backend: String,
@@ -90,6 +97,14 @@ fn true_fn() -> bool {
true
}
+fn default_address() -> IpAddr {
+ Ipv4Addr::LOCALHOST.into()
+}
+
+fn default_port() -> u16 {
+ 8000
+}
+
fn default_database_backend() -> String {
"sqlite".to_owned()
}
@@ -123,7 +138,7 @@ fn default_max_concurrent_requests() -> u16 {
}
fn default_log() -> String {
- "info,state_res=warn,rocket=off,_=off,sled=off".to_owned()
+ "info,state_res=warn,_=off,sled=off".to_owned()
}
fn default_turn_ttl() -> u64 {
diff --git a/src/database.rs b/src/database.rs
index 2b1671c..9eb8bd5 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -13,16 +13,12 @@ pub mod transaction_ids;
pub mod uiaa;
pub mod users;
+use self::admin::create_admin_room;
use crate::{utils, Config, Error, Result};
use abstraction::DatabaseEngine;
use directories::ProjectDirs;
+use futures_util::{stream::FuturesUnordered, StreamExt};
use lru_cache::LruCache;
-use rocket::{
- futures::{channel::mpsc, stream::FuturesUnordered, StreamExt},
- outcome::{try_outcome, IntoOutcome},
- request::{FromRequest, Request},
- Shutdown, State,
-};
use ruma::{DeviceId, EventId, RoomId, UserId};
use std::{
collections::{BTreeMap, HashMap, HashSet},
@@ -33,11 +29,9 @@ use std::{
path::Path,
sync::{Arc, Mutex, RwLock},
};
-use tokio::sync::{OwnedRwLockReadGuard, RwLock as TokioRwLock, Semaphore};
+use tokio::sync::{mpsc, OwnedRwLockReadGuard, RwLock as TokioRwLock, Semaphore};
use tracing::{debug, error, info, warn};
-use self::admin::create_admin_room;
-
pub struct Database {
_db: Arc<dyn DatabaseEngine>,
pub globals: globals::Globals,
@@ -151,8 +145,8 @@ impl Database {
eprintln!("ERROR: Max request size is less than 1KB. Please increase it.");
}
- let (admin_sender, admin_receiver) = mpsc::unbounded();
- let (sending_sender, sending_receiver) = mpsc::unbounded();
+ let (admin_sender, admin_receiver) = mpsc::unbounded_channel();
+ let (sending_sender, sending_receiver) = mpsc::unbounded_channel();
let db = Arc::new(TokioRwLock::from(Self {
_db: builder.clone(),
@@ -764,14 +758,9 @@ impl Database {
}
#[cfg(feature = "conduit_bin")]
- pub async fn start_on_shutdown_tasks(db: Arc<TokioRwLock<Self>>, shutdown: Shutdown) {
- tokio::spawn(async move {
- shutdown.await;
-
- info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers...");
-
- db.read().await.globals.rotate.fire();
- });
+ pub async fn on_shutdown(db: Arc<TokioRwLock<Self>>) {
+ info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers...");
+ db.read().await.globals.rotate.fire();
}
pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) {
@@ -948,14 +937,23 @@ impl Deref for DatabaseGuard {
}
}
-#[rocket::async_trait]
-impl<'r> FromRequest<'r> for DatabaseGuard {
- type Error = ();
+#[cfg(feature = "conduit_bin")]
+#[axum::async_trait]
+impl<B> axum::extract::FromRequest<B> for DatabaseGuard
+where
+ B: Send,
+{
+ type Rejection = axum::extract::rejection::ExtensionRejection;
+
+ async fn from_request(
+ req: &mut axum::extract::RequestParts<B>,
+ ) -> Result<Self, Self::Rejection> {
+ use axum::extract::Extension;
- async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
- let db = try_outcome!(req.guard::<&State<Arc<TokioRwLock<Database>>>>().await);
+ let Extension(db): Extension<Arc<TokioRwLock<Database>>> =
+ Extension::from_request(req).await?;
- Ok(DatabaseGuard(Arc::clone(db).read_owned().await)).or_forward(())
+ Ok(DatabaseGuard(db.read_owned().await))
}
}
diff --git a/src/database/admin.rs b/src/database/admin.rs
index 9bbfd4e..e4b7e0f 100644
--- a/src/database/admin.rs
+++ b/src/database/admin.rs
@@ -1,34 +1,41 @@
-use std::{collections::BTreeMap, convert::TryFrom, convert::TryInto, sync::Arc, time::Instant};
+use std::{
+ collections::BTreeMap,
+ convert::{TryFrom, TryInto},
+ sync::Arc,
+ time::Instant,
+};
use crate::{
error::{Error, Result},
pdu::PduBuilder,
- server_server, Database, PduEvent,
+ server_server,
+ utils::HtmlEscape,
+ Database, PduEvent,
};
use clap::Parser;
use regex::Regex;
-use rocket::{
- futures::{channel::mpsc, stream::StreamExt},
- http::RawStr,
-};
use ruma::{
- events::room::{
- canonical_alias::RoomCanonicalAliasEventContent,
- create::RoomCreateEventContent,
- guest_access::{GuestAccess, RoomGuestAccessEventContent},
- history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
- join_rules::{JoinRule, RoomJoinRulesEventContent},
- member::{MembershipState, RoomMemberEventContent},
- name::RoomNameEventContent,
- power_levels::RoomPowerLevelsEventContent,
- topic::RoomTopicEventContent,
+ events::{
+ room::{
+ canonical_alias::RoomCanonicalAliasEventContent,
+ create::RoomCreateEventContent,
+ guest_access::{GuestAccess, RoomGuestAccessEventContent},
+ history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
+ join_rules::{JoinRule, RoomJoinRulesEventContent},
+ member::{MembershipState, RoomMemberEventContent},
+ message::RoomMessageEventContent,
+ name::RoomNameEventContent,
+ power_levels::RoomPowerLevelsEventContent,
+ topic::RoomTopicEventContent,
+ },
+ EventType,
},
- events::{room::message::RoomMessageEventContent, EventType},
identifiers::{EventId, RoomAliasId, RoomId, RoomName, RoomVersionId, ServerName, UserId},
};
use serde_json::value::to_raw_value;
-use tokio::sync::{MutexGuard, RwLock, RwLockReadGuard};
+use tokio::sync::{mpsc, MutexGuard, RwLock, RwLockReadGuard};
+#[derive(Debug)]
pub enum AdminRoomEvent {
ProcessMessage(String),
SendMessage(RoomMessageEventContent),
@@ -91,7 +98,7 @@ impl Admin {
loop {
tokio::select! {
- Some(event) = receiver.next() => {
+ Some(event) = receiver.recv() => {
let guard = db.read().await;
let mutex_state = Arc::clone(
guard.globals
@@ -123,13 +130,13 @@ impl Admin {
pub fn process_message(&self, room_message: String) {
self.sender
- .unbounded_send(AdminRoomEvent::ProcessMessage(room_message))
+ .send(AdminRoomEvent::ProcessMessage(room_message))
.unwrap();
}
pub fn send_message(&self, message_content: RoomMessageEventContent) {
self.sender
- .unbounded_send(AdminRoomEvent::SendMessage(message_content))
+ .send(AdminRoomEvent::SendMessage(message_content))
.unwrap();
}
}
@@ -405,7 +412,7 @@ fn process_admin_command(
} else {
"PDU was accepted"
},
- RawStr::new(&json_text).html_escape()
+ HtmlEscape(&json_text)
),
)
}
diff --git a/src/database/sending.rs b/src/database/sending.rs
index 4a03285..2d64be1 100644
--- a/src/database/sending.rs
+++ b/src/database/sending.rs
@@ -9,11 +9,8 @@ use crate::{
appservice_server, database::pusher, server_server, utils, Database, Error, PduEvent, Result,
};
use federation::transactions::send_transaction_message;
+use futures_util::{stream::FuturesUnordered, StreamExt};
use ring::digest;
-use rocket::futures::{
- channel::mpsc,
- stream::{FuturesUnordered, StreamExt},
-};
use ruma::{
api::{
appservice,
@@ -33,7 +30,7 @@ use ruma::{
};
use tokio::{
select,
- sync::{RwLock, Semaphore},
+ sync::{mpsc, RwLock, Semaphore},
};
use tracing::{error, warn};
@@ -170,7 +167,7 @@ impl Sending {
Self::parse_servercurrentevent(&k, v).ok().map(|ev| (ev, k))
})
.take(30)
- .collect::<>();
+ .collect();
// TODO: find edus
@@ -207,7 +204,7 @@ impl Sending {
}
};
},
- Some((key, value)) = receiver.next() => {
+ Some((key, value)) = receiver.recv() => {
if let Ok((outgoing_kind, event)) = Self::parse_servercurrentevent(&key, value) {
let guard = db.read().await;
@@ -417,7 +414,7 @@ impl Sending {
key.push(0xff);
key.extend_from_slice(pdu_id);
self.servernameevent_data.insert(&key, &[])?;
- self.sender.unbounded_send((key, vec![])).unwrap();
+ self.sender.send((key, vec![])).unwrap();
Ok(())
}
@@ -433,7 +430,7 @@ impl Sending {
key.push(0xff);
key.extend_from_slice(pdu_id);
- self.sender.unbounded_send((key.clone(), vec![])).unwrap();
+ self.sender.send((key.clone(), vec![])).unwrap();
(key, Vec::new())
});
@@ -454,7 +451,7 @@ impl Sending {
key.push(0xff);
key.extend_from_slice(&id.to_be_bytes());
self.servernameevent_data.insert(&key, &serialized)?;
- self.sender.unbounded_send((key, serialized)).unwrap();
+ self.sender.send((key, serialized)).unwrap();
Ok(())
}
@@ -466,7 +463,7 @@ impl Sending {
key.push(0xff);
key.extend_from_slice(pdu_id);
self.servernameevent_data.insert(&key, &[])?;
- self.sender.unbounded_send((key, vec![])).unwrap();
+ self.sender.send((key, vec![])).unwrap();
Ok(())
}
diff --git a/src/error.rs b/src/error.rs
index 5ffe48c..817ef50 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,27 +1,20 @@
+use std::convert::Infallible;
+
+use http::StatusCode;
use ruma::{
api::client::{
error::{Error as RumaError, ErrorKind},
- r0::uiaa::UiaaInfo,
+ r0::uiaa::{UiaaInfo, UiaaResponse},
},
ServerName,
};
use thiserror::Error;
-use tracing::warn;
+use tracing::{error, warn};
#[cfg(feature = "persy")]
use persy::PersyError;
-#[cfg(feature = "conduit_bin")]
-use {
- crate::RumaResponse,
- http::StatusCode,
- rocket::{
- response::{self, Responder},
- Request,
- },
- ruma::api::client::r0::uiaa::UiaaResponse,
- tracing::error,
-};
+use crate::RumaResponse;
pub type Result<T, E = Error> = std::result::Result<T, E>;
@@ -81,6 +74,9 @@ pub enum Error {
BadRequest(ErrorKind, &'static str),
#[error("{0}")]
Conflict(&'static str), // This is only needed for when a room alias already exists
+ #[cfg(feature = "conduit_bin")]
+ #[error("{0}")]
+ ExtensionError(#[from] axum::extract::rejection::ExtensionRejection),
}
impl Error {
@@ -139,16 +135,6 @@ impl Error {
}
}
-#[cfg(feature = "conduit_bin")]
-impl<'r, 'o> Responder<'r, 'o> for Error
-where
- 'o: 'r,
-{
- fn respond_to(self, r: &'r Request<'_>) -> response::Result<'o> {
- self.to_response().respond_to(r)
- }
-}
-
#[cfg(feature = "persy")]
impl<T: Into<PersyError>> From<persy::PE<T>> for Error {
fn from(err: persy::PE<T>) -> Self {
@@ -157,3 +143,16 @@ impl<T: Into<PersyError>> From<persy::PE<T>> for Error {
}
}
}
+
+impl From<Infallible> for Error {
+ fn from(i: Infallible) -> Self {
+ match i {}
+ }
+}
+
+#[cfg(feature = "conduit_bin")]
+impl axum::response::IntoResponse for Error {
+ fn into_response(self) -> axum::response::Response {
+ self.to_response().into_response()
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 030dfc3..135ab85 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,8 +7,6 @@
#![allow(clippy::suspicious_else_formatting)]
#![deny(clippy::dbg_macro)]
-use std::ops::Deref;
-
mod config;
mod database;
mod error;
@@ -24,16 +22,4 @@ pub use config::Config;
pub use database::Database;
pub use error::{Error, Result};
pub use pdu::PduEvent;
-pub use rocket::Config as RocketConfig;
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
-
-pub struct State<'r, T: Send + Sync + 'static>(pub &'r T);
-
-impl<'r, T: Send + Sync + 'static> Deref for State<'r, T> {
- type Target = T;
-
- #[inline(always)]
- fn deref(&self) -> &T {
- self.0
- }
-}
diff --git a/src/main.rs b/src/main.rs
index ea09dd5..3ab1294 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,24 +7,37 @@
#![allow(clippy::suspicious_else_formatting)]
#![deny(clippy::dbg_macro)]
-use std::sync::Arc;
+use std::{future::Future, net::SocketAddr, sync::Arc, time::Duration};
-use maplit::hashset;
+use axum::{
+ extract::{FromRequest, MatchedPath},
+ handler::Handler,
+ routing::{get, on, MethodFilter},
+ Router,
+};
+use figment::{
+ providers::{Env, Format, Toml},
+ Figment,
+};
+use http::{
+ header::{self, HeaderName},
+ Method,
+};
use opentelemetry::trace::{FutureExt, Tracer};
-use rocket::{
- catch, catchers,
- figment::{
- providers::{Env, Format, Toml},
- Figment,
- },
- routes, Request,
+use ruma::{
+ api::{IncomingRequest, Metadata},
+ Outgoing,
+};
+use tokio::{signal, sync::RwLock};
+use tower::ServiceBuilder;
+use tower_http::{
+ cors::{self, CorsLayer},
+ trace::TraceLayer,
+ ServiceBuilderExt as _,
};
-use ruma::api::client::error::ErrorKind;
-use tokio::sync::RwLock;
use tracing_subscriber::{prelude::*, EnvFilter};
pub use conduit::*; // Re-export everything from the library crate
-pub use rocket::State;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc;
@@ -33,160 +46,10 @@ use tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
-fn setup_rocket(config: Figment, data: Arc<RwLock<Database>>) -> rocket::Rocket<rocket::Build> {
- rocket::custom(config)
- .manage(data)
- .mount(
- "/",
- routes![
- client_server::get_supported_versions_route,
- client_server::get_register_available_route,
- client_server::register_route,
- client_server::get_login_types_route,
- client_server::login_route,
- client_server::whoami_route,
- client_server::logout_route,
- client_server::logout_all_route,
- client_server::change_password_route,
- client_server::deactivate_route,
- client_server::third_party_route,
- client_server::get_capabilities_route,
- client_server::get_pushrules_all_route,
- client_server::set_pushrule_route,
- client_server::get_pushrule_route,
- client_server::set_pushrule_enabled_route,
- client_server::get_pushrule_enabled_route,
- client_server::get_pushrule_actions_route,
- client_server::set_pushrule_actions_route,
- client_server::delete_pushrule_route,
- client_server::get_room_event_route,
- client_server::get_room_aliases_route,
- client_server::get_filter_route,
- client_server::create_filter_route,
- client_server::set_global_account_data_route,
- client_server::set_room_account_data_route,
- client_server::get_global_account_data_route,
- client_server::get_room_account_data_route,
- client_server::set_displayname_route,
- client_server::get_displayname_route,
- client_server::set_avatar_url_route,
- client_server::get_avatar_url_route,
- client_server::get_profile_route,
- client_server::set_presence_route,
- client_server::get_presence_route,
- client_server::upload_keys_route,
- client_server::get_keys_route,
- client_server::claim_keys_route,
- client_server::create_backup_route,
- client_server::update_backup_route,
- client_server::delete_backup_route,
- client_server::get_latest_backup_route,
- client_server::get_backup_route,
- client_server::add_backup_key_sessions_route,
- client_server::add_backup_keys_route,
- client_server::delete_backup_key_session_route,
- client_server::delete_backup_key_sessions_route,
- client_server::delete_backup_keys_route,
- client_server::get_backup_key_session_route,
- client_server::get_backup_key_sessions_route,
- client_server::get_backup_keys_route,
- client_server::set_read_marker_route,
- client_server::create_receipt_route,
- client_server::create_typing_event_route,
- client_server::create_room_route,
- client_server::redact_event_route,
- client_server::report_event_route,
- client_server::create_alias_route,
- client_server::delete_alias_route,
- client_server::get_alias_route,
- client_server::join_room_by_id_route,
- client_server::join_room_by_id_or_alias_route,
- client_server::joined_members_route,
- client_server::leave_room_route,
- client_server::forget_room_route,
- client_server::joined_rooms_route,
- client_server::kick_user_route,
- client_server::ban_user_route,
- client_server::unban_user_route,
- client_server::invite_user_route,
- client_server::set_room_visibility_route,
- client_server::get_room_visibility_route,
- client_server::get_public_rooms_route,
- client_server::get_public_rooms_filtered_route,
- client_server::search_users_route,
- client_server::get_member_events_route,
- client_server::get_protocols_route,
- client_server::send_message_event_route,
- client_server::send_state_event_for_key_route,
- client_server::send_state_event_for_empty_key_route,
- client_server::get_state_events_route,
- client_server::get_state_events_for_key_route,
- client_server::get_state_events_for_empty_key_route,
- client_server::sync_events_route,
- client_server::get_context_route,
- client_server::get_message_events_route,
- client_server::search_events_route,
- client_server::turn_server_route,
- client_server::send_event_to_device_route,
- client_server::get_media_config_route,
- client_server::create_content_route,
- client_server::get_content_as_filename_route,
- client_server::get_content_route,
- client_server::get_content_thumbnail_route,
- client_server::get_devices_route,
- client_server::get_device_route,
- client_server::update_device_route,
- client_server::delete_device_route,
- client_server::delete_devices_route,
- client_server::get_tags_route,
- client_server::update_tag_route,
- client_server::delete_tag_route,
- client_server::options_route,
- client_server::upload_signing_keys_route,
- client_server::upload_signatures_route,
- client_server::get_key_changes_route,
- client_server::get_pushers_route,
- client_server::set_pushers_route,
- // client_server::third_party_route,
- client_server::upgrade_room_route,
- server_server::get_server_version_route,
- server_server::get_server_keys_route,
- server_server::get_server_keys_deprecated_route,
- server_server::get_public_rooms_route,
- server_server::get_public_rooms_filtered_route,
- server_server::send_transaction_message_route,
- server_server::get_event_route,
- server_server::get_missing_events_route,
- server_server::get_event_authorization_route,
- server_server::get_room_state_route,
- server_server::get_room_state_ids_route,
- server_server::create_join_event_template_route,
- server_server::create_join_event_v1_route,
- server_server::create_join_event_v2_route,
- server_server::create_invite_route,
- server_server::get_devices_route,
- server_server::get_room_information_route,
- server_server::get_profile_information_route,
- server_server::get_keys_route,
- server_server::claim_keys_route,
- ],
- )
- .register(
- "/",
- catchers![
- not_found_catcher,
- forbidden_catcher,
- unknown_token_catcher,
- missing_token_catcher,
- bad_json_catcher
- ],
- )
-}
-
-#[rocket::main]
+#[tokio::main]
async fn main() {
let raw_config =
- Figment::from(default_config())
+ Figment::new()
.merge(
Toml::file(Env::var("CONDUIT_CONFIG").expect(
"The CONDUIT_CONFIG env var needs to be set. Example: /etc/conduit.toml",
@@ -217,14 +80,7 @@ async fn main() {
}
};
- let rocket = setup_rocket(raw_config, Arc::clone(&db))
- .ignite()
- .await
- .unwrap();
-
- Database::start_on_shutdown_tasks(db, rocket.shutdown()).await;
-
- rocket.launch().await.unwrap();
+ run_server(&config, db).await.unwrap();
};
if config.allow_jaeger {
@@ -264,55 +120,282 @@ async fn main() {
}
}
-#[catch(404)]
-fn not_found_catcher(_: &Request<'_>) -> String {
- "404 Not Found".to_owned()
-}
+async fn run_server(config: &Config, db: Arc<RwLock<Database>>) -> hyper::Result<()> {
+ let listen_addr = SocketAddr::from((config.address, config.port));
-#[catch(580)]
-fn forbidden_catcher() -> Result<()> {
- Err(Error::BadRequest(ErrorKind::Forbidden, "Forbidden."))
-}
+ let x_requested_with = HeaderName::from_static("x-requested-with");
-#[catch(581)]
-fn unknown_token_catcher() -> Result<()> {
- Err(Error::BadRequest(
- ErrorKind::UnknownToken { soft_logout: false },
- "Unknown token.",
- ))
-}
+ let middlewares = ServiceBuilder::new()
+ .sensitive_headers([header::AUTHORIZATION])
+ .layer(
+ TraceLayer::new_for_http().make_span_with(|request: &http::Request<_>| {
+ let path = if let Some(path) = request.extensions().get::<MatchedPath>() {
+ path.as_str()
+ } else {
+ request.uri().path()
+ };
+
+ tracing::info_span!("http_request", %path)
+ }),
+ )
+ .compression()
+ .layer(
+ CorsLayer::new()
+ .allow_origin(cors::any())
+ .allow_methods([
+ Method::GET,
+ Method::POST,
+ Method::PUT,
+ Method::DELETE,
+ Method::OPTIONS,
+ ])
+ .allow_headers([
+ header::ORIGIN,
+ x_requested_with,
+ header::CONTENT_TYPE,
+ header::ACCEPT,
+ header::AUTHORIZATION,
+ ])
+ .max_age(Duration::from_secs(86400)),
+ )
+ .add_extension(db.clone());
+
+ axum::Server::bind(&listen_addr)
+ .serve(routes().layer(middlewares).into_make_service())
+ .with_graceful_shutdown(shutdown_signal())
+ .await?;
+
+ // After serve exits and before exiting, shutdown the DB
+ Database::on_shutdown(db).await;
-#[catch(582)]
-fn missing_token_catcher() -> Result<()> {
- Err(Error::BadRequest(ErrorKind::MissingToken, "Missing token."))
+ Ok(())
}
-#[catch(583)]
-fn bad_json_catcher() -> Result<()> {
- Err(Error::BadRequest(ErrorKind::BadJson, "Bad json."))
+fn routes() -> Router {
+ Router::new()
+ .ruma_route(client_server::get_supported_versions_route)
+ .ruma_route(client_server::get_register_available_route)
+ .ruma_route(client_server::register_route)
+ .ruma_route(client_server::get_login_types_route)
+ .ruma_route(client_server::login_route)
+ .ruma_route(client_server::whoami_route)
+ .ruma_route(client_server::logout_route)
+ .ruma_route(client_server::logout_all_route)
+ .ruma_route(client_server::change_password_route)
+ .ruma_route(client_server::deactivate_route)
+ .ruma_route(client_server::third_party_route)
+ .ruma_route(client_server::get_capabilities_route)
+ .ruma_route(client_server::get_pushrules_all_route)
+ .ruma_route(client_server::set_pushrule_route)
+ .ruma_route(client_server::get_pushrule_route)
+ .ruma_route(client_server::set_pushrule_enabled_route)
+ .ruma_route(client_server::get_pushrule_enabled_route)
+ .ruma_route(client_server::get_pushrule_actions_route)
+ .ruma_route(client_server::set_pushrule_actions_route)
+ .ruma_route(client_server::delete_pushrule_route)
+ .ruma_route(client_server::get_room_event_route)
+ .ruma_route(client_server::get_room_aliases_route)
+ .ruma_route(client_server::get_filter_route)
+ .ruma_route(client_server::create_filter_route)
+ .ruma_route(client_server::set_global_account_data_route)
+ .ruma_route(client_server::set_room_account_data_route)
+ .ruma_route(client_server::get_global_account_data_route)
+ .ruma_route(client_server::get_room_account_data_route)
+ .ruma_route(client_server::set_displayname_route)
+ .ruma_route(client_server::get_displayname_route)
+ .ruma_route(client_server::set_avatar_url_route)
+ .ruma_route(client_server::get_avatar_url_route)
+ .ruma_route(client_server::get_profile_route)
+ .ruma_route(client_server::set_presence_route)
+ .ruma_route(client_server::get_presence_route)
+ .ruma_route(client_server::upload_keys_route)
+ .ruma_route(client_server::get_keys_route)
+ .ruma_route(client_server::claim_keys_route)
+ .ruma_route(client_server::create_backup_route)
+ .ruma_route(client_server::update_backup_route)
+ .ruma_route(client_server::delete_backup_route)
+ .ruma_route(client_server::get_latest_backup_route)
+ .ruma_route(client_server::get_backup_route)
+ .ruma_route(client_server::add_backup_key_sessions_route)
+ .ruma_route(client_server::add_backup_keys_route)
+ .ruma_route(client_server::delete_backup_key_session_route)
+ .ruma_route(client_server::delete_backup_key_sessions_route)
+ .ruma_route(client_server::delete_backup_keys_route)
+ .ruma_route(client_server::get_backup_key_session_route)
+ .ruma_route(client_server::get_backup_key_sessions_route)
+ .ruma_route(client_server::get_backup_keys_route)
+ .ruma_route(client_server::set_read_marker_route)
+ .ruma_route(client_server::create_receipt_route)
+ .ruma_route(client_server::create_typing_event_route)
+ .ruma_route(client_server::create_room_route)
+ .ruma_route(client_server::redact_event_route)
+ .ruma_route(client_server::report_event_route)
+ .ruma_route(client_server::create_alias_route)
+ .ruma_route(client_server::delete_alias_route)
+ .ruma_route(client_server::get_alias_route)
+ .ruma_route(client_server::join_room_by_id_route)
+ .ruma_route(client_server::join_room_by_id_or_alias_route)
+ .ruma_route(client_server::joined_members_route)
+ .ruma_route(client_server::leave_room_route)
+ .ruma_route(client_server::forget_room_route)
+ .ruma_route(client_server::joined_rooms_route)
+ .ruma_route(client_server::kick_user_route)
+ .ruma_route(client_server::ban_user_route)
+ .ruma_route(client_server::unban_user_route)
+ .ruma_route(client_server::invite_user_route)
+ .ruma_route(client_server::set_room_visibility_route)
+ .ruma_route(client_server::get_room_visibility_route)
+ .ruma_route(client_server::get_public_rooms_route)
+ .ruma_route(client_server::get_public_rooms_filtered_route)
+ .ruma_route(client_server::search_users_route)
+ .ruma_route(client_server::get_member_events_route)
+ .ruma_route(client_server::get_protocols_route)
+ .ruma_route(client_server::send_message_event_route)
+ .ruma_route(client_server::send_state_event_for_key_route)
+ .ruma_route(client_server::send_state_event_for_empty_key_route)
+ .ruma_route(client_server::get_state_events_route)
+ .ruma_route(client_server::get_state_events_for_key_route)
+ .ruma_route(client_server::get_state_events_for_empty_key_route)
+ .route(
+ "/_matrix/client/r0/sync",
+ get(client_server::sync_events_route),
+ )
+ .ruma_route(client_server::get_context_route)
+ .ruma_route(client_server::get_message_events_route)
+ .ruma_route(client_server::search_events_route)
+ .ruma_route(client_server::turn_server_route)
+ .ruma_route(client_server::send_event_to_device_route)
+ .ruma_route(client_server::get_media_config_route)
+ .ruma_route(client_server::create_content_route)
+ .ruma_route(client_server::get_content_route)
+ .ruma_route(client_server::get_content_as_filename_route)
+ .ruma_route(client_server::get_content_thumbnail_route)
+ .ruma_route(client_server::get_devices_route)
+ .ruma_route(client_server::get_device_route)
+ .ruma_route(client_server::update_device_route)
+ .ruma_route(client_server::delete_device_route)
+ .ruma_route(client_server::delete_devices_route)
+ .ruma_route(client_server::get_tags_route)
+ .ruma_route(client_server::update_tag_route)
+ .ruma_route(client_server::delete_tag_route)
+ .ruma_route(client_server::upload_signing_keys_route)
+ .ruma_route(client_server::upload_signatures_route)
+ .ruma_route(client_server::get_key_changes_route)
+ .ruma_route(client_server::get_pushers_route)
+ .ruma_route(client_server::set_pushers_route)
+ // .ruma_route(client_server::third_party_route)
+ .ruma_route(client_server::upgrade_room_route)
+ .ruma_route(server_server::get_server_version_route)
+ .route(
+ "/_matrix/key/v2/server",
+ get(server_server::get_server_keys_route),
+ )
+ .route(
+ "/_matrix/key/v2/server/:key_id",
+ get(server_server::get_server_keys_deprecated_route),
+ )
+ .ruma_route(server_server::get_public_rooms_route)
+ .ruma_route(server_server::get_public_rooms_filtered_route)
+ .ruma_route(server_server::send_transaction_message_route)
+ .ruma_route(server_server::get_event_route)
+ .ruma_route(server_server::get_missing_events_route)
+ .ruma_route(server_server::get_event_authorization_route)
+ .ruma_route(server_server::get_room_state_route)
+ .ruma_route(server_server::get_room_state_ids_route)
+ .ruma_route(server_server::create_join_event_template_route)
+ .ruma_route(server_server::create_join_event_v1_route)
+ .ruma_route(server_server::create_join_event_v2_route)
+ .ruma_route(server_server::create_invite_route)
+ .ruma_route(server_server::get_devices_route)
+ .ruma_route(server_server::get_room_information_route)
+ .ruma_route(server_server::get_profile_information_route)
+ .ruma_route(server_server::get_keys_route)
+ .ruma_route(server_server::claim_keys_route)
}
-fn default_config() -> rocket::Config {
- use rocket::config::{LogLevel, Shutdown, Sig};
+async fn shutdown_signal() {
+ let ctrl_c = async {
+ signal::ctrl_c()
+ .await
+ .expect("failed to install Ctrl+C handler");
+ };
+
+ #[cfg(unix)]
+ let terminate = async {
+ signal::unix::signal(signal::unix::SignalKind::terminate())
+ .expect("failed to install signal handler")
+ .recv()
+ .await;
+ };
- rocket::Config {
- // Disable rocket's logging to get only tracing-subscriber's log output
- log_level: LogLevel::Off,
- shutdown: Shutdown {
- // Once shutdown is triggered, this is the amount of seconds before rocket
- // will forcefully start shutting down connections, this gives enough time to /sync
- // requests and the like (which havent gotten the memo, somehow) to still complete gracefully.
- grace: 35,
+ #[cfg(not(unix))]
+ let terminate = std::future::pending::<()>();
- // After the grace period, rocket starts shutting down connections, and waits at least this
- // many seconds before forcefully shutting all of them down.
- mercy: 10,
+ tokio::select! {
+ _ = ctrl_c => {},
+ _ = terminate => {},
+ }
+}
- #[cfg(unix)]
- signals: hashset![Sig::Term, Sig::Int],
+trait RouterExt {
+ fn ruma_route<H, T>(self, handler: H) -> Self
+ where
+ H: RumaHandler<T>,
+ T: 'static;
+}
- ..Shutdown::default()
- },
- ..rocket::Config::release_default()
+impl RouterExt for Router {
+ fn ruma_route<H, T>(self, handler: H) -> Self
+ where
+ H: RumaHandler<T>,
+ T: 'static,
+ {
+ let meta = H::METADATA;
+ let method_filter = match meta.method {
+ Method::DELETE => MethodFilter::DELETE,
+ Method::GET => MethodFilter::GET,
+ Method::HEAD => MethodFilter::HEAD,
+ Method::OPTIONS => MethodFilter::OPTIONS,
+ Method::PATCH => MethodFilter::PATCH,
+ Method::POST => MethodFilter::POST,
+ Method::PUT => MethodFilter::PUT,
+ Method::TRACE => MethodFilter::TRACE,
+ _ => panic!(""),
+ };
+
+ self.route(meta.path, on(method_filter, handler))
}
}
+
+pub trait RumaHandler<T>: Handler<T> {
+ const METADATA: Metadata;
+}
+
+macro_rules! impl_ruma_handler {
+ ( $($ty:ident),* $(,)? ) => {
+ #[axum::async_trait]
+ #[allow(non_snake_case)]
+ impl<Req, F, Fut, $($ty,)*> RumaHandler<($($ty,)* Ruma<Req>,)> for F
+ where
+ Req: Outgoing,
+ Req::Incoming: IncomingRequest + Send,
+ F: FnOnce($($ty,)* Ruma<Req>) -> Fut + Clone + Send + 'static,
+ Fut: Future<Output = ConduitResult<
+ <Req::Incoming as IncomingRequest>::OutgoingResponse
+ >> + Send,
+ $( $ty: FromRequest<axum::body::Body> + Send, )*
+ {
+ const METADATA: Metadata = Req::Incoming::METADATA;
+ }
+ };
+}
+
+impl_ruma_handler!();
+impl_ruma_handler!(T1);
+impl_ruma_handler!(T1, T2);
+impl_ruma_handler!(T1, T2, T3);
+impl_ruma_handler!(T1, T2, T3, T4);
+impl_ruma_handler!(T1, T2, T3, T4, T5);
+impl_ruma_handler!(T1, T2, T3, T4, T5, T6);
+impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7);
+impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7, T8);
diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs
index 1bd921d..12be79a 100644
--- a/src/ruma_wrapper.rs
+++ b/src/ruma_wrapper.rs
@@ -1,6 +1,6 @@
-use crate::{database::DatabaseGuard, Error};
+use crate::Error;
use ruma::{
- api::{client::r0::uiaa::UiaaResponse, OutgoingResponse},
+ api::client::r0::uiaa::UiaaResponse,
identifiers::{DeviceId, UserId},
signatures::CanonicalJsonValue,
Outgoing, ServerName,
@@ -8,24 +8,9 @@ use ruma::{
use std::ops::Deref;
#[cfg(feature = "conduit_bin")]
-use {
- crate::server_server,
- rocket::{
- data::{self, ByteUnit, Data, FromData},
- http::Status,
- outcome::Outcome::*,
- response::{self, Responder},
- tokio::io::AsyncReadExt,
- Request,
- },
- ruma::api::{AuthScheme, IncomingRequest},
- std::collections::BTreeMap,
- std::io::Cursor,
- tracing::{debug, warn},
-};
+mod axum;
-/// This struct converts rocket requests into ruma structs by converting them into http requests
-/// first.
+/// Extractor for Ruma request structs
pub struct Ruma<T: Outgoing> {
pub body: T::Incoming,
pub sender_user: Option<Box<UserId>>,
@@ -36,300 +21,6 @@ pub struct Ruma<T: Outgoing> {
pub from_appservice: bool,
}
-#[cfg(feature = "conduit_bin")]
-#[rocket::async_trait]
-impl<'a, T: Outgoing> FromData<'a> for Ruma<T>
-where
- T::Incoming: IncomingRequest,
-{
- type Error = ();
-
- #[tracing::instrument(skip(request, data))]
- async fn from_data(
- request: &'a Request<'_>,
- data: Data<'a>,
- ) -> data::Outcome<'a, Self, Self::Error> {
- let metadata = T::Incoming::METADATA;
- let db = request
- .guard::<DatabaseGuard>()
- .await
- .expect("database was loaded");
-
- // Get token from header or query value
- let token = request
- .headers()
- .get_one("Authorization")
- .and_then(|s| s.get(7..)) // Split off "Bearer "
- .or_else(|| request.query_value("access_token").and_then(|r| r.ok()));
-
- let limit = db.globals.max_request_size();
- let mut handle = data.open(ByteUnit::Byte(limit.into()));
- let mut body = Vec::new();
- if handle.read_to_end(&mut body).await.is_err() {
- // Client disconnected
- // Missing Token
- return Failure((Status::new(582), ()));
- }
-
- let mut json_body = serde_json::from_slice::<CanonicalJsonValue>(&body).ok();
-
- let (sender_user, sender_device, sender_servername, from_appservice) = if let Some((
- _id,
- registration,
- )) = db
- .appservice
- .all()
- .unwrap()
- .iter()
- .find(|(_id, registration)| {
- registration
- .get("as_token")
- .and_then(|as_token| as_token.as_str())
- .map_or(false, |as_token| token == Some(as_token))
- }) {
- match metadata.authentication {
- AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
- let user_id = request.query_value::<String>("user_id").map_or_else(
- || {
- UserId::parse_with_server_name(
- registration
- .get("sender_localpart")
- .unwrap()
- .as_str()
- .unwrap(),
- db.globals.server_name(),
- )
- .unwrap()
- },
- |string| {
- UserId::parse(string.expect("parsing to string always works")).unwrap()
- },
- );
-
- if !db.users.exists(&user_id).unwrap() {
- // Forbidden
- return Failure((Status::new(580), ()));
- }
-
- // TODO: Check if appservice is allowed to be that user
- (Some(user_id), None, None, true)
- }
- AuthScheme::ServerSignatures => (None, None, None, true),
- AuthScheme::None => (None, None, None, true),
- }
- } else {
- match metadata.authentication {
- AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
- if let Some(token) = token {
- match db.users.find_from_token(token).unwrap() {
- // Unknown Token
- None => return Failure((Status::new(581), ())),
- Some((user_id, device_id)) => (
- Some(user_id),
- Some(Box::<DeviceId>::from(device_id)),
- None,
- false,
- ),
- }
- } else {
- // Missing Token
- return Failure((Status::new(582), ()));
- }
- }
- AuthScheme::ServerSignatures => {
- // Get origin from header
- let x_matrix = match request
- .headers()
- .get_one("Authorization")
- .and_then(|s| s.get(9..)) // Split off "X-Matrix " and parse the rest
- .map(|s| {
- s.split_terminator(',')
- .map(|field| {
- let mut splits = field.splitn(2, '=');
- (splits.next(), splits.next().map(|s| s.trim_matches('"')))
- })
- .collect::<BTreeMap<_, _>>()
- }) {
- Some(t) => t,
- None => {
- warn!("No Authorization header");
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let origin_str = match x_matrix.get(&Some("origin")) {
- Some(Some(o)) => *o,
- _ => {
- warn!("Invalid X-Matrix header origin field: {:?}", x_matrix);
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let origin = match ServerName::parse(origin_str) {
- Ok(s) => s,
- _ => {
- warn!(
- "Invalid server name in X-Matrix header origin field: {:?}",
- x_matrix
- );
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let key = match x_matrix.get(&Some("key")) {
- Some(Some(k)) => *k,
- _ => {
- warn!("Invalid X-Matrix header key field: {:?}", x_matrix);
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let sig = match x_matrix.get(&Some("sig")) {
- Some(Some(s)) => *s,
- _ => {
- warn!("Invalid X-Matrix header sig field: {:?}", x_matrix);
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let mut request_map = BTreeMap::<String, CanonicalJsonValue>::new();
-
- if let Some(json_body) = &json_body {
- request_map.insert("content".to_owned(), json_body.clone());
- };
-
- request_map.insert(
- "method".to_owned(),
- CanonicalJsonValue::String(request.method().to_string()),
- );
- request_map.insert(
- "uri".to_owned(),
- CanonicalJsonValue::String(request.uri().to_string()),
- );
- request_map.insert(
- "origin".to_owned(),
- CanonicalJsonValue::String(origin.as_str().to_owned()),
- );
- request_map.insert(
- "destination".to_owned(),
- CanonicalJsonValue::String(db.globals.server_name().as_str().to_owned()),
- );
-
- let mut origin_signatures = BTreeMap::new();
- origin_signatures
- .insert(key.to_owned(), CanonicalJsonValue::String(sig.to_owned()));
-
- let mut signatures = BTreeMap::new();
- signatures.insert(
- origin.as_str().to_owned(),
- CanonicalJsonValue::Object(origin_signatures),
- );
-
- request_map.insert(
- "signatures".to_owned(),
- CanonicalJsonValue::Object(signatures),
- );
-
- let keys =
- match server_server::fetch_signing_keys(&db, &origin, vec![key.to_owned()])
- .await
- {
- Ok(b) => b,
- Err(e) => {
- warn!("Failed to fetch signing keys: {}", e);
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- };
-
- let mut pub_key_map = BTreeMap::new();
- pub_key_map.insert(origin.as_str().to_owned(), keys);
-
- match ruma::signatures::verify_json(&pub_key_map, &request_map) {
- Ok(()) => (None, None, Some(origin), false),
- Err(e) => {
- warn!(
- "Failed to verify json request from {}: {}\n{:?}",
- origin, e, request_map
- );
-
- if request.uri().to_string().contains('@') {
- warn!("Request uri contained '@' character. Make sure your reverse proxy gives Conduit the raw uri (apache: use nocanon)");
- }
-
- // Forbidden
- return Failure((Status::new(580), ()));
- }
- }
- }
- AuthScheme::None => (None, None, None, false),
- }
- };
-
- let mut http_request = http::Request::builder()
- .uri(request.uri().to_string())
- .method(&*request.method().to_string());
- for header in request.headers().iter() {
- http_request = http_request.header(header.name.as_str(), &*header.value);
- }
-
- if let Some(json_body) = json_body.as_mut().and_then(|val| val.as_object_mut()) {
- let user_id = sender_user.clone().unwrap_or_else(|| {
- UserId::parse_with_server_name("", db.globals.server_name())
- .expect("we know this is valid")
- });
-
- if let Some(CanonicalJsonValue::Object(initial_request)) = json_body
- .get("auth")
- .and_then(|auth| auth.as_object())
- .and_then(|auth| auth.get("session"))
- .and_then(|session| session.as_str())
- .and_then(|session| {
- db.uiaa.get_uiaa_request(
- &user_id,
- &sender_device.clone().unwrap_or_else(|| "".into()),
- session,
- )
- })
- {
- for (key, value) in initial_request {
- json_body.entry(key).or_insert(value);
- }
- }
- body = serde_json::to_vec(json_body).expect("value to bytes can't fail");
- }
-
- let http_request = http_request.body(&*body).unwrap();
- debug!("{:?}", http_request);
- match <T::Incoming as IncomingRequest>::try_from_http_request(http_request) {
- Ok(t) => Success(Ruma {
- body: t,
- sender_user,
- sender_device,
- sender_servername,
- from_appservice,
- json_body,
- }),
- Err(e) => {
- warn!("{:?}", e);
- // Bad Json
- Failure((Status::new(583), ()))
- }
- }
- }
-}
-
impl<T: Outgoing> Deref for Ruma<T> {
type Target = T::Incoming;
@@ -338,41 +29,9 @@ impl<T: Outgoing> Deref for Ruma<T> {
}
}
-/// This struct converts ruma responses into rocket http responses.
+/// This struct converts ruma structs to http responses.
pub type ConduitResult<T> = Result<RumaResponse<T>, Error>;
-pub fn response<T: OutgoingResponse>(response: RumaResponse<T>) -> response::Result<'static> {
- let http_response = response
- .0
- .try_into_http_response::<Vec<u8>>()
- .map_err(|_| Status::InternalServerError)?;
-
- let mut response = rocket::response::Response::build();
-
- let status = http_response.status();
- response.status(Status::new(status.as_u16()));
-
- for header in http_response.headers() {
- response.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
- }
-
- let http_body = http_response.into_body();
-
- response.sized_body(http_body.len(), Cursor::new(http_body));
-
- response.raw_header("Access-Control-Allow-Origin", "*");
- response.raw_header(
- "Access-Control-Allow-Methods",
- "GET, POST, PUT, DELETE, OPTIONS",
- );
- response.raw_header(
- "Access-Control-Allow-Headers",
- "Origin, X-Requested-With, Content-Type, Accept, Authorization",
- );
- response.raw_header("Access-Control-Max-Age", "86400");
- response.ok()
-}
-
#[derive(Clone)]
pub struct RumaResponse<T>(pub T);
@@ -387,14 +46,3 @@ impl From<Error> for RumaResponse<UiaaResponse> {
t.to_response()
}
}
-
-#[cfg(feature = "conduit_bin")]
-impl<'r, 'o, T> Responder<'r, 'o> for RumaResponse<T>
-where
- 'o: 'r,
- T: OutgoingResponse,
-{
- fn respond_to(self, _: &'r Request<'_>) -> response::Result<'o> {
- response(self)
- }
-}
diff --git a/src/ruma_wrapper/axum.rs b/src/ruma_wrapper/axum.rs
new file mode 100644
index 0000000..d2cf3f1
--- /dev/null
+++ b/src/ruma_wrapper/axum.rs
@@ -0,0 +1,338 @@
+use std::{collections::BTreeMap, iter::FromIterator, str};
+
+use axum::{
+ async_trait,
+ body::{Full, HttpBody},
+ extract::{FromRequest, RequestParts, TypedHeader},
+ headers::{
+ authorization::{Bearer, Credentials},
+ Authorization,
+ },
+ response::{IntoResponse, Response},
+ BoxError,
+};
+use bytes::{BufMut, Bytes, BytesMut};
+use http::StatusCode;
+use ruma::{
+ api::{client::error::ErrorKind, AuthScheme, IncomingRequest, OutgoingResponse},
+ signatures::CanonicalJsonValue,
+ DeviceId, Outgoing, ServerName, UserId,
+};
+use tracing::{debug, warn};
+
+use super::{Ruma, RumaResponse};
+use crate::{database::DatabaseGuard, server_server, Error, Result};
+
+#[async_trait]
+impl<T, B> FromRequest<B> for Ruma<T>
+where
+ T: Outgoing,
+ T::Incoming: IncomingRequest,
+ B: HttpBody + Send,
+ B::Data: Send,
+ B::Error: Into<BoxError>,
+{
+ type Rejection = Error;
+
+ async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
+ let metadata = T::Incoming::METADATA;
+ let db = DatabaseGuard::from_request(req).await?;
+ let auth_header = Option::<TypedHeader<Authorization<Bearer>>>::from_request(req).await?;
+
+ // FIXME: Do this more efficiently
+ let query: BTreeMap<String, String> =
+ ruma::serde::urlencoded::from_str(req.uri().query().unwrap_or_default())
+ .expect("Query to string map deserialization should be fine");
+
+ let token = match &auth_header {
+ Some(TypedHeader(Authorization(bearer))) => Some(bearer.token()),
+ None => query.get("access_token").map(|tok| tok.as_str()),
+ };
+
+ let mut body = Bytes::from_request(req)
+ .await
+ .map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?;
+
+ let mut json_body = serde_json::from_slice::<CanonicalJsonValue>(&body).ok();
+
+ let appservices = db.appservice.all().unwrap();
+ let appservice_registration = appservices.iter().find(|(_id, registration)| {
+ registration
+ .get("as_token")
+ .and_then(|as_token| as_token.as_str())
+ .map_or(false, |as_token| token == Some(as_token))
+ });
+
+ let (sender_user, sender_device, sender_servername, from_appservice) =
+ if let Some((_id, registration)) = appservice_registration {
+ match metadata.authentication {
+ AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
+ let user_id = query.get("user_id").map_or_else(
+ || {
+ UserId::parse_with_server_name(
+ registration
+ .get("sender_localpart")
+ .unwrap()
+ .as_str()
+ .unwrap(),
+ db.globals.server_name(),
+ )
+ .unwrap()
+ },
+ |s| UserId::parse(s.as_str()).unwrap(),
+ );
+
+ if !db.users.exists(&user_id).unwrap() {
+ return Err(forbidden());
+ }
+
+ // TODO: Check if appservice is allowed to be that user
+ (Some(user_id), None, None, true)
+ }
+ AuthScheme::ServerSignatures => (None, None, None, true),
+ AuthScheme::None => (None, None, None, true),
+ }
+ } else {
+ match metadata.authentication {
+ AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
+ let token = match token {
+ Some(token) => token,
+ _ => return Err(missing_token()),
+ };
+
+ match db.users.find_from_token(token).unwrap() {
+ None => return Err(unknown_token()),
+ Some((user_id, device_id)) => (
+ Some(user_id),
+ Some(Box::<DeviceId>::from(device_id)),
+ None,
+ false,
+ ),
+ }
+ }
+ AuthScheme::ServerSignatures => {
+ let TypedHeader(Authorization(x_matrix)) =
+ TypedHeader::<Authorization<XMatrix>>::from_request(req)
+ .await
+ .map_err(|e| {
+ warn!("Missing or invalid Authorization header: {}", e);
+ forbidden()
+ })?;
+
+ let origin_signatures = BTreeMap::from_iter([(
+ x_matrix.key.clone(),
+ CanonicalJsonValue::String(x_matrix.sig),
+ )]);
+
+ let signatures = BTreeMap::from_iter([(
+ x_matrix.origin.as_str().to_owned(),
+ CanonicalJsonValue::Object(origin_signatures),
+ )]);
+
+ let mut request_map = BTreeMap::from_iter([
+ (
+ "method".to_owned(),
+ CanonicalJsonValue::String(req.method().to_string()),
+ ),
+ (
+ "uri".to_owned(),
+ CanonicalJsonValue::String(req.uri().to_string()),
+ ),
+ (
+ "origin".to_owned(),
+ CanonicalJsonValue::String(x_matrix.origin.as_str().to_owned()),
+ ),
+ (
+ "destination".to_owned(),
+ CanonicalJsonValue::String(
+ db.globals.server_name().as_str().to_owned(),
+ ),
+ ),
+ (
+ "signatures".to_owned(),
+ CanonicalJsonValue::Object(signatures),
+ ),
+ ]);
+
+ if let Some(json_body) = &json_body {
+ request_map.insert("content".to_owned(), json_body.clone());
+ };
+
+ let keys_result = server_server::fetch_signing_keys(
+ &db,
+ &x_matrix.origin,
+ vec![x_matrix.key.to_owned()],
+ )
+ .await;
+
+ let keys = match keys_result {
+ Ok(b) => b,
+ Err(e) => {
+ warn!("Failed to fetch signing keys: {}", e);
+ return Err(forbidden());
+ }
+ };
+
+ let pub_key_map =
+ BTreeMap::from_iter([(x_matrix.origin.as_str().to_owned(), keys)]);
+
+ match ruma::signatures::verify_json(&pub_key_map, &request_map) {
+ Ok(()) => (None, None, Some(x_matrix.origin), false),
+ Err(e) => {
+ warn!(
+ "Failed to verify json request from {}: {}\n{:?}",
+ x_matrix.origin, e, request_map
+ );
+
+ if req.uri().to_string().contains('@') {
+ warn!(
+ "Request uri contained '@' character. Make sure your \
+ reverse proxy gives Conduit the raw uri (apache: use \
+ nocanon)"
+ );
+ }
+
+ return Err(forbidden());
+ }
+ }
+ }
+ AuthScheme::None => (None, None, None, false),
+ }
+ };
+
+ let mut http_request = http::Request::builder().uri(req.uri()).method(req.method());
+ *http_request.headers_mut().unwrap() =
+ req.headers().expect("Headers already extracted").clone();
+
+ if let Some(CanonicalJsonValue::Object(json_body)) = &mut json_body {
+ let user_id = sender_user.clone().unwrap_or_else(|| {
+ UserId::parse_with_server_name("", db.globals.server_name())
+ .expect("we know this is valid")
+ });
+
+ let uiaa_request = json_body
+ .get("auth")
+ .and_then(|auth| auth.as_object())
+ .and_then(|auth| auth.get("session"))
+ .and_then(|session| session.as_str())
+ .and_then(|session| {
+ db.uiaa.get_uiaa_request(
+ &user_id,
+ &sender_device.clone().unwrap_or_else(|| "".into()),
+ session,
+ )
+ });
+
+ if let Some(CanonicalJsonValue::Object(initial_request)) = uiaa_request {
+ for (key, value) in initial_request {
+ json_body.entry(key).or_insert(value);
+ }
+ }
+
+ let mut buf = BytesMut::new().writer();
+ serde_json::to_writer(&mut buf, json_body).expect("value serialization can't fail");
+ body = buf.into_inner().freeze();
+ }
+
+ let http_request = http_request.body(&*body).unwrap();
+
+ debug!("{:?}", http_request);
+
+ let body =
+ <T::Incoming as IncomingRequest>::try_from_http_request(http_request).map_err(|e| {
+ warn!("{:?}", e);
+ bad_json()
+ })?;
+
+ Ok(Ruma {
+ body,
+ sender_user,
+ sender_device,
+ sender_servername,
+ from_appservice,
+ json_body,
+ })
+ }
+}
+
+fn forbidden() -> Error {
+ Error::BadRequest(ErrorKind::Forbidden, "Forbidden.")
+}
+
+fn unknown_token() -> Error {
+ Error::BadRequest(
+ ErrorKind::UnknownToken { soft_logout: false },
+ "Unknown token.",
+ )
+}
+
+fn missing_token() -> Error {
+ Error::BadRequest(ErrorKind::MissingToken, "Missing token.")
+}
+
+fn bad_json() -> Error {
+ Error::BadRequest(ErrorKind::BadJson, "Bad json.")
+}
+
+struct XMatrix {
+ origin: Box<ServerName>,
+ key: String, // KeyName?
+ sig: String,
+}
+
+impl Credentials for XMatrix {
+ const SCHEME: &'static str = "X-Matrix";
+
+ fn decode(value: &http::HeaderValue) -> Option<Self> {
+ debug_assert!(
+ value.as_bytes().starts_with(b"X-Matrix "),
+ "HeaderValue to decode should start with \"X-Matrix ..\", received = {:?}",
+ value,
+ );
+
+ let parameters = str::from_utf8(&value.as_bytes()["X-Matrix ".len()..])
+ .ok()?
+ .trim_start();
+
+ let mut origin = None;
+ let mut key = None;
+ let mut sig = None;
+
+ for entry in parameters.split_terminator(',') {
+ let (name, value) = entry.split_once('=')?;
+
+ // FIXME: Catch multiple fields of the same name
+ match name {
+ "origin" => origin = Some(value.try_into().ok()?),
+ "key" => key = Some(value.to_owned()),
+ "sig" => sig = Some(value.to_owned()),
+ _ => warn!(
+ "Unexpected field `{}` in X-Matrix Authorization header",
+ name
+ ),
+ }
+ }
+
+ Some(Self {
+ origin: origin?,
+ key: key?,
+ sig: sig?,
+ })
+ }
+
+ fn encode(&self) -> http::HeaderValue {
+ todo!()
+ }
+}
+
+impl<T> IntoResponse for RumaResponse<T>
+where
+ T: OutgoingResponse,
+{
+ fn into_response(self) -> Response {
+ match self.0.try_into_http_response::<BytesMut>() {
+ Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(),
+ Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
+ }
+ }
+}
diff --git a/src/server_server.rs b/src/server_server.rs
index a39b3a5..5e6fab0 100644
--- a/src/server_server.rs
+++ b/src/server_server.rs
@@ -4,13 +4,11 @@ use crate::{
pdu::EventHash,
utils, ConduitResult, Database, Error, PduEvent, Result, Ruma,
};
+use axum::{response::IntoResponse, Json};
+use futures_util::{stream::FuturesUnordered, StreamExt};
use get_profile_information::v1::ProfileField;
use http::header::{HeaderValue, AUTHORIZATION};
use regex::Regex;
-use rocket::{
- futures::{prelude::*, stream::FuturesUnordered},
- response::content::Json,
-};
use ruma::{
api::{
client::error::{Error as RumaError, ErrorKind},
@@ -72,9 +70,6 @@ use std::{
use tokio::sync::{MutexGuard, Semaphore};
use tracing::{debug, error, info, trace, warn};
-#[cfg(feature = "conduit_bin")]
-use rocket::{get, post, put};
-
/// Wraps either an literal IP address plus port, or a hostname plus complement
/// (colon-plus-port if it was specified).
///
@@ -495,10 +490,10 @@ async fn request_well_known(
/// # `GET /_matrix/federation/v1/version`
///
/// Get version information on this server.
-#[cfg_attr(feature = "conduit_bin", get("/_matrix/federation/v1/version"))]
-#[tracing::instrument(skip(db))]
-pub fn get_server_version_route(
+#[tracing::instrument(skip(db, _body))]
+pub async fn get_server_version_route(
db: DatabaseGuard,
+ _body: Ruma<get_server_version::v1::Request>,
) -> ConduitResult<get_server_version::v1::Response> {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
@@ -520,12 +515,11 @@ pub fn get_server_version_route(
/// - Matrix does not support invalidating public keys, so the key returned by this will be valid
/// forever.
// 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 async fn get_server_keys_route(db: DatabaseGuard) -> impl IntoResponse {
if !db.globals.allow_federation() {
// TODO: Use proper types
- return Json("Federation is disabled.".to_owned());
+ return Json("Federation is disabled.").into_response();
}
let mut verify_keys: BTreeMap<Box<ServerSigningKeyId>, VerifyKey> = BTreeMap::new();
@@ -563,7 +557,7 @@ pub fn get_server_keys_route(db: DatabaseGuard) -> Json<String> {
)
.unwrap();
- Json(serde_json::to_string(&response).expect("JSON is canonical"))
+ Json(response).into_response()
}
/// # `GET /_matrix/key/v2/server/{keyId}`
@@ -572,19 +566,14 @@ pub fn get_server_keys_route(db: DatabaseGuard) -> Json<String> {
///
/// - Matrix does not support invalidating public keys, so the key returned by this will be valid
/// forever.
-#[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> {
- get_server_keys_route(db)
+pub async fn get_server_keys_deprecated_route(db: DatabaseGuard) -> impl IntoResponse {
+ get_server_keys_route(db).await
}
/// # `POST /_matrix/federation/v1/publicRooms`
///
/// Lists the public rooms on this server.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/federation/v1/publicRooms", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_public_rooms_filtered_route(
db: DatabaseGuard,
@@ -628,10 +617,6 @@ pub async fn get_public_rooms_filtered_route(
/// # `GET /_matrix/federation/v1/publicRooms`
///
/// Lists the public rooms on this server.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/publicRooms", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_public_rooms_route(
db: DatabaseGuard,
@@ -675,10 +660,6 @@ pub async fn get_public_rooms_route(
/// # `PUT /_matrix/federation/v1/send/{txnId}`
///
/// Push EDUs and PDUs to this server.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/federation/v1/send/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn send_transaction_message_route(
db: DatabaseGuard,
@@ -2309,12 +2290,8 @@ fn get_auth_chain_inner(
/// Retrieves a single event from the server.
///
/// - Only works if a user of this server is currently invited or joined the room
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/event/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_event_route(
+pub async fn get_event_route(
db: DatabaseGuard,
body: Ruma<get_event::v1::Request<'_>>,
) -> ConduitResult<get_event::v1::Response> {
@@ -2358,12 +2335,8 @@ pub fn get_event_route(
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
///
/// Retrieves events that the sender is missing.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/federation/v1/get_missing_events/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_missing_events_route(
+pub async fn get_missing_events_route(
db: DatabaseGuard,
body: Ruma<get_missing_events::v1::Request<'_>>,
) -> ConduitResult<get_missing_events::v1::Response> {
@@ -2436,12 +2409,8 @@ pub fn get_missing_events_route(
/// Retrieves the auth chain for a given event.
///
/// - This does not include the event itself
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/event_auth/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_event_authorization_route(
+pub async fn get_event_authorization_route(
db: DatabaseGuard,
body: Ruma<get_event_authorization::v1::Request<'_>>,
) -> ConduitResult<get_event_authorization::v1::Response> {
@@ -2490,12 +2459,8 @@ pub fn get_event_authorization_route(
/// # `GET /_matrix/federation/v1/state/{roomId}`
///
/// Retrieves the current state of the room.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/state/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_room_state_route(
+pub async fn get_room_state_route(
db: DatabaseGuard,
body: Ruma<get_room_state::v1::Request<'_>>,
) -> ConduitResult<get_room_state::v1::Response> {
@@ -2555,12 +2520,8 @@ pub fn get_room_state_route(
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
///
/// Retrieves the current state of the room.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/state_ids/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_room_state_ids_route(
+pub async fn get_room_state_ids_route(
db: DatabaseGuard,
body: Ruma<get_room_state_ids::v1::Request<'_>>,
) -> ConduitResult<get_room_state_ids::v1::Response> {
@@ -2609,12 +2570,8 @@ pub fn get_room_state_ids_route(
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
///
/// Creates a join template.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/make_join/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn create_join_event_template_route(
+pub async fn create_join_event_template_route(
db: DatabaseGuard,
body: Ruma<create_join_event_template::v1::Request<'_>>,
) -> ConduitResult<create_join_event_template::v1::Response> {
@@ -2895,10 +2852,6 @@ async fn create_join_event(
/// # `PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}`
///
/// Submits a signed join event.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/federation/v1/send_join/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_join_event_v1_route(
db: DatabaseGuard,
@@ -2917,10 +2870,6 @@ pub async fn create_join_event_v1_route(
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
///
/// Submits a signed join event.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/federation/v2/send_join/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_join_event_v2_route(
db: DatabaseGuard,
@@ -2939,10 +2888,6 @@ pub async fn create_join_event_v2_route(
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
///
/// Invites a remote user to a room.
-#[cfg_attr(
- feature = "conduit_bin",
- put("/_matrix/federation/v2/invite/<_>/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn create_invite_route(
db: DatabaseGuard,
@@ -3055,12 +3000,8 @@ pub async fn create_invite_route(
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
///
/// Gets information on all devices of the user.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/user/devices/<_>", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_devices_route(
+pub async fn get_devices_route(
db: DatabaseGuard,
body: Ruma<get_devices::v1::Request<'_>>,
) -> ConduitResult<get_devices::v1::Response> {
@@ -3098,12 +3039,8 @@ pub fn get_devices_route(
/// # `GET /_matrix/federation/v1/query/directory`
///
/// Resolve a room alias to a room id.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/query/directory", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_room_information_route(
+pub async fn get_room_information_route(
db: DatabaseGuard,
body: Ruma<get_room_information::v1::Request<'_>>,
) -> ConduitResult<get_room_information::v1::Response> {
@@ -3129,12 +3066,8 @@ pub fn get_room_information_route(
/// # `GET /_matrix/federation/v1/query/profile`
///
/// Gets information on a profile.
-#[cfg_attr(
- feature = "conduit_bin",
- get("/_matrix/federation/v1/query/profile", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
-pub fn get_profile_information_route(
+pub async fn get_profile_information_route(
db: DatabaseGuard,
body: Ruma<get_profile_information::v1::Request<'_>>,
) -> ConduitResult<get_profile_information::v1::Response> {
@@ -3172,10 +3105,6 @@ pub fn get_profile_information_route(
/// # `POST /_matrix/federation/v1/user/keys/query`
///
/// Gets devices and identity keys for the given users.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/federation/v1/user/keys/query", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn get_keys_route(
db: DatabaseGuard,
@@ -3206,10 +3135,6 @@ pub async fn get_keys_route(
/// # `POST /_matrix/federation/v1/user/keys/claim`
///
/// Claims one-time keys.
-#[cfg_attr(
- feature = "conduit_bin",
- post("/_matrix/federation/v1/user/keys/claim", data = "<body>")
-)]
#[tracing::instrument(skip(db, body))]
pub async fn claim_keys_route(
db: DatabaseGuard,
diff --git a/src/utils.rs b/src/utils.rs
index e2d71f4..7142b3f 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -3,7 +3,7 @@ use cmp::Ordering;
use rand::prelude::*;
use ruma::serde::{try_from_json_map, CanonicalJsonError, CanonicalJsonObject};
use std::{
- cmp,
+ cmp, fmt,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
@@ -140,3 +140,40 @@ pub fn deserialize_from_str<
}
deserializer.deserialize_str(Visitor(std::marker::PhantomData))
}
+
+// Copied from librustdoc:
+// https://github.com/rust-lang/rust/blob/cbaeec14f90b59a91a6b0f17fc046c66fa811892/src/librustdoc/html/escape.rs
+
+/// Wrapper struct which will emit the HTML-escaped version of the contained
+/// string when passed to a format string.
+pub struct HtmlEscape<'a>(pub &'a str);
+
+impl<'a> fmt::Display for HtmlEscape<'a> {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ // Because the internet is always right, turns out there's not that many
+ // characters to escape: http://stackoverflow.com/questions/7381974
+ let HtmlEscape(s) = *self;
+ let pile_o_bits = s;
+ let mut last = 0;
+ for (i, ch) in s.char_indices() {
+ let s = match ch {
+ '>' => "&gt;",
+ '<' => "&lt;",
+ '&' => "&amp;",
+ '\'' => "&#39;",
+ '"' => "&quot;",
+ _ => continue,
+ };
+ fmt.write_str(&pile_o_bits[last..i])?;
+ fmt.write_str(s)?;
+ // NOTE: we only expect single byte characters here - which is fine as long as we
+ // only match single byte characters
+ last = i + 1;
+ }
+
+ if last < s.len() {
+ fmt.write_str(&pile_o_bits[last..])?;
+ }
+ Ok(())
+ }
+}
diff --git a/tests/Complement.Dockerfile b/tests/Complement.Dockerfile
index f6c62fe..22016e9 100644
--- a/tests/Complement.Dockerfile
+++ b/tests/Complement.Dockerfile
@@ -27,19 +27,18 @@ RUN chmod +x /workdir/caddy
COPY conduit-example.toml conduit.toml
ENV SERVER_NAME=localhost
-ENV ROCKET_LOG=normal
ENV CONDUIT_CONFIG=/workdir/conduit.toml
RUN sed -i "s/port = 6167/port = 8008/g" conduit.toml
RUN echo "allow_federation = true" >> conduit.toml
RUN echo "allow_encryption = true" >> conduit.toml
RUN echo "allow_registration = true" >> conduit.toml
-RUN echo "log = \"info,rocket=info,_=off,sled=off\"" >> conduit.toml
+RUN echo "log = \"info,_=off,sled=off\"" >> conduit.toml
RUN sed -i "s/address = \"127.0.0.1\"/address = \"0.0.0.0\"/g" conduit.toml
# Enabled Caddy auto cert generation for complement provided CA.
-RUN echo '{"logging":{"logs":{"default":{"level":"WARN"}}}, "apps":{"http":{"https_port":8448,"servers":{"srv0":{"listen":[":8448"],"routes":[{"match":[{"host":["your.server.name"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"127.0.0.1:8008"}]}]}]}],"terminal":true}],"tls_connection_policies": [{"match": {"sni": ["your.server.name"]}}]}}},"pki": {"certificate_authorities": {"local": {"name": "Complement CA","root": {"certificate": "/ca/ca.crt","private_key": "/ca/ca.key"},"intermediate": {"certificate": "/ca/ca.crt","private_key": "/ca/ca.key"}}}},"tls":{"automation":{"policies":[{"subjects":["your.server.name"],"issuer":{"module":"internal"},"on_demand":true},{"issuer":{"module":"internal", "ca": "local"}}]}}}}' > caddy.json
-
+RUN echo '{"logging":{"logs":{"default":{"level":"WARN"}}}, "apps":{"http":{"https_port":8448,"servers":{"srv0":{"listen":[":8448"],"routes":[{"match":[{"host":["your.server.name"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"127.0.0.1:8008"}]}]}]}],"terminal":true}],"tls_connection_policies": [{"match": {"sni": ["your.server.name"]}}]}}},"pki": {"certificate_authorities": {"local": {"name": "Complement CA","root": {"certificate": "/ca/ca.crt","private_key": "/ca/ca.key"},"intermediate": {"certificate": "/ca/ca.crt","private_key": "/ca/ca.key"}}}},"tls":{"automation":{"policies":[{"subjects":["your.server.name"],"issuer":{"module":"internal"},"on_demand":true},{"issuer":{"module":"internal", "ca": "local"}}]}}}}' > caddy.json
+
EXPOSE 8008 8448
CMD ([ -z "${COMPLEMENT_CA}" ] && echo "Error: Need Complement PKI support" && true) || \