Unverified Commit fe5811bb authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert
Browse files

Don't federate to pods that are offline for more than two weeks

Also fix a case where offline_since can be nil.

fixes #6220

closes #7120
parent a37d9d53
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ Note: Although this is a minor release, the configuration file changed because t
* You'll now get redirected to the invites page if you follow an invitation but you're already logged in [#7061](https://github.com/diaspora/diaspora/pull/7061)
* Add support for setting BOSH access protocol via chat configuration [#7100](https://github.com/diaspora/diaspora/pull/7100)
* Add number of unreviewed reports to admin dashboard and admin sidebar [#7109](https://github.com/diaspora/diaspora/pull/7109)
* Don't federate to pods that have been offline for an extended period of time [#7120](https://github.com/diaspora/diaspora/pull/7120)

# 0.6.0.1

+8 −3
Original line number Diff line number Diff line
@@ -66,8 +66,13 @@ class Pod < ActiveRecord::Base
    Pod.offline_statuses.include?(Pod.statuses[status])
  end

  def was_offline?
    Pod.offline_statuses.include?(Pod.statuses[status_was])
  # a pod is active if it is online or was online less than 14 days ago
  def active?
    !offline? || offline_since.try {|date| date > DateTime.now.utc - 14.days }
  end

  def to_s
    "#{id}:#{host}"
  end

  def test_connection!
@@ -87,7 +92,7 @@ class Pod < ActiveRecord::Base

  def update_offline_since
    if offline?
      touch(:offline_since) unless was_offline?
      self.offline_since ||= DateTime.now.utc
    else
      self.offline_since = nil
    end
+3 −1
Original line number Diff line number Diff line
@@ -12,7 +12,9 @@ module Diaspora
        end

        def targets(people, salmon_slap)
          people.map {|person| [person.receive_url, salmon_slap.generate_xml(person.public_key)] }.to_h
          active, inactive = people.partition {|person| person.pod.active? }
          logger.info "ignoring inactive pods: #{inactive.map(&:diaspora_handle).join(', ')}" if inactive.any?
          active.map {|person| [person.receive_url, salmon_slap.generate_xml(person.public_key)] }.to_h
        end

        def salmon_slap(entity)
+3 −1
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ module Diaspora
        end

        def target_urls(people)
          Pod.where(id: people.map(&:pod_id).uniq).map {|pod| pod.url_to("/receive/public") }
          active, inactive = Pod.where(id: people.map(&:pod_id).uniq).partition(&:active?)
          logger.info "ignoring inactive pods: #{inactive.join(', ')}" if inactive.any?
          active.map {|pod| pod.url_to("/receive/public") }
        end

        def additional_target_urls
+19 −0
Original line number Diff line number Diff line
@@ -71,6 +71,25 @@ describe Diaspora::Federation::Dispatcher::Private do

        Diaspora::Federation::Dispatcher.build(alice, post, subscribers: [remote_person]).dispatch
      end

      it "only queues a private send job for a active pods" do
        remote_person = FactoryGirl.create(:person)
        offline_pod = FactoryGirl.create(:pod, status: :net_failed, offline_since: DateTime.now.utc - 15.days)
        offline_person = FactoryGirl.create(:person, pod: offline_pod)

        expect(Workers::SendPrivate).to receive(:perform_async) do |user_id, _entity_string, targets|
          expect(user_id).to eq(alice.id)
          expect(targets.size).to eq(1)
          expect(targets).to have_key(remote_person.receive_url)
          expect(targets[remote_person.receive_url]).to eq(xml)
        end

        salmon = double
        expect(DiasporaFederation::Salmon::EncryptedSlap).to receive(:prepare).and_return(salmon)
        expect(salmon).to receive(:generate_xml).and_return(xml)

        Diaspora::Federation::Dispatcher.build(alice, post, subscribers: [remote_person, offline_person]).dispatch
      end
    end
  end

Loading