From 1ce00f90fea3f1f078e22387442087c5ca7329b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Thu, 4 Mar 2021 13:36:06 +0100 Subject: [PATCH 1/5] fix: don't accept incoming pdus if we know about them already --- src/server_server.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server_server.rs b/src/server_server.rs index 00f31ca..d589818 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -554,6 +554,12 @@ pub async fn send_transaction_message_route<'a>( // TODO: redact event if hashing fails let (event_id, value) = crate::pdu::process_incoming_pdu(pdu); + // Skip the pdu if we already know about it + if db.rooms.get_pdu_id(&event_id)?.is_some() { + resolved_map.insert(event_id, Err("We already know about this event".into())); + continue; + } + let pdu = serde_json::from_value::( serde_json::to_value(&value).expect("CanonicalJsonObj is a valid JsonValue"), ) From 6309506a48daa70b120b4dcf0ea76ab2487208d2 Mon Sep 17 00:00:00 2001 From: Rudi Floren Date: Thu, 4 Mar 2021 15:26:34 +0100 Subject: [PATCH 2/5] Allow suspicious_else_formatting This is probably unfixable because it is caused by macros --- src/lib.rs | 1 + src/main.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index aed129f..196626e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::suspicious_else_formatting)] pub mod appservice_server; pub mod client_server; mod database; diff --git a/src/main.rs b/src/main.rs index 498cfa6..eff5552 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![warn(rust_2018_idioms)] +#![allow(clippy::suspicious_else_formatting)] pub mod appservice_server; pub mod client_server; From 4027cbd01ddf11541c84e4029fbb1587d951e784 Mon Sep 17 00:00:00 2001 From: Rudi Floren Date: Thu, 4 Mar 2021 15:27:25 +0100 Subject: [PATCH 3/5] Fix various clippy errors --- src/database/sending.rs | 8 +++----- src/ruma_wrapper.rs | 5 +++-- src/server_server.rs | 10 +++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index 48fe68a..1ae063f 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -74,7 +74,7 @@ impl Sending { for ((server, is_appservice), pdus) in current_transactions { // Create new reservation let mut prefix = if is_appservice { - "+".as_bytes().to_vec() + b"+".to_vec() } else { Vec::new() }; @@ -217,11 +217,9 @@ impl Sending { prefix.extend_from_slice(server.as_bytes()); prefix.push(0xff); - if servercurrentpdus + servercurrentpdus .compare_and_swap(prefix, Option::<&[u8]>::None, Some(&[])) // Try to reserve - == Ok(Ok(())) { true } else { - false - } + == Ok(Ok(())) }) { servercurrentpdus.insert(&key, &[]).unwrap(); diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index 898561f..188d1b6 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -1,17 +1,17 @@ use crate::Error; use ruma::{ - api::{AuthScheme, OutgoingRequest}, identifiers::{DeviceId, UserId}, Outgoing, }; use std::{ - convert::{TryFrom, TryInto}, + convert::{TryInto}, ops::Deref, }; #[cfg(feature = "conduit_bin")] use { crate::utils, + ruma::api::{AuthScheme, OutgoingRequest}, log::{debug, warn}, rocket::{ data::{ @@ -25,6 +25,7 @@ use { Request, State, }, std::io::Cursor, + std::convert::TryFrom, }; /// This struct converts rocket requests into ruma structs by converting them into http requests diff --git a/src/server_server.rs b/src/server_server.rs index 00f31ca..a3fac18 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -3,7 +3,7 @@ use get_profile_information::v1::ProfileField; use http::header::{HeaderValue, AUTHORIZATION, HOST}; use log::{info, warn}; use regex::Regex; -use rocket::{get, post, put, response::content::Json, State}; +use rocket::{response::content::Json, State}; use ruma::{ api::{ federation::{ @@ -29,6 +29,10 @@ use std::{ net::{IpAddr, SocketAddr}, time::{Duration, SystemTime}, }; +#[cfg(feature = "conduit_bin")] +use { + rocket::{get, post, put} +}; #[tracing::instrument(skip(globals))] pub async fn send_request( @@ -591,7 +595,7 @@ pub async fn send_transaction_message_route<'a>( .get("users") .and_then(|users| users.as_sequence()) .map_or_else( - || Vec::new(), + Vec::new, |users| { users .iter() @@ -623,7 +627,7 @@ pub async fn send_transaction_message_route<'a>( .and_then(|string| { UserId::parse_with_server_name(string, db.globals.server_name()).ok() }); - + #[allow(clippy::blocks_in_if_conditions)] if bridge_user_id.map_or(false, |bridge_user_id| { db.rooms .is_joined(&bridge_user_id, room_id) From bb1064ce04fb66594f4de7b61b60d05d05ef5730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Thu, 4 Mar 2021 15:28:28 +0100 Subject: [PATCH 4/5] docs: small readme changes --- README.md | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8e4b1b7..bff15e6 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,43 @@ # Conduit ### A Matrix homeserver written in Rust -[![Liberapay](https://img.shields.io/liberapay/receives/timokoesters?logo=liberapay)](https://liberapay.com/timokoesters) -[![Matrix](https://img.shields.io/matrix/conduit:conduit.rs?server_fqdn=conduit.koesters.xyz)](https://matrix.to/#/#conduit:matrix.org) - #### What is the goal? A fast Matrix homeserver that's easy to set up and just works. You can install it on a mini-computer like the Raspberry Pi to host Matrix for your family, friends or company. + #### Can I try it out? Yes! Just open a Matrix client ( or Element Android for example) and register on the `https://conduit.koesters.xyz` homeserver. + +#### What is it build on? + +- [Ruma](https://www.ruma.io): Useful structures for endpoint requests and + responses that can be (de)serialized +- [Sled](https://github.com/spacejam/sled): A simple (key, value) database with + good performance +- [Rocket](https://rocket.rs): A flexible web framework + + +#### What are the biggest things still missing? + +- Most federation features (invites, e2ee) +- Push notifications on mobile +- Notification settings +- Lots of testing + +Check out the [Conduit 1.0 Release Milestone](https://gitlab.com/famedly/conduit/-/milestones/3). + + #### How can I deploy my own? ##### Deploy -Download or compile a conduit binary and call it from somewhere like a systemd script. [Read +Download or compile a Conduit binary, set up the config and call it from somewhere like a systemd script. [Read more](DEPLOY.md) ##### Deploy using Docker @@ -33,32 +51,15 @@ docker run -d -p 8448:8000 -v db:/srv/conduit/.local/share/conduit matrixconduit Or build and run it with docker or docker-compose. [Read more](docker/README.md) -#### What is it build on? - -- [Ruma](https://www.ruma.io): Useful structures for endpoint requests and - responses that can be (de)serialized -- [Sled](https://github.com/spacejam/sled): A simple (key, value) database with - good performance -- [Rocket](https://rocket.rs): A flexible web framework - -#### What are the biggest things still missing? - -- Appservices (Bridges and Bots) -- Most federation features (invites, e2ee) -- Push notifications on mobile -- Notification settings -- Lots of testing - -Also check out the [milestones](https://git.koesters.xyz/timo/conduit/milestones). #### How can I contribute? 1. Look for an issue you would like to work on and make sure it's not assigned to other users 2. Ask someone to assign the issue to you (comment on the issue or chat in - #conduit:matrix.org) -3. Fork the repo and work on the issue. #conduit:matrix.org is happy to help :) -4. Submit a PR + #conduit:nordgedanken.dev) +3. Fork the repo and work on the issue. #conduit:nordgedanken.dev is happy to help :) +4. Submit a MR #### Donate From 156296ac051a83cf009cd399dc097164238a6a18 Mon Sep 17 00:00:00 2001 From: Rudi Floren Date: Thu, 4 Mar 2021 17:22:23 +0000 Subject: [PATCH 5/5] Fix Complement CI paths The final container tried to COPY from the default cargo target dir, but we only checked if cached_target is present. We copy from cached_target to target when cached_target is present now in the builder --- tests/Complement.Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Complement.Dockerfile b/tests/Complement.Dockerfile index 370db7c..7deb6e8 100644 --- a/tests/Complement.Dockerfile +++ b/tests/Complement.Dockerfile @@ -9,7 +9,9 @@ ARG SCCACHE_ENDPOINT ARG SCCACHE_S3_USE_SSL COPY . . -RUN test -e cached_target/release/conduit || cargo build --release +RUN mkdir -p target/release +RUN test -e cached_target/release/conduit && cp cached_target/release/conduit target/release/conduit || cargo build --release + FROM valkum/docker-rust-ci:latest WORKDIR /workdir @@ -37,4 +39,4 @@ CMD ([ -z "${COMPLEMENT_CA}" ] && echo "Error: Need Complement PKI support" && t sed -i "s/your.server.name/${SERVER_NAME}/g" caddy.json && \ /workdir/caddy start --config caddy.json > /dev/null && \ /workdir/conduit - \ No newline at end of file +