diff --git a/src/config.rs b/src/config.rs index f6677e0..d334a0f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,7 +118,7 @@ impl Config { UrlKind::Following => format!("{}://{}/following", scheme, self.hostname), UrlKind::Inbox => format!("{}://{}/inbox", scheme, self.hostname), UrlKind::MainKey => format!("{}://{}/actor#main-key", scheme, self.hostname), - UrlKind::NodeInfo => format!("{}://{}/nodeinfo/2.0", scheme, self.hostname), + UrlKind::NodeInfo => format!("{}://{}/nodeinfo/2.0.json", scheme, self.hostname), UrlKind::Outbox => format!("{}://{}/outbox", scheme, self.hostname), } } diff --git a/src/main.rs b/src/main.rs index ca3a204..0180e62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,7 +120,7 @@ async fn main() -> Result<(), anyhow::Error> { .route(web::post().to(inbox::inbox)), ) .service(web::resource("/actor").route(web::get().to(actor::route))) - .service(web::resource("/nodeinfo/2.0").route(web::get().to(nodeinfo::route))) + .service(web::resource("/nodeinfo/2.0.json").route(web::get().to(nodeinfo::route))) .service( web::scope("/.well-known") .service(actix_webfinger::scoped::<_, RelayResolver>()) diff --git a/src/nodeinfo.rs b/src/nodeinfo.rs index 96803eb..b4683d7 100644 --- a/src/nodeinfo.rs +++ b/src/nodeinfo.rs @@ -1,19 +1,26 @@ -use crate::config::{Config, UrlKind}; +use crate::{ + config::{Config, UrlKind}, + state::State, +}; use actix_web::{web, Responder}; use actix_webfinger::Link; -use std::collections::HashMap; +use serde_json::json; pub async fn well_known(config: web::Data) -> impl Responder { - web::Json(Link { - rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), - href: Some(config.generate_url(UrlKind::NodeInfo)), - template: None, - kind: None, - }) + web::Json(json!({ + "links": [ + Link { + rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), + href: Some(config.generate_url(UrlKind::NodeInfo)), + template: None, + kind: None, + } + ] + })) .with_header("Content-Type", "application/jrd+json") } -pub async fn route(config: web::Data) -> web::Json { +pub async fn route(config: web::Data, state: web::Data) -> web::Json { web::Json(NodeInfo { version: NodeInfoVersion, software: Software { @@ -27,7 +34,15 @@ pub async fn route(config: web::Data) -> web::Json { local_posts: 0, local_comments: 0, }, - metadata: Metadata::default(), + metadata: Metadata { + peers: state + .listeners() + .await + .iter() + .filter_map(|listener| listener.as_url().domain()) + .map(|s| s.to_owned()) + .collect(), + }, }) } @@ -69,8 +84,9 @@ pub struct Usage { } #[derive(Clone, Debug, Default, serde::Serialize)] -#[serde(transparent)] -pub struct Metadata(pub HashMap); +pub struct Metadata { + peers: Vec, +} impl serde::ser::Serialize for NodeInfoVersion { fn serialize(&self, serializer: S) -> Result