diff --git a/Cargo.lock b/Cargo.lock index 59541f0..8e3c016 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1283,7 +1283,7 @@ dependencies = [ ] [[package]] -name = "syndicate-rs" +name = "syndicate" version = "0.2.0" dependencies = [ "bytes", @@ -1294,10 +1294,21 @@ dependencies = [ "openssl", "preserves", "preserves-schema", - "serde", - "serde_bytes", "sha2", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", + "tracing-subscriber", +] + +[[package]] +name = "syndicate-server" +version = "0.2.0" +dependencies = [ + "futures", "structopt", + "syndicate", "tokio", "tokio-tungstenite", "tokio-util", diff --git a/Cargo.toml b/Cargo.toml index 6d5f224..800f8ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "syndicate", + "syndicate-server", ] [patch.crates-io] diff --git a/README.md b/README.md index 0bc629d..67176b0 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ A Rust implementation of: - the Syndicate network protocol, including - a high-speed Dataspace indexing structure - ([`src/skeleton.rs`](src/skeleton.rs); see also + ([`skeleton.rs`](syndicate/src/skeleton.rs); see also [HOWITWORKS.md](https://git.syndicate-lang.org/syndicate-lang/syndicate-rkt/src/commit/90c4c60699069b496491b81ee63b5a45ffd638cb/syndicate/HOWITWORKS.md) from `syndicate-rkt`) and - a standalone Syndicate protocol "broker" service (roughly comparable in scope and intent to D-Bus); and - - a handful of [example programs](examples/). + - a handful of [example programs](syndicate-server/examples/). ![The Syndicate/rs server running.](syndicate-rs-server.png) *The Syndicate/rs server running.* diff --git a/syndicate/rust-toolchain b/rust-toolchain similarity index 100% rename from syndicate/rust-toolchain rename to rust-toolchain diff --git a/syndicate-server/Cargo.toml b/syndicate-server/Cargo.toml new file mode 100644 index 0000000..a1f0cb5 --- /dev/null +++ b/syndicate-server/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "syndicate-server" +version = "0.2.0" +authors = ["Tony Garnock-Jones "] +edition = "2018" + +[dependencies] +syndicate = { path = "../syndicate", version = "^0.2.0" } + +futures = "0.3.5" + +structopt = "0.3.14" + +tungstenite = "0.13.0" +tokio-tungstenite = "0.14.0" + +tokio = { version = "1.10.0", features = ["io-util", "macros", "sync", "net", "rt", "rt-multi-thread", "time"] } +tokio-util = "0.6.7" + +tracing = "0.1.14" +tracing-subscriber = "0.2.5" +tracing-futures = "0.2.4" diff --git a/syndicate-server/Makefile b/syndicate-server/Makefile new file mode 100644 index 0000000..89fa16f --- /dev/null +++ b/syndicate-server/Makefile @@ -0,0 +1,50 @@ +all: binary-debug + +# cargo install cargo-watch +watch: + cargo watch -c -x check -x 'test -- --nocapture' + +run-watch: + RUST_BACKTRACE=1 cargo watch -c -x 'build --all-targets' -x 'run' + +inotifytest: + inotifytest sh -c 'reset; cargo build && RUST_BACKTRACE=1 cargo test -- --nocapture' + +binary: binary-release + +binary-release: + cargo build --release --all-targets + +binary-debug: + cargo build --all-targets + +# OK, rather than doing it myself (per +# https://eighty-twenty.org/2019/10/15/cross-compiling-rust), it turns +# out past a certain level of complexity we need more than just a +# linker but also a C compiler, compatible headers, and so forth. This +# proved nontrivial. The Rust team maintains a docker-based +# cross-compilation environment that's very easy to use, so instead, +# I'll just use that! +# +# cargo install cross +# +# The `vendored-openssl` thing is necessary because otherwise I'd have +# to mess about with getting a musl build of openssl, plus its headers +# etc, ready on my system despite being otherwise able to rely on +# cross. I think. It's a bit confusing. + +arm-binary: arm-binary-release + +arm-binary-release: + cross build --target=armv7-unknown-linux-musleabihf --release --all-targets --features vendored-openssl + +arm-binary-debug: + cross build --target=armv7-unknown-linux-musleabihf --all-targets --features vendored-openssl + +aarch64-binary: aarch64-binary-release + +aarch64-binary-release: + cross build --target=aarch64-unknown-linux-musl --release --all-targets --features vendored-openssl + +aarch64-binary-debug: + cross build --target=aarch64-unknown-linux-musl --all-targets --features vendored-openssl diff --git a/syndicate/examples/consumer.rs b/syndicate-server/examples/consumer.rs similarity index 100% rename from syndicate/examples/consumer.rs rename to syndicate-server/examples/consumer.rs diff --git a/syndicate/examples/pingpong.rs b/syndicate-server/examples/pingpong.rs similarity index 100% rename from syndicate/examples/pingpong.rs rename to syndicate-server/examples/pingpong.rs diff --git a/syndicate/examples/producer.rs b/syndicate-server/examples/producer.rs similarity index 100% rename from syndicate/examples/producer.rs rename to syndicate-server/examples/producer.rs diff --git a/syndicate/examples/state-consumer.rs b/syndicate-server/examples/state-consumer.rs similarity index 100% rename from syndicate/examples/state-consumer.rs rename to syndicate-server/examples/state-consumer.rs diff --git a/syndicate/examples/state-producer.rs b/syndicate-server/examples/state-producer.rs similarity index 97% rename from syndicate/examples/state-producer.rs rename to syndicate-server/examples/state-producer.rs index 1ec8bc8..6531757 100644 --- a/syndicate/examples/state-producer.rs +++ b/syndicate-server/examples/state-producer.rs @@ -32,7 +32,7 @@ async fn main() -> Result<(), Box> { let presence: AnyValue = Value::simple_record1( "Present", Value::from(std::process::id()).wrap()).wrap(); - let handle = syndicate::next_handle(); + let handle = syndicate::actor::next_handle(); let assert_e = || { let ds = Arc::clone(&ds); let presence = presence.clone(); diff --git a/syndicate/src/bin/syndicate-server.rs b/syndicate-server/src/main.rs similarity index 99% rename from syndicate/src/bin/syndicate-server.rs rename to syndicate-server/src/main.rs index 3147df4..567f295 100644 --- a/syndicate/src/bin/syndicate-server.rs +++ b/syndicate-server/src/main.rs @@ -1,10 +1,6 @@ use futures::SinkExt; use futures::StreamExt; -use preserves::value::Map; -use preserves::value::NestedValue; -use preserves::value::Value; - use std::future::ready; use std::io; use std::iter::FromIterator; @@ -23,6 +19,10 @@ use syndicate::schemas::internal_protocol::_Any; use syndicate::schemas::gatekeeper; use syndicate::sturdy; +use syndicate::value::Map; +use syndicate::value::NestedValue; +use syndicate::value::Value; + use tokio::net::TcpListener; use tokio::net::TcpStream; use tokio::net::UnixListener; diff --git a/syndicate/Cargo.toml b/syndicate/Cargo.toml index b114762..dc6e20e 100644 --- a/syndicate/Cargo.toml +++ b/syndicate/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "syndicate-rs" +name = "syndicate" version = "0.2.0" authors = ["Tony Garnock-Jones "] edition = "2018" @@ -7,9 +7,6 @@ edition = "2018" [features] vendored-openssl = ["openssl/vendored"] -[lib] -name = "syndicate" - [build-dependencies] preserves-schema = "0.5.0" @@ -17,10 +14,7 @@ preserves-schema = "0.5.0" preserves = "0.17.1" preserves-schema = "0.5.0" -serde = { version = "1.0", features = ["derive", "rc"] } -serde_bytes = "0.11" - -tokio = { version = "1.7.1", features = ["macros", "sync", "net", "rt", "rt-multi-thread", "time"] } +tokio = { version = "1.10.0", features = ["io-util", "macros", "sync", "net", "rt", "rt-multi-thread", "time"] } tokio-util = "0.6.7" bytes = "1.0.1" @@ -30,11 +24,6 @@ getrandom = "0.2.3" hmac = "0.11.0" sha2 = "0.9.5" -structopt = "0.3.14" - -tungstenite = "0.13.0" -tokio-tungstenite = "0.14.0" - tracing = "0.1.14" tracing-subscriber = "0.2.5" tracing-futures = "0.2.4" diff --git a/syndicate/Makefile b/syndicate/Makefile index d3909d9..5ae1981 100644 --- a/syndicate/Makefile +++ b/syndicate/Makefile @@ -1,55 +1,15 @@ +all: binary-debug + # cargo install cargo-watch watch: cargo watch -c -x check -x 'test -- --nocapture' -run-watch: - RUST_BACKTRACE=1 cargo watch -c -x 'build --all-targets' -x 'run' - -clippy-watch: - cargo watch -c -x clippy - inotifytest: inotifytest sh -c 'reset; cargo build && RUST_BACKTRACE=1 cargo test -- --nocapture' -binary: binary-release - -binary-release: - cargo build --release --all-targets - binary-debug: cargo build --all-targets -# OK, rather than doing it myself (per -# https://eighty-twenty.org/2019/10/15/cross-compiling-rust), it turns -# out past a certain level of complexity we need more than just a -# linker but also a C compiler, compatible headers, and so forth. This -# proved nontrivial. The Rust team maintains a docker-based -# cross-compilation environment that's very easy to use, so instead, -# I'll just use that! -# -# cargo install cross -# -# The `vendored-openssl` thing is necessary because otherwise I'd have -# to mess about with getting a musl build of openssl, plus its headers -# etc, ready on my system despite being otherwise able to rely on -# cross. I think. It's a bit confusing. - -arm-binary: arm-binary-release - -arm-binary-release: - cross build --target=armv7-unknown-linux-musleabihf --release --all-targets --features vendored-openssl - -arm-binary-debug: - cross build --target=armv7-unknown-linux-musleabihf --all-targets --features vendored-openssl - -aarch64-binary: aarch64-binary-release - -aarch64-binary-release: - cross build --target=aarch64-unknown-linux-musl --release --all-targets --features vendored-openssl - -aarch64-binary-debug: - cross build --target=aarch64-unknown-linux-musl --all-targets --features vendored-openssl - pull-protocols: git subtree pull -P protocols \ -m 'Merge latest changes from the syndicate-protocols repository' \ diff --git a/syndicate/src/actor.rs b/syndicate/src/actor.rs index 45653ba..a6e7afe 100644 --- a/syndicate/src/actor.rs +++ b/syndicate/src/actor.rs @@ -163,12 +163,12 @@ where const BUMP_AMOUNT: u8 = 10; static NEXT_ACTOR_ID: AtomicU64 = AtomicU64::new(1); -fn next_actor_id() -> ActorId { +pub fn next_actor_id() -> ActorId { NEXT_ACTOR_ID.fetch_add(BUMP_AMOUNT.into(), Ordering::Relaxed) } static NEXT_HANDLE: AtomicU64 = AtomicU64::new(3); -fn next_handle() -> Handle { +pub fn next_handle() -> Handle { NEXT_HANDLE.fetch_add(BUMP_AMOUNT.into(), Ordering::Relaxed) }