From 98dd702be6f91330dd127735d42f21e7ca4daf74 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 25 Jan 2023 16:48:52 +0400 Subject: [PATCH] well known endpoint protocol --- Cargo.lock | 32 ++++++++++++++++++++++++++------ Cargo.toml | 5 +++++ crates/proto/Cargo.toml | 9 +++++++++ crates/proto/src/lib.rs | 2 ++ crates/proto/src/prelude.rs | 3 +++ crates/proto/src/well_known.rs | 13 +++++++++++++ 6 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 crates/proto/Cargo.toml create mode 100644 crates/proto/src/lib.rs create mode 100644 crates/proto/src/prelude.rs create mode 100644 crates/proto/src/well_known.rs diff --git a/Cargo.lock b/Cargo.lock index 9b44f96..4daf179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,17 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" +[[package]] +name = "async-trait" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff18d764974428cf3a9328e23fc5c986f5fbed46e6cd4cdf42544df5d297ec1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic" version = "0.5.1" @@ -196,6 +207,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "lavina_proto" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "serde", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -337,9 +357,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -457,9 +477,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.24.1" +version = "1.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae" +checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" dependencies = [ "autocfg", "bytes", @@ -488,9 +508,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 3637219..20115f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,8 @@ +[workspace] +members = [ + "crates/*" +] + [package] name = "lavina" version = "0.1.0" diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml new file mode 100644 index 0000000..528c796 --- /dev/null +++ b/crates/proto/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "lavina_proto" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.68" +async-trait = "0.1.63" +serde = { version = "1.0.152", features = ["serde_derive"] } diff --git a/crates/proto/src/lib.rs b/crates/proto/src/lib.rs new file mode 100644 index 0000000..b47b3c7 --- /dev/null +++ b/crates/proto/src/lib.rs @@ -0,0 +1,2 @@ +mod prelude; +pub mod well_known; diff --git a/crates/proto/src/prelude.rs b/crates/proto/src/prelude.rs new file mode 100644 index 0000000..af48d0d --- /dev/null +++ b/crates/proto/src/prelude.rs @@ -0,0 +1,3 @@ +pub type Result = std::result::Result; +pub use async_trait::async_trait; +pub use serde::{Deserialize, Serialize}; diff --git a/crates/proto/src/well_known.rs b/crates/proto/src/well_known.rs new file mode 100644 index 0000000..f3f1a84 --- /dev/null +++ b/crates/proto/src/well_known.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; + +#[derive(Serialize, Deserialize)] +pub struct ServerInfo { + pub name: String, + pub user_api_base_url: String, + pub fedi_api_base_url: String, +} + +#[async_trait] +pub trait WellKnown { + async fn well_known(&self) -> Result; +}