From fc67e9e6933cf06a1d769e5fc6f78f1926ce6979 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Sun, 29 Oct 2023 12:42:28 -0500 Subject: [PATCH] Begin splitting net out into net (common), client, server, and manager crates --- Cargo.lock | 42 +++++++++++++++++++++++++++++++++ Cargo.toml | 3 +++ distant-core-client/Cargo.toml | 23 ++++++++++++++++++ distant-core-client/src/lib.rs | 0 distant-core-manager/Cargo.toml | 23 ++++++++++++++++++ distant-core-manager/src/lib.rs | 0 distant-core-server/Cargo.toml | 23 ++++++++++++++++++ distant-core-server/src/lib.rs | 0 distant-core/Cargo.toml | 3 +++ distant-plugin/src/api/ctx.rs | 13 +++++++++- distant-plugin/src/client.rs | 5 ++++ distant-plugin/src/lib.rs | 1 + 12 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 distant-core-client/Cargo.toml create mode 100644 distant-core-client/src/lib.rs create mode 100644 distant-core-manager/Cargo.toml create mode 100644 distant-core-manager/src/lib.rs create mode 100644 distant-core-server/Cargo.toml create mode 100644 distant-core-server/src/lib.rs create mode 100644 distant-plugin/src/client.rs diff --git a/Cargo.lock b/Cargo.lock index 45c6fd4..948adc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -825,8 +825,11 @@ dependencies = [ "bitflags 2.4.0", "bytes", "derive_more", + "distant-core-client", + "distant-core-manager", "distant-core-net", "distant-core-protocol", + "distant-core-server", "distant-plugin", "env_logger", "futures", @@ -857,6 +860,32 @@ dependencies = [ "tokio", ] +[[package]] +name = "distant-core-client" +version = "0.21.0" +dependencies = [ + "async-trait", + "derive_more", + "env_logger", + "log", + "serde", + "test-log", + "tokio", +] + +[[package]] +name = "distant-core-manager" +version = "0.21.0" +dependencies = [ + "async-trait", + "derive_more", + "env_logger", + "log", + "serde", + "test-log", + "tokio", +] + [[package]] name = "distant-core-net" version = "0.21.0" @@ -906,6 +935,19 @@ dependencies = [ "strum", ] +[[package]] +name = "distant-core-server" +version = "0.21.0" +dependencies = [ + "async-trait", + "derive_more", + "env_logger", + "log", + "serde", + "test-log", + "tokio", +] + [[package]] name = "distant-plugin" version = "0.21.0" diff --git a/Cargo.toml b/Cargo.toml index 04e1110..f03c3b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,11 @@ license = "MIT OR Apache-2.0" members = [ "distant-core", "distant-core-auth", + "distant-core-client", + "distant-core-manager", "distant-core-net", "distant-core-protocol", + "distant-core-server", "distant-plugin", "distant-plugin-local", "distant-plugin-ssh", diff --git a/distant-core-client/Cargo.toml b/distant-core-client/Cargo.toml new file mode 100644 index 0000000..9914802 --- /dev/null +++ b/distant-core-client/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "distant-core-client" +description = "Core client library for distant, providing mechanisms to connect to a distant-compatible server" +categories = ["network-programming"] +keywords = ["client", "network", "distant"] +version = "0.21.0" +authors = ["Chip Senkbeil "] +edition = "2021" +homepage = "https://github.com/chipsenkbeil/distant" +repository = "https://github.com/chipsenkbeil/distant" +readme = "README.md" +license = "MIT OR Apache-2.0" + +[dependencies] +async-trait = "0.1.68" +derive_more = { version = "0.99.17", default-features = false, features = ["display", "from", "error"] } +log = "0.4.18" +serde = { version = "1.0.163", features = ["derive"] } + +[dev-dependencies] +env_logger = "0.10.0" +test-log = "0.2.11" +tokio = { version = "1.28.2", features = ["full"] } diff --git a/distant-core-client/src/lib.rs b/distant-core-client/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/distant-core-manager/Cargo.toml b/distant-core-manager/Cargo.toml new file mode 100644 index 0000000..e2fef18 --- /dev/null +++ b/distant-core-manager/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "distant-core-manager" +description = "Core manager library for distant, providing client & server implementation of a manager" +categories = ["network-programming"] +keywords = ["client", "server", "manager", "network", "distant"] +version = "0.21.0" +authors = ["Chip Senkbeil "] +edition = "2021" +homepage = "https://github.com/chipsenkbeil/distant" +repository = "https://github.com/chipsenkbeil/distant" +readme = "README.md" +license = "MIT OR Apache-2.0" + +[dependencies] +async-trait = "0.1.68" +derive_more = { version = "0.99.17", default-features = false, features = ["display", "from", "error"] } +log = "0.4.18" +serde = { version = "1.0.163", features = ["derive"] } + +[dev-dependencies] +env_logger = "0.10.0" +test-log = "0.2.11" +tokio = { version = "1.28.2", features = ["full"] } diff --git a/distant-core-manager/src/lib.rs b/distant-core-manager/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/distant-core-server/Cargo.toml b/distant-core-server/Cargo.toml new file mode 100644 index 0000000..0b43536 --- /dev/null +++ b/distant-core-server/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "distant-core-server" +description = "Core server library for distant, providing distant-compatible server implementation" +categories = ["network-programming"] +keywords = ["server", "network", "distant"] +version = "0.21.0" +authors = ["Chip Senkbeil "] +edition = "2021" +homepage = "https://github.com/chipsenkbeil/distant" +repository = "https://github.com/chipsenkbeil/distant" +readme = "README.md" +license = "MIT OR Apache-2.0" + +[dependencies] +async-trait = "0.1.68" +derive_more = { version = "0.99.17", default-features = false, features = ["display", "from", "error"] } +log = "0.4.18" +serde = { version = "1.0.163", features = ["derive"] } + +[dev-dependencies] +env_logger = "0.10.0" +test-log = "0.2.11" +tokio = { version = "1.28.2", features = ["full"] } diff --git a/distant-core-server/src/lib.rs b/distant-core-server/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/distant-core/Cargo.toml b/distant-core/Cargo.toml index 5bbb3cc..c2b18ee 100644 --- a/distant-core/Cargo.toml +++ b/distant-core/Cargo.toml @@ -17,6 +17,9 @@ bitflags = "2.3.1" bytes = "1.4.0" derive_more = { version = "0.99.17", default-features = false, features = ["as_mut", "as_ref", "deref", "deref_mut", "display", "from", "error", "into", "into_iterator", "is_variant", "try_into"] } distant-core-net = { version = "=0.21.0", path = "../distant-core-net" } +distant-core-client = { version = "=0.21.0", path = "../distant-core-client" } +distant-core-manager = { version = "=0.21.0", path = "../distant-core-manager" } +distant-core-server = { version = "=0.21.0", path = "../distant-core-server" } distant-plugin = { version = "=0.21.0", path = "../distant-plugin" } distant-core-protocol = { version = "=0.21.0", path = "../distant-core-protocol" } futures = "0.3.28" diff --git a/distant-plugin/src/api/ctx.rs b/distant-plugin/src/api/ctx.rs index 2618665..1a2b186 100644 --- a/distant-plugin/src/api/ctx.rs +++ b/distant-plugin/src/api/ctx.rs @@ -1,3 +1,5 @@ +use std::io; + use async_trait::async_trait; /// Type abstraction of a boxed [`Ctx`]. @@ -6,4 +8,13 @@ pub type BoxedCtx = Box; /// Represents a context associated when an API request is being executed, supporting the ability /// to send responses back asynchronously. #[async_trait] -pub trait Ctx: Send {} +pub trait Ctx: Send { + /// Id of the connection associated with this context. + fn connection(&self) -> u32; + + /// Clones context, returning a new boxed instance. + fn clone_ctx(&self) -> BoxedCtx; + + /// Sends some response back. + fn send(&self, data: Vec) -> io::Result<()>; +} diff --git a/distant-plugin/src/client.rs b/distant-plugin/src/client.rs new file mode 100644 index 0000000..400ef9f --- /dev/null +++ b/distant-plugin/src/client.rs @@ -0,0 +1,5 @@ +use async_trait::async_trait; + +/// +#[async_trait] +pub trait Client {} diff --git a/distant-plugin/src/lib.rs b/distant-plugin/src/lib.rs index 1c2d709..0771cd9 100644 --- a/distant-plugin/src/lib.rs +++ b/distant-plugin/src/lib.rs @@ -5,6 +5,7 @@ pub struct ReadmeDoctests; pub mod api; +pub mod client; pub mod common; pub mod handlers;