- // Skip it if it can't connect
- let res = client
- .get(&node_info_url)
- .send()
- .ok()
- .and_then(|t| t.json::<NodeInfo>().ok());
-
- if let Some(node_info) = res {
- let software = node_info.software.as_ref();
- let form = InstanceForm::builder()
- .domain(instance.domain)
- .software(software.and_then(|s| s.name.clone()))
- .version(software.and_then(|s| s.version.clone()))
- .updated(Some(naive_now()))
- .build();
-
- match diesel::update(instance::table.find(instance.id))
- .set(form)
- .execute(conn)
- {
- Ok(_) => {
- info!("Done.");
+ // The `updated` column is used to check if instances are alive. If it is more than three days
+ // in the past, no outgoing activities will be sent to that instance. However not every
+ // Fediverse instance has a valid Nodeinfo endpoint (its not required for Activitypub). That's
+ // why we always need to mark instances as updated if they are alive.
+ let default_form = InstanceForm::builder()
+ .domain(instance.domain.clone())
+ .updated(Some(naive_now()))
+ .build();
+ let form = match client.get(&node_info_url).send() {
+ Ok(res) if res.status().is_client_error() => {
+ // Instance doesnt have nodeinfo but sent a response, consider it alive
+ Some(default_form)
+ }
+ Ok(res) => match res.json::<NodeInfo>() {
+ Ok(node_info) => {
+ // Instance sent valid nodeinfo, write it to db
+ Some(
+ InstanceForm::builder()
+ .domain(instance.domain)
+ .updated(Some(naive_now()))
+ .software(node_info.software.and_then(|s| s.name))
+ .version(node_info.version.clone())
+ .build(),
+ )