]> Untitled Git - lemmy.git/commitdiff
Remove instance follows
authorFelix <me@nutomic.com>
Fri, 17 Apr 2020 14:39:03 +0000 (16:39 +0200)
committerFelix <me@nutomic.com>
Fri, 17 Apr 2020 14:39:03 +0000 (16:39 +0200)
docker/federation/docker-compose.yml
server/config/defaults.hjson
server/src/apub/fetcher.rs
server/src/apub/mod.rs
server/src/main.rs
server/src/routes/federation.rs
server/src/routes/nodeinfo.rs
server/src/settings.rs

index a4e5c3074bd68a2bb3c968a0b59fbb11c18bb3eb..61db932cc44f2f765a7458de3015685503ee5031 100644 (file)
@@ -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
index 8603e49a8b3e5edd4788b013c989e02cf82e370a..509bef47d622547946578d0b71ea1aa5f33adcc5 100644 (file)
@@ -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
   }
index f29d9f19fcb152f6c00598c5c7f8cd1f6e7e6123..3be53ea7264082c84769989d18af8d5c9365dcb6 100644 (file)
@@ -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<NodeInfo, Error> {
+fn _fetch_node_info(domain: &str) -> Result<NodeInfo, Error> {
   let well_known_uri = Url::parse(&format!(
     "{}://{}/.well-known/nodeinfo",
     get_apub_protocol_string(),
-    instance.domain
+    domain
   ))?;
   let well_known = fetch_remote_object::<NodeInfoWellKnown>(&well_known_uri)?;
   Ok(fetch_remote_object::<NodeInfo>(&well_known.links.href)?)
@@ -61,22 +60,6 @@ fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, Error>
   }
 }
 
-fn fetch_communities_from_instance(
-  community_list: &Url,
-  conn: &PgConnection,
-) -> Result<Vec<Community>, Error> {
-  fetch_remote_object::<UnorderedCollection>(community_list)?
-    .collection_props
-    .get_many_items_base_boxes()
-    .unwrap()
-    .map(|b| -> Result<CommunityForm, Error> {
-      let group = b.to_owned().to_concrete::<GroupExt>()?;
-      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<Response>(url: &Url) -> Result<Response, Error>
 where
@@ -126,6 +109,7 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchRespo
     }
     SearchAcceptedObjects::Group(g) => {
       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<SearchRespo
       response.posts = vec![PostView::read(conn, p.id, None)?];
     }
   }
-  dbg!(&response);
   Ok(response)
 }
 
-fn fetch_remote_community_posts(
-  community: &Community,
-  conn: &PgConnection,
-) -> Result<Vec<Post>, Error> {
+fn fetch_community_outbox(community: &Community, conn: &PgConnection) -> Result<Vec<Post>, Error> {
   let outbox_url = Url::parse(&community.get_outbox_url())?;
   let outbox = fetch_remote_object::<OrderedCollection>(&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<Comm
   let cf = CommunityForm::from_group(&group, conn)?;
   upsert_community(&cf, conn)
 }
-
-// TODO: in the future, this should only be done when an instance is followed for the first time
-//       after that, we should rely in the inbox, and fetch on demand when needed
-pub fn fetch_all(conn: &PgConnection) -> 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(())
-}
index 11b513bebf9bca008185b6bfd27c93b589bff33b..04b462bff9267a1d8a34236ab471a59a47d7b205 100644 (file)
@@ -27,10 +27,6 @@ pub enum EndpointType {
   Comment,
 }
 
-pub struct Instance {
-  domain: String,
-}
-
 fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
 where
   T: serde::ser::Serialize,
@@ -92,14 +88,3 @@ pub fn gen_keypair_str() -> (String, String) {
 fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
   String::from_utf8_lossy(&bytes).into_owned()
 }
-
-pub fn get_following_instances() -> Vec<Instance> {
-  Settings::get()
-    .federation
-    .followed_instances
-    .split(',')
-    .map(|i| Instance {
-      domain: i.to_string(),
-    })
-    .collect()
-}
index 2b4e8b081ed8f4ad5a20b7cc423b31af06b9c9c9..a4acf1ec0fb35eeeff164f95e68568ef49830ccc 100644 (file)
@@ -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
index 4be4e54b518c998499e815a52fa0bb46575669db..ef7ba56f826068ca568b540bfe2188cd73f8a3f1 100644 (file)
@@ -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",
index a8ae213889f3bd49505f4a6d80e427ffe8a25d12..8f50fbc793bd8a26263b823d0b2d0e4d14ce9f38 100644 (file)
@@ -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<String>,
   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<Url>,
-}
index d9d7a2291a388bbf623ea86b3ec9dff2c8304628..a82e478601bd8fded283e5b76ee3148c403060dd 100644 (file)
@@ -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,
 }