Add optional publish-blocks option
This commit is contained in:
		
							parent
							
								
									82d837b963
								
							
						
					
					
						commit
						d00961ae86
					
				
					 4 changed files with 36 additions and 12 deletions
				
			
		|  | @ -21,7 +21,8 @@ $ ./relay -w asonix.dog blimps.xyz | ||||||
| $ ./relay -uw asonix.dog blimps.xyz | $ ./relay -uw asonix.dog blimps.xyz | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Whitelisted domains are only checked against incoming activities if `WHITELIST_MODE` is enabled | Whitelisted domains are only checked against incoming activities if `WHITELIST_MODE` is enabled. | ||||||
|  | Blocks can be published in the nodeinfo metadata by settings `PUBLISH_BLOCKS` to true | ||||||
| 
 | 
 | ||||||
| ### Subscribing | ### Subscribing | ||||||
| Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings. | Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings. | ||||||
|  | @ -61,6 +62,7 @@ VALIDATE_SIGNATURES=false | ||||||
| HTTPS=false | HTTPS=false | ||||||
| DATABASE_URL= | DATABASE_URL= | ||||||
| PRETTY_LOG=true | PRETTY_LOG=true | ||||||
|  | PUBLISH_BLOCKS=false | ||||||
| ``` | ``` | ||||||
| To run this server in production, you'll likely want to set most of them | To run this server in production, you'll likely want to set most of them | ||||||
| ```env | ```env | ||||||
|  | @ -73,6 +75,7 @@ VALIDATE_SIGNATURES=true | ||||||
| HTTPS=true | HTTPS=true | ||||||
| DATABASE_URL=postgres://pg_user:pg_pass@pg_host:pg_port/pg_database | DATABASE_URL=postgres://pg_user:pg_pass@pg_host:pg_port/pg_database | ||||||
| PRETTY_LOG=false | PRETTY_LOG=false | ||||||
|  | PUBLISH_BLOCKS=true | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ### Contributing | ### Contributing | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ pub struct Config { | ||||||
|     https: bool, |     https: bool, | ||||||
|     database_url: String, |     database_url: String, | ||||||
|     pretty_log: bool, |     pretty_log: bool, | ||||||
|  |     publish_blocks: bool, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub enum UrlKind { | pub enum UrlKind { | ||||||
|  | @ -42,6 +43,7 @@ impl Config { | ||||||
|             .set_default("validate_signatures", false)? |             .set_default("validate_signatures", false)? | ||||||
|             .set_default("https", false)? |             .set_default("https", false)? | ||||||
|             .set_default("pretty_log", true)? |             .set_default("pretty_log", true)? | ||||||
|  |             .set_default("publish_blocks", false)? | ||||||
|             .merge(Environment::new())?; |             .merge(Environment::new())?; | ||||||
| 
 | 
 | ||||||
|         Ok(config.try_into()?) |         Ok(config.try_into()?) | ||||||
|  | @ -79,6 +81,10 @@ impl Config { | ||||||
|         self.debug |         self.debug | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     pub fn publish_blocks(&self) -> bool { | ||||||
|  |         self.publish_blocks | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     pub fn whitelist_mode(&self) -> bool { |     pub fn whitelist_mode(&self) -> bool { | ||||||
|         self.whitelist_mode |         self.whitelist_mode | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -4,22 +4,24 @@ use crate::{ | ||||||
| }; | }; | ||||||
| use actix_web::{web, Responder}; | use actix_web::{web, Responder}; | ||||||
| use actix_webfinger::Link; | use actix_webfinger::Link; | ||||||
| use serde_json::json; |  | ||||||
| 
 | 
 | ||||||
| pub async fn well_known(config: web::Data<Config>) -> impl Responder { | pub async fn well_known(config: web::Data<Config>) -> impl Responder { | ||||||
|     web::Json(json!({ |     web::Json(Links { | ||||||
|         "links": [ |         links: vec![Link { | ||||||
|             Link { |             rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), | ||||||
|                 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(), |             href: Some(config.generate_url(UrlKind::NodeInfo)), | ||||||
|                 href: Some(config.generate_url(UrlKind::NodeInfo)), |             template: None, | ||||||
|                 template: None, |             kind: None, | ||||||
|                 kind: None, |         }], | ||||||
|             } |     }) | ||||||
|         ] |  | ||||||
|     })) |  | ||||||
|     .with_header("Content-Type", "application/jrd+json") |     .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> { | pub async fn route(config: web::Data<Config>, state: web::Data<State>) -> web::Json<NodeInfo> { | ||||||
|     web::Json(NodeInfo { |     web::Json(NodeInfo { | ||||||
|         version: NodeInfoVersion, |         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()) |                 .filter_map(|listener| listener.as_url().domain()) | ||||||
|                 .map(|s| s.to_owned()) |                 .map(|s| s.to_owned()) | ||||||
|                 .collect(), |                 .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)] | #[derive(Clone, Debug, Default, serde::Serialize)] | ||||||
| pub struct Metadata { | pub struct Metadata { | ||||||
|     peers: Vec<String>, |     peers: Vec<String>, | ||||||
|  | 
 | ||||||
|  |     #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|  |     blocks: Option<Vec<String>>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Clone, Debug, Default, serde::Serialize)] | #[derive(Clone, Debug, Default, serde::Serialize)] | ||||||
|  |  | ||||||
|  | @ -65,6 +65,11 @@ impl State { | ||||||
|         read_guard.iter().cloned().collect() |         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> { |     pub async fn listeners_without(&self, inbox: &XsdAnyUri, domain: &str) -> Vec<XsdAnyUri> { | ||||||
|         let read_guard = self.listeners.read().await; |         let read_guard = self.listeners.read().await; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue