[LIB] Protocol data structures
All checks were successful
/ build (push) Successful in 1m28s
/ clippy (push) Successful in 1m26s

This commit is contained in:
xqtc 2024-09-04 13:45:33 +02:00
parent 8ee5194af7
commit f7f582bc69
6 changed files with 325 additions and 2 deletions

207
Cargo.lock generated
View file

@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.3"
@ -66,6 +81,32 @@ version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "async-trait"
version = "0.1.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "backtrace"
version = "0.3.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bincode"
version = "1.3.3"
@ -75,6 +116,30 @@ dependencies = [
"serde",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "bytes"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]]
name = "cc"
version = "1.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -127,6 +192,35 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "cpufeatures"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "env_logger"
version = "0.10.2"
@ -146,6 +240,22 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "gimli"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
[[package]]
name = "hashbrown"
version = "0.14.5"
@ -164,6 +274,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "humantime"
version = "2.1.0"
@ -222,7 +338,9 @@ dependencies = [
"pretty_env_logger",
"serde",
"serde_json",
"sha256",
"toml",
"uuid",
]
[[package]]
@ -252,6 +370,30 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miniz_oxide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.36.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a"
dependencies = [
"memchr",
]
[[package]]
name = "pin-project-lite"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]]
name = "pretty_env_logger"
version = "0.5.0"
@ -309,6 +451,12 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "ryu"
version = "1.0.18"
@ -356,6 +504,36 @@ dependencies = [
"serde",
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha256"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0"
dependencies = [
"async-trait",
"bytes",
"hex",
"sha2",
"tokio",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "static_assertions"
version = "1.1.0"
@ -388,6 +566,17 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "tokio"
version = "1.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
dependencies = [
"backtrace",
"bytes",
"pin-project-lite",
]
[[package]]
name = "toml"
version = "0.8.19"
@ -432,6 +621,12 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-ident"
version = "1.0.12"
@ -444,6 +639,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
[[package]]
name = "uwusched"
version = "0.1.0"
@ -460,6 +661,12 @@ dependencies = [
"toml",
]
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "winapi-util"
version = "0.1.9"

View file

@ -7,6 +7,8 @@ edition = "2021"
[dependencies]
pretty_env_logger = "0.5"
uuid = "1.10"
sha256 = "1.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"

View file

@ -0,0 +1,83 @@
#![allow(non_camel_case_types, unused)]
use std::str::FromStr;
#[derive(Debug, serde::Serialize)]
pub enum DataStatus {
OK,
/// An Error while looking up a hash
HASH_ERR,
/// Timeout Error
TIMEOUT_ERR,
}
#[derive(Debug, serde::Serialize)]
pub enum NodeStatusLogin {
/// Accepted Login
ACCEPTED,
/// Rejected Login
REJECTED,
}
#[derive(Debug, serde::Serialize)]
pub enum NodeStatusLogout {
/// Head-Node ACKs the Logout request from compute node
ACK,
/// Head-Node restructured and rebalanced Task-Queue, allowing the compute node to log out
OK,
/// Head-Node failed to restructure and rebalance Task-Queue, preventing compute node to log out
ERR,
}
#[derive(Debug, serde::Serialize)]
pub enum ProtocolId {
/// Identifier indicating one node pushing data to another
DATA_PUSH,
/// Identifier indicating one node pulling to another
DATA_PULL,
/// Identifier indicating the success of a `DATA_PUSH` or `DATA_PULL`
DATA_RESP,
HASH_PUSH,
HASH_PULL,
HASH_RESP,
/// Identifier indicating a node wants to join the cluster
NODE_LOGIN,
/// Identifier indicating a node being online
NODE_ALIVE,
/// Identifier indicating a node wants to leave the cluster
NODE_LOGOUT,
}
pub struct Login {
protocol_id: ProtocolId,
node_id: String,
transaction_uuid: uuid::Uuid,
status: NodeStatusLogin,
}
pub struct AliveCheck {
protocol_id: ProtocolId,
node_id: String,
transaction_uuid: uuid::Uuid,
}
pub struct Logout {
protocol_id: ProtocolId,
node_id: String,
transaction_uuid: uuid::Uuid,
status: NodeStatusLogout,
}
fn str_to_uuid(uuid: String) -> uuid::Uuid {
uuid::Uuid::from_str(&uuid).unwrap()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn uuid() {
let res = str_to_uuid("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_string());
assert_eq!(uuid::uuid!("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"), res);
}
}

View file

@ -0,0 +1,31 @@
#![allow(non_camel_case_types, unused)]
use crate::control::ProtocolId;
pub struct Pull {
protocol_id: ProtocolId,
node_id: String,
uuid: String,
hashmap_id: String,
}
#[derive(Debug)]
pub struct Push<T> {
protocol_id: ProtocolId,
node_id: String,
uuid: String,
hashmap_id: String,
length_decomp: i64,
length_comp: i64,
comp_format: String,
attributes: Option<T>,
data: String,
}
pub struct Response {
protocol_id: ProtocolId,
node_id: String,
uuid: String,
hashmap_id: String,
status: String,
}

View file

@ -1,2 +1,3 @@
pub mod data;
pub mod control;

View file

@ -90,7 +90,6 @@
"protocol_id":<protocol_id>,
"node_id":<node_id>,
"uuid":<uuid>,
"uuid":<uuid>,
"hashmap_id":<hashmap_id>,
"length_decomp": <length_decomp>,
"length_comp": <length_comp>,