From a882fbea97a4aa4d53dd1a9e3599659f853543ed Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 19 Dec 2019 01:29:56 +0100 Subject: [PATCH] Added option to enable/disable federation --- server/config/defaults.hjson | 3 +++ server/src/main.rs | 11 +++++++++-- server/src/nodeinfo.rs | 7 ++++++- server/src/settings.rs | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/config/defaults.hjson b/server/config/defaults.hjson index e65bbcf43..ceb21db0e 100644 --- a/server/config/defaults.hjson +++ b/server/config/defaults.hjson @@ -22,6 +22,9 @@ port: 8536 # json web token for authorization between server and client jwt_secret: "changeme" + # whether to enable activitypub federation. this feature is in alpha, do not enable in production, as might + # cause problems like remote instances fetching and permanently storing bad data. + federation_enabled: false # rate limits for various user actions, by user ip rate_limit: { # maximum number of messages created in interval diff --git a/server/src/main.rs b/server/src/main.rs index 29f361ea3..398a6c39a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -198,7 +198,7 @@ fn main() { // Create Http server with websocket support HttpServer::new(move || { - App::new() + let app = App::new() .data(server.clone()) // Front end routes .service(actix_files::Files::new("/static", front_end_dir())) @@ -257,10 +257,17 @@ fn main() { .route( "/federation/u/{user_name}", web::get().to(apub::user::get_apub_user)) - .route( + .route("/feeds/all.xml", web::get().to(feeds::get_all_feed)); + + // Federation + if Settings::get().federation_enabled { + app.route( ".well-known/webfinger", web::get().to(webfinger::get_webfinger_response), ) + } else { + app + } }) .bind((settings.bind, settings.port)) .unwrap() diff --git a/server/src/nodeinfo.rs b/server/src/nodeinfo.rs index f8135c7d0..65bd93700 100644 --- a/server/src/nodeinfo.rs +++ b/server/src/nodeinfo.rs @@ -25,13 +25,18 @@ pub fn node_info() -> HttpResponse { Ok(site_view) => site_view, Err(_e) => return HttpResponse::InternalServerError().finish(), }; + let protocols = if Settings::get().federation_enabled { + vec!["activitypub"] + } else { + vec![] + }; let json = json!({ "version": "2.0", "software": { "name": "lemmy", "version": version::VERSION, }, - "protocols": [], + "protocols": protocols, "usage": { "users": { "total": site_view.number_of_users diff --git a/server/src/settings.rs b/server/src/settings.rs index 4df2979e1..7da19c0f7 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -16,6 +16,7 @@ pub struct Settings { pub jwt_secret: String, pub rate_limit: RateLimitConfig, pub email: Option, + pub federation_enabled: bool, } #[derive(Debug, Deserialize)]