From 231d27e00ff01b903422563ee7c42a145c3266ec Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 18 Oct 2023 03:46:12 +0200 Subject: [PATCH] fix: removed broken legacy nodeinfo, fix datetime --- src/entities/node_info.rs | 2 +- src/nodeinfo/model.rs | 53 +++------------------------------------ 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/src/entities/node_info.rs b/src/entities/node_info.rs index 4e6d735..f66992c 100644 --- a/src/entities/node_info.rs +++ b/src/entities/node_info.rs @@ -9,7 +9,7 @@ pub struct Model { pub id: i32, pub domain: String, pub data: String, - pub updated: String, + pub updated: ChronoDateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/src/nodeinfo/model.rs b/src/nodeinfo/model.rs index 6911ffc..4f084c2 100644 --- a/src/nodeinfo/model.rs +++ b/src/nodeinfo/model.rs @@ -3,13 +3,14 @@ use serde_json::{Map, Value}; /// Node metadata for version detection only used for deserialization. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd, derive_more::Display)] -pub(crate) enum NodeVersion { +pub enum NodeVersion { V1_0 = 1000, V1_1 = 1001, V2_0 = 2000, V2_1 = 2001, } +#[allow(unused)] pub type NodeInfo<'a> = NodeInfoInternal<&'a str>; pub type NodeInfoOwned = NodeInfoInternal; @@ -30,23 +31,6 @@ pub struct NodeInfoInternal { pub metadata: Map, } -/// Node legacy metadata about a server running in the federation, only used for deserialization. -#[derive(Debug, PartialEq, Deserialize)] -pub(crate) struct LegacyNodeInfo<'a> { - version: NodeVersion, - software: Software<&'a str>, - #[serde(default)] - services: Services<&'a str>, - #[serde(default)] - protocols: Services<&'a str>, - #[serde(rename = "openRegistrations", default)] - open_registrations: bool, - #[serde(default)] - usage: Usage, - #[serde(default)] - metadata: Map, -} - /// Software contains infos about software running on the node. #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct Software { @@ -101,11 +85,12 @@ impl<'a> Services<&'a str> { } } +#[allow(unused)] impl NodeInfo<'_> { /// Converts all internal `&str`s into `String`s. pub fn to_owned(&self) -> NodeInfoOwned { NodeInfoOwned { - version: self.version.to_string(), + version: self.version.clone(), software: self.software.to_owned(), protocols: self.protocols.iter().map(ToString::to_string).collect(), services: self.services.to_owned(), @@ -115,33 +100,3 @@ impl NodeInfo<'_> { } } } - -impl<'a> From> for NodeInfo<'a> { - fn from(other: LegacyNodeInfo<'a>) -> Self { - let mut combined_protocols: Vec<&'a str> = other - .protocols - .inbound - .into_iter() - .chain(other.protocols.outbound) - .collect(); - combined_protocols.sort(); - combined_protocols.dedup(); - - NodeInfo { - version: other.version, - software: other.software, - services: other.services, - protocols: combined_protocols, - open_registrations: other.open_registrations, - usage: other.usage, - metadata: other.metadata, - } - } -} - -impl<'a> From> for NodeInfoOwned { - fn from(value: LegacyNodeInfo<'a>) -> Self { - NodeInfo::from(value).to_owned() - } -} -