From: Felix Date: Fri, 17 Apr 2020 14:39:03 +0000 (+0200) Subject: Remove instance follows X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%24%7B%60data:application/static/%7B%60https:/%7BmarkdownHelpUrl%7D?a=commitdiff_plain;h=9c974fbe505f5518ba0541633e8f043edca18e69;p=lemmy.git Remove instance follows --- diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index a4e5c307..61db932c 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -24,7 +24,6 @@ services: - LEMMY_JWT_SECRET=changeme - LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FEDERATION__ENABLED=true - - LEMMY_FEDERATION__FOLLOWED_INSTANCES=lemmy_beta:8550 - LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_PORT=8540 - LEMMY_SETUP__ADMIN_USERNAME=lemmy_alpha @@ -58,7 +57,6 @@ services: - LEMMY_JWT_SECRET=changeme - LEMMY_FRONT_END_DIR=/app/dist - LEMMY_FEDERATION__ENABLED=true - - LEMMY_FEDERATION__FOLLOWED_INSTANCES=lemmy_alpha:8540 - LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_PORT=8550 - LEMMY_SETUP__ADMIN_USERNAME=lemmy_beta diff --git a/server/config/defaults.hjson b/server/config/defaults.hjson index 8603e49a..509bef47 100644 --- a/server/config/defaults.hjson +++ b/server/config/defaults.hjson @@ -54,8 +54,6 @@ federation: { # whether to enable activitypub federation. this feature is in alpha, do not enable in production. enabled: false - # comma seperated list of instances to follow - followed_instances: "" # whether tls is required for activitypub. only disable this for debugging, never for producion. tls_enabled: true } diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index f29d9f19..3be53ea7 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -9,23 +9,22 @@ use crate::db::user_view::UserView; use crate::db::{Crud, SearchType}; use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}; use crate::settings::Settings; -use activitystreams::collection::{OrderedCollection, UnorderedCollection}; +use activitystreams::collection::OrderedCollection; use activitystreams::object::Page; use activitystreams::BaseBox; use diesel::result::Error::NotFound; use diesel::PgConnection; use failure::Error; use isahc::prelude::*; -use log::warn; use serde::Deserialize; use std::time::Duration; use url::Url; -fn fetch_node_info(instance: &Instance) -> Result { +fn _fetch_node_info(domain: &str) -> Result { let well_known_uri = Url::parse(&format!( "{}://{}/.well-known/nodeinfo", get_apub_protocol_string(), - instance.domain + domain ))?; let well_known = fetch_remote_object::(&well_known_uri)?; Ok(fetch_remote_object::(&well_known.links.href)?) @@ -61,22 +60,6 @@ fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result } } -fn fetch_communities_from_instance( - community_list: &Url, - conn: &PgConnection, -) -> Result, Error> { - fetch_remote_object::(community_list)? - .collection_props - .get_many_items_base_boxes() - .unwrap() - .map(|b| -> Result { - let group = b.to_owned().to_concrete::()?; - Ok(CommunityForm::from_group(&group, conn)?) - }) - .map(|cf| upsert_community(&cf?, conn)) - .collect() -} - // TODO: add an optional param last_updated and only fetch if its too old pub fn fetch_remote_object(url: &Url) -> Result where @@ -126,6 +109,7 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result { let c = upsert_community(&CommunityForm::from_group(&g, conn)?, conn)?; + fetch_community_outbox(&c, conn)?; response.communities = vec![CommunityView::read(conn, c.id, None)?]; } SearchAcceptedObjects::Page(p) => { @@ -133,14 +117,10 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result Result, Error> { +fn fetch_community_outbox(community: &Community, conn: &PgConnection) -> Result, Error> { let outbox_url = Url::parse(&community.get_outbox_url())?; let outbox = fetch_remote_object::(&outbox_url)?; let items = outbox.collection_props.get_many_items_base_boxes(); @@ -168,23 +148,3 @@ pub fn fetch_remote_community(apub_id: &Url, conn: &PgConnection) -> Result Result<(), Error> { - for instance in &get_following_instances() { - let node_info = fetch_node_info(instance)?; - if let Some(community_list) = node_info.metadata.community_list_url { - let communities = fetch_communities_from_instance(&community_list, conn)?; - for c in communities { - fetch_remote_community_posts(&c, conn)?; - } - } else { - warn!( - "{} is not a Lemmy instance, federation is not supported", - instance.domain - ); - } - } - Ok(()) -} diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 11b513be..04b462bf 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -27,10 +27,6 @@ pub enum EndpointType { Comment, } -pub struct Instance { - domain: String, -} - fn create_apub_response(json: &T) -> HttpResponse where T: serde::ser::Serialize, @@ -92,14 +88,3 @@ pub fn gen_keypair_str() -> (String, String) { fn vec_bytes_to_str(bytes: Vec) -> String { String::from_utf8_lossy(&bytes).into_owned() } - -pub fn get_following_instances() -> Vec { - Settings::get() - .federation - .followed_instances - .split(',') - .map(|i| Instance { - domain: i.to_string(), - }) - .collect() -} diff --git a/server/src/main.rs b/server/src/main.rs index 2b4e8b08..a4acf1ec 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -7,15 +7,10 @@ use actix_web::*; use diesel::r2d2::{ConnectionManager, Pool}; use diesel::PgConnection; use failure::Error; -use lemmy_server::apub::fetcher::fetch_all; use lemmy_server::db::code_migrations::run_advanced_migrations; use lemmy_server::routes::{api, federation, feeds, index, nodeinfo, webfinger, websocket}; use lemmy_server::settings::Settings; use lemmy_server::websocket::server::*; -use log::warn; -use std::thread; -use std::thread::sleep; -use std::time::Duration; embed_migrations!(); @@ -39,16 +34,6 @@ async fn main() -> Result<(), Error> { // Set up websocket server let server = ChatServer::startup(pool.clone()).start(); - thread::spawn(move || { - // some work here - sleep(Duration::from_secs(5)); - println!("Fetching apub data"); - match fetch_all(&conn) { - Ok(_) => {} - Err(e) => warn!("Error during apub fetch: {}", e), - } - }); - println!( "Starting http server at {}:{}", settings.bind, settings.port diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs index 4be4e54b..ef7ba56f 100644 --- a/server/src/routes/federation.rs +++ b/server/src/routes/federation.rs @@ -6,10 +6,6 @@ pub fn config(cfg: &mut web::ServiceConfig) { if Settings::get().federation.enabled { println!("federation enabled, host is {}", Settings::get().hostname); cfg - .route( - "/federation/communities", - web::get().to(apub::community::get_apub_community_list), - ) // TODO: check the user/community params for these .route( "/federation/c/{_}/inbox", diff --git a/server/src/routes/nodeinfo.rs b/server/src/routes/nodeinfo.rs index a8ae2138..8f50fbc7 100644 --- a/server/src/routes/nodeinfo.rs +++ b/server/src/routes/nodeinfo.rs @@ -61,13 +61,6 @@ async fn node_info( local_comments: site_view.number_of_comments, open_registrations: site_view.open_registration, }, - metadata: NodeInfoMetadata { - community_list_url: Some(Url::parse(&format!( - "{}://{}/federation/communities", - get_apub_protocol_string(), - Settings::get().hostname - ))?), - }, }) }) .await @@ -93,7 +86,6 @@ pub struct NodeInfo { pub software: NodeInfoSoftware, pub protocols: Vec, pub usage: NodeInfoUsage, - pub metadata: NodeInfoMetadata, } #[derive(Serialize, Deserialize, Debug)] @@ -115,8 +107,3 @@ pub struct NodeInfoUsage { pub struct NodeInfoUsers { pub total: i64, } - -#[derive(Serialize, Deserialize, Debug)] -pub struct NodeInfoMetadata { - pub community_list_url: Option, -} diff --git a/server/src/settings.rs b/server/src/settings.rs index d9d7a229..a82e4786 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -63,7 +63,6 @@ pub struct Database { #[derive(Debug, Deserialize, Clone)] pub struct Federation { pub enabled: bool, - pub followed_instances: String, pub tls_enabled: bool, }