refactor: node
All checks were successful
ci/woodpecker/push/proto Pipeline was successful
ci/woodpecker/push/node Pipeline was successful

This commit is contained in:
Strix 2023-11-06 18:27:00 +01:00
parent bd9ce9f01f
commit 812748981a
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
8 changed files with 10 additions and 104 deletions

View file

@ -1,3 +0,0 @@
[node.type.bridge]
bind = "127.0.0.1:4481"
master_address = "127.0.0.1:4480"

View file

@ -1,5 +1,2 @@
[node.type.master]
bind = "0.0.0.0:4480"
[node]
node_id = "ffffffff"
node_id = "ff"

View file

@ -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()
}
}

View file

@ -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(())