From 812748981af1ed86cf89d70e2f4c27d898df2e52 Mon Sep 17 00:00:00 2001 From: Raine Date: Mon, 6 Nov 2023 18:27:00 +0100 Subject: [PATCH] refactor: node --- doc/domo_node/config.md | 6 ----- doc/domo_node/devnotes.md | 3 --- doc/domo_node/node_types.md | 45 ------------------------------------ domo_node/config.bridge.toml | 3 --- domo_node/config.toml | 5 +--- domo_node/src/config/node.rs | 39 ------------------------------- domo_node/src/main.rs | 5 ++-- domo_proto/src/identifier.rs | 8 +++++-- 8 files changed, 10 insertions(+), 104 deletions(-) delete mode 100644 doc/domo_node/config.md delete mode 100644 doc/domo_node/devnotes.md delete mode 100644 doc/domo_node/node_types.md delete mode 100644 domo_node/config.bridge.toml diff --git a/doc/domo_node/config.md b/doc/domo_node/config.md deleted file mode 100644 index 6c91eb9..0000000 --- a/doc/domo_node/config.md +++ /dev/null @@ -1,6 +0,0 @@ -You can set up the node in very cool ways. - -# `node.id` (optional) -This will set the node's id. -Your app may not start if the id is already taken. -> tip: `0xFF------` is a free subnet in `domo_node`. \ No newline at end of file diff --git a/doc/domo_node/devnotes.md b/doc/domo_node/devnotes.md deleted file mode 100644 index 2afb19c..0000000 --- a/doc/domo_node/devnotes.md +++ /dev/null @@ -1,3 +0,0 @@ -# Todo - -- [ ] `0xFF------` subnet should be free to use without interference. \ No newline at end of file diff --git a/doc/domo_node/node_types.md b/doc/domo_node/node_types.md deleted file mode 100644 index dc2818f..0000000 --- a/doc/domo_node/node_types.md +++ /dev/null @@ -1,45 +0,0 @@ -The `domo_node` implementation is quite limited. -It's not made to be used standalone but rather in combination with other tools and use drivers. - -# The Master node (`master`) -Of these, there can only be one. -The job of a master node is rather complex. - -## Forwarding packets -The most straight forward job of the node. -It works by essentially having a hashmap with a reference to a socket. -When a packet comes in the packet gets forwarded to the right node and socket. - -## Handling network state -The master node ensures there are no duplicate identifiers and therefore nodes. -Also, it will make sure no invalid updates can be sent. -Most packets go through the master node before getting to the source. -Most because the subnet node can have private nodes and handle those themselves. - -# The Bridge node (`bridge`) -The bridge node is simple. -In config you define where to forward the packets to, and they get delivered to there. - -# The Subnet node (`subnet`) -This is maybe another advanced node. -It's a slave node that also acts as a master node. -You can define private nodes in config, and they will be managed by the subnet node. -For big domo networks this can be very useful to ensure privacy and keep control. - -## Subnet properties -The `domo_node` implementation ensures a couple properties. - -### Lights (`all_lights` = `Switch`) -With this property you can turn off all the lights in the subnet. -This property will be absent is there are no lights present in the subnet. - -> TODO: this feature requires distinction between switches and lights. -> Either with extra identification information in `0x01` - -### Enabled (`enabled` = `Switch`) -Enable or disable the subnet. -Functionality like: Master emulation, forwarding, private nodes will be paused. - -### Forward (`forward` = `Swtich`) -This will disable the forwarding of the subnet's node. -Essentially make the subnet all private. diff --git a/domo_node/config.bridge.toml b/domo_node/config.bridge.toml deleted file mode 100644 index 2166844..0000000 --- a/domo_node/config.bridge.toml +++ /dev/null @@ -1,3 +0,0 @@ -[node.type.bridge] -bind = "127.0.0.1:4481" -master_address = "127.0.0.1:4480" diff --git a/domo_node/config.toml b/domo_node/config.toml index f45b974..0c666db 100644 --- a/domo_node/config.toml +++ b/domo_node/config.toml @@ -1,5 +1,2 @@ -[node.type.master] -bind = "0.0.0.0:4480" - [node] -node_id = "ffffffff" +node_id = "ff" \ No newline at end of file diff --git a/domo_node/src/config/node.rs b/domo_node/src/config/node.rs index c9ea25f..d399305 100644 --- a/domo_node/src/config/node.rs +++ b/domo_node/src/config/node.rs @@ -1,47 +1,9 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Display, Formatter}; -use std::net::SocketAddr; use domo_proto::identifier::Identifier; -#[derive(Debug, Serialize, Deserialize, Clone)] -pub enum NodeType { - #[serde(rename = "master")] - Master { - bind: SocketAddr, - }, - #[serde(rename = "relay")] - Bridge { - bind: SocketAddr, - master_address: SocketAddr - }, - #[serde(rename = "subnet")] - Subnet { - master_address: String - }, -} - -impl Display for NodeType { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - NodeType::Master { .. } => write!(f, "master"), - NodeType::Bridge { .. } => write!(f, "relay"), - NodeType::Subnet { .. } => write!(f, "subnet"), - } - } -} - -impl Default for NodeType { - fn default() -> Self { - Self::Master { - bind: SocketAddr::from(([0,0,0,0], 4480)), - } - } -} - #[derive(Debug, Serialize, Deserialize, Clone)] pub struct NodeConfig { - #[serde(rename = "type")] - pub node_type: NodeType, #[serde(default)] pub node_id: String } @@ -49,7 +11,6 @@ pub struct NodeConfig { impl Default for NodeConfig { fn default() -> Self { Self { - node_type: NodeType::default(), node_id: Identifier::random().to_string() } } diff --git a/domo_node/src/main.rs b/domo_node/src/main.rs index 2aa6ce4..acc77d4 100644 --- a/domo_node/src/main.rs +++ b/domo_node/src/main.rs @@ -27,8 +27,7 @@ fn main() -> io::Result<()> { debug!("Built tokio runtime with all features..."); info!( - "Staring {} node as 0x{}!", - CONFIG.with_borrow(|c| c.node.node_type.clone()), + "Starting node with id: 0x{}!", CONFIG.with_borrow(|c| c.node.node_id.clone()) ); @@ -43,6 +42,8 @@ fn main() -> io::Result<()> { ) ); + + }); Ok(()) diff --git a/domo_proto/src/identifier.rs b/domo_proto/src/identifier.rs index d99b0fb..6be5ba1 100644 --- a/domo_proto/src/identifier.rs +++ b/domo_proto/src/identifier.rs @@ -41,8 +41,12 @@ impl LowerHex for Identifier { impl From<&[u8]> for Identifier { fn from(value: &[u8]) -> Self { - let mut bytes = [0_u8; 4]; - bytes[..4].copy_from_slice(value[..4].as_ref()); + let mut bytes = [0; 4]; + for i in 0..4 { + if i < value.len() { + bytes[i] = value[i]; + } + } Identifier { bytes }