Add optional publish-blocks option
This commit is contained in:
@@ -16,6 +16,7 @@ pub struct Config {
|
||||
https: bool,
|
||||
database_url: String,
|
||||
pretty_log: bool,
|
||||
publish_blocks: bool,
|
||||
}
|
||||
|
||||
pub enum UrlKind {
|
||||
@@ -42,6 +43,7 @@ impl Config {
|
||||
.set_default("validate_signatures", false)?
|
||||
.set_default("https", false)?
|
||||
.set_default("pretty_log", true)?
|
||||
.set_default("publish_blocks", false)?
|
||||
.merge(Environment::new())?;
|
||||
|
||||
Ok(config.try_into()?)
|
||||
@@ -79,6 +81,10 @@ impl Config {
|
||||
self.debug
|
||||
}
|
||||
|
||||
pub fn publish_blocks(&self) -> bool {
|
||||
self.publish_blocks
|
||||
}
|
||||
|
||||
pub fn whitelist_mode(&self) -> bool {
|
||||
self.whitelist_mode
|
||||
}
|
||||
|
||||
+21
-11
@@ -4,22 +4,24 @@ use crate::{
|
||||
};
|
||||
use actix_web::{web, Responder};
|
||||
use actix_webfinger::Link;
|
||||
use serde_json::json;
|
||||
|
||||
pub async fn well_known(config: web::Data<Config>) -> impl Responder {
|
||||
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,
|
||||
}
|
||||
]
|
||||
}))
|
||||
web::Json(Links {
|
||||
links: vec![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")
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct Links {
|
||||
links: Vec<Link>,
|
||||
}
|
||||
|
||||
pub async fn route(config: web::Data<Config>, state: web::Data<State>) -> web::Json<NodeInfo> {
|
||||
web::Json(NodeInfo {
|
||||
version: NodeInfoVersion,
|
||||
@@ -50,6 +52,11 @@ pub async fn route(config: web::Data<Config>, state: web::Data<State>) -> web::J
|
||||
.filter_map(|listener| listener.as_url().domain())
|
||||
.map(|s| s.to_owned())
|
||||
.collect(),
|
||||
blocks: if config.publish_blocks() {
|
||||
Some(state.blocks().await)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -102,6 +109,9 @@ pub struct Usage {
|
||||
#[derive(Clone, Debug, Default, serde::Serialize)]
|
||||
pub struct Metadata {
|
||||
peers: Vec<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
blocks: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, serde::Serialize)]
|
||||
|
||||
@@ -65,6 +65,11 @@ impl State {
|
||||
read_guard.iter().cloned().collect()
|
||||
}
|
||||
|
||||
pub async fn blocks(&self) -> Vec<String> {
|
||||
let read_guard = self.blocks.read().await;
|
||||
read_guard.iter().cloned().collect()
|
||||
}
|
||||
|
||||
pub async fn listeners_without(&self, inbox: &XsdAnyUri, domain: &str) -> Vec<XsdAnyUri> {
|
||||
let read_guard = self.listeners.read().await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user