-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial sketchings of how distributed node's might look, based heavil…
…y on the Erlang protocol. This is a collection of tcp managing actors and session management for automated session handling Related issue: #16
- Loading branch information
Showing
49 changed files
with
3,078 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
members = [ | ||
"ractor", | ||
"ractor-cluster", | ||
"ractor-playground", | ||
"xtask" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "ractor-cluster" | ||
version = "0.4.0" | ||
authors = ["Sean Lawlor", "Evan Au", "Dillon George"] | ||
description = "Distributed cluster environment of Ractor actors" | ||
documentation = "https://docs.rs/ractor" | ||
license = "MIT" | ||
edition = "2018" | ||
keywords = ["actor", "ractor", "cluster"] | ||
repository = "https://github.com/slawlor/ractor" | ||
readme = "../README.md" | ||
homepage = "https://github.com/slawlor/ractor" | ||
categories = ["actor", "erlang"] | ||
build = "src/build.rs" | ||
|
||
[build-dependencies] | ||
protobuf-src = "1" | ||
prost-build = { version = "0.11" } | ||
|
||
[dependencies] | ||
## Required dependencies | ||
async-trait = "0.1" | ||
bytes = { version = "1" } | ||
# dashmap = "5" | ||
# futures = "0.3" | ||
log = "0.4" | ||
# once_cell = "1" | ||
prost = { version = "0.11" } | ||
ractor = { version = "0.4", features = ["cluster"], path = "../ractor" } | ||
rand = "0.8" | ||
sha2 = "0.10" | ||
tokio = { version = "1", features = ["rt", "time", "sync", "macros", "net", "io-util"]} | ||
|
||
## Optional dependencies | ||
# tokio-rustls = { version = "0.23", optional = true } | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["rt", "time", "sync", "macros", "rt-multi-thread"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Sean Lawlor | ||
// | ||
// This source code is licensed under both the MIT license found in the | ||
// LICENSE-MIT file in the root directory of this source tree. | ||
|
||
//! This is the pre-compilation build script for the crate `ractor` when running in distrubted | ||
//! mode. It's used to compile protobuf into Rust code prior to compilation. | ||
|
||
/// The shared-path for all protobuf specifications | ||
const PROTOBUF_BASE_DIRECTORY: &str = "src/protocol"; | ||
/// The list of protobuf files to generate inside PROBUF_BASE_DIRECTORY | ||
const PROTOBUF_FILES: [&str; 4] = ["meta", "node", "auth", "control"]; | ||
|
||
fn build_protobufs() { | ||
std::env::set_var("PROTOC", protobuf_src::protoc()); | ||
|
||
let mut protobuf_files = Vec::with_capacity(PROTOBUF_FILES.len()); | ||
|
||
for file in PROTOBUF_FILES.iter() { | ||
let proto_file = format!("{}/{}.proto", PROTOBUF_BASE_DIRECTORY, file); | ||
println!("cargo:rerun-if-changed={}", proto_file); | ||
protobuf_files.push(proto_file); | ||
} | ||
|
||
prost_build::compile_protos(&protobuf_files, &[PROTOBUF_BASE_DIRECTORY]).unwrap(); | ||
} | ||
|
||
fn main() { | ||
// compile the spec files into Rust code | ||
build_protobufs(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Sean Lawlor | ||
// | ||
// This source code is licensed under both the MIT license found in the | ||
// LICENSE-MIT file in the root directory of this source tree. | ||
|
||
//! Hashing utilities mainly used around challenge computation | ||
|
||
pub(crate) const DIGEST_BYTES: usize = 32; | ||
pub(crate) type Digest = [u8; DIGEST_BYTES]; | ||
|
||
/// Compute a challenge digest | ||
pub(crate) fn challenge_digest(secret: &'_ str, challenge: u32) -> Digest { | ||
use sha2::Digest; | ||
|
||
let secret_bytes = secret.as_bytes(); | ||
let mut data = Vec::with_capacity(secret_bytes.len() + 4); | ||
data.resize(secret_bytes.len() + 4, 0u8); | ||
|
||
let challenge_bytes = challenge.to_be_bytes(); | ||
data[0..4].copy_from_slice(&challenge_bytes); | ||
data[4..].copy_from_slice(secret_bytes); | ||
|
||
let hash = sha2::Sha256::digest(&data); | ||
|
||
hash.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Sean Lawlor | ||
// | ||
// This source code is licensed under both the MIT license found in the | ||
// LICENSE-MIT file in the root directory of this source tree. | ||
|
||
//! Support for remote nodes in a distributed cluster. | ||
//! | ||
//! A node is the same as [Erlang's definition](https://www.erlang.org/doc/reference_manual/distributed.html) | ||
//! for distributed Erlang, in that it's a remote "hosting" process in the distributed pool of processes. | ||
//! | ||
//! In this realization, nodes are simply actors which handle an external connection to the other nodes in the pool. | ||
//! When nodes connect, they identify all of the nodes the remote node is also connected to and additionally connect | ||
//! to them as well. They merge registries and pg groups together in order to create larger clusters of services. | ||
//! | ||
//! We have chosen protobuf for our inter-node defined protocol, however you can chose whatever medium you like | ||
//! for binary serialization + deserialization. The "remote" actor will simply encode your message type and send it | ||
//! over the wire for you | ||
//! | ||
//! ## A note on usage | ||
//! | ||
//! An important note on usage, when utilizing `ractor-cluster` and [ractor] in the cluster configuration | ||
//! (i.e. `ractor/cluster`), you no longer receive the auto-implementation for all types for [ractor::Message]. This | ||
//! is due to specialization (see: https://github.com/rust-lang/rust/issues/31844). Ideally we'd have the trait have a | ||
//! "default" non-serializable implementation for all types that could be messages, and specific implementations for | ||
//! those that can be messages sent over the network. However this is presently a `+nightly` only functionality and | ||
//! has a soundness hole in it's processes. Therefore as a workaround, when the `cluster` feature is enabled on [ractor] | ||
//! the default implementation, specifically `impl<T: Any + Send + Sized + 'static> Message for T {}` is disabled. | ||
//! | ||
//! This means that you need to specify the implementation of the [ractor::Message] trait on all message types, and when | ||
//! they're not network supported messages, this is just a default empty implementation. When they **are** potentially | ||
//! sent over a network in a dist protocol, then you need to fill out the implementation details for how the message | ||
//! serialization is handled. See the documentation of [crate::serialized_rpc_forward] for an example. | ||
|
||
// #![deny(warnings)] | ||
#![warn(unused_imports)] | ||
#![warn(unsafe_code)] | ||
#![warn(missing_docs)] | ||
#![warn(unused_crate_dependencies)] | ||
#![cfg_attr(docsrs, feature(doc_cfg))] | ||
|
||
mod hash; | ||
mod net; | ||
pub mod node; | ||
pub(crate) mod protocol; | ||
pub(crate) mod remote_actor; | ||
|
||
pub mod macros; | ||
|
||
// Re-exports | ||
pub use node::NodeServer; | ||
|
||
/// Node's are representing by an integer id | ||
pub type NodeId = u64; |
Oops, something went wrong.