tirocinio-canali-steffo-acrate/acrate-nodeinfo/src/lib.rs

77 lines
1.8 KiB
Rust
Raw Normal View History

//! Serde-based loose [NodeInfo] fetcher and parser.
2024-11-11 02:20:48 +00:00
//!
//! [NodeInfo]: https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1 {
pub version: String,
pub software: NodeInfo1Software,
pub protocols: NodeInfo1Protocols,
pub services: NodeInfo1Services,
pub open_registrations: bool,
pub usage: NodeInfo1Usage,
pub metadata: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo2 {
pub version: String,
pub instance: Option<NodeInfo2Instance>,
pub software: NodeInfo1Software,
pub protocols: NodeInfo1Protocols,
pub services: NodeInfo1Services,
pub open_registrations: bool,
pub usage: NodeInfo1Usage,
pub metadata: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1Software {
pub name: String,
pub version: String,
pub repository: Option<String>,
pub homepage: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1Protocols {
pub inbound: Vec<String>,
pub outbound: Vec<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1Services {
pub inbound: Vec<String>,
pub outbound: Vec<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1Usage {
pub users: NodeInfo1UsageUsers,
pub local_posts: i32,
pub local_comments: i32,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo1UsageUsers {
pub total: i32,
pub active_halfyear: i32,
pub active_month: i32,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeInfo2Instance {
pub name: String,
pub description: String,
}