posting to a person with a user on the same pod will send internally, skipping the http queue and encryption.

This commit is contained in:
danielvincent 2010-11-03 18:51:45 -07:00
parent b4679c9041
commit f4dba54ff3
9 changed files with 74 additions and 58 deletions

View file

@ -236,16 +236,23 @@ class User
def push_to_people(post, people)
salmon = salmon(post)
people.each { |person|
xml = salmon.xml_for person
push_to_person(person, xml)
}
people.each do |person|
push_to_person(salmon, post, person)
end
end
def push_to_person(person, xml)
Rails.logger.debug("#{self.real_name} is adding xml to message queue to #{person.receive_url}")
QUEUE.add_post_request(person.receive_url, xml)
QUEUE.process
def push_to_person(salmon, post, person)
# person.owner will always return a ProxyObject.
# calling nil? performs a necessary evaluation.
unless person.owner.nil?
person.owner.receive(post.to_diaspora_xml, self.person)
else
xml = salmon.xml_for person
Rails.logger.debug("#{self.real_name} is adding xml to message queue to #{person.receive_url}")
QUEUE.add_post_request(person.receive_url, xml)
QUEUE.process
end
end
def push_to_hub(post)

View file

@ -22,7 +22,6 @@ module Diaspora
aspect.requests << request
aspect.save
push_to_people request, [desired_friend]
end
request
@ -37,8 +36,7 @@ module Diaspora
end
def dispatch_friend_acceptance(request, requester)
friend_acceptance = salmon(request)
push_to_person requester, friend_acceptance.xml_for(requester)
push_to_people request, [requester]
request.destroy unless request.callback_url.include? url
end
@ -79,7 +77,7 @@ module Diaspora
friend_request.save
Notifier.new_request(self, friend_request.person).deliver
else
Rails.logger.info("#{self.real_name} is trying to receive a friend request from himself.")
raise "#{self.real_name} is trying to receive a friend request from himself."
end
friend_request
end
@ -121,8 +119,8 @@ module Diaspora
new_contact = Contact.create(:user => self, :person => person, :aspects => [aspect])
new_contact.aspects << aspect
friends << new_contact
save
aspect.save
save!
aspect.save!
end
def request_from_me?(request)

View file

@ -32,7 +32,7 @@ module Diaspora
end
if (salmon_author.diaspora_handle != xml_author)
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{xml_author} "
raise "Malicious Post, #{salmon_author.real_name} with handle #{salmon_author.diaspora_handle} is sending a #{object.class} as #{xml_author} "
end
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request) || object.is_a?(Retraction) || object.is_a?(Profile)
@ -92,10 +92,7 @@ module Diaspora
def receive_request request, person
request.person = person
request.person.save!
old_request = Request.find_by_diaspora_handle(request.diaspora_handle)
Rails.logger.info("I got a request from #{request.diaspora_handle} with old request #{old_request.inspect}")
request.aspect_id = old_request.aspect_id if old_request
request.save
request.save!
receive_friend_request(request)
end

View file

@ -29,12 +29,20 @@ module HelperMethods
def friend_users(user1, aspect1, user2, aspect2)
request = user1.send_friend_request_to(user2.person, aspect1)
new_request = user2.receive request.to_diaspora_xml, user1.person
reversed_request = user2.accept_friend_request( new_request.id, aspect2.id)
user1.reload
aspect1.reload
user2.reload
aspect2.reload
new_request = user2.pending_requests.find_by_destination_url!(user2.receive_url)
user1.reload
aspect1.reload
user2.reload
aspect2.reload
user2.accept_and_respond( new_request.id, aspect2.id)
user1.receive reversed_request.to_diaspora_xml, user2.person
user1.reload
aspect1.reload
user2.reload

View file

@ -66,5 +66,10 @@ describe 'making sure the spec runner works' do
@aspect2.people.include?(contact).should be_true
contact.aspects.include?( @aspect2 ).should be true
end
it 'allows posting after running' do
message = @user1.post(:status_message, :message => "Friendship!", :to => @aspect1.id)
@user2.reload.visible_posts.should include message
end
end
end

View file

@ -11,6 +11,8 @@ describe Comment do
let(:user2) {make_user}
let(:aspect2) {user2.aspects.create(:name => "Lame-faces")}
let!(:friending) { friend_users(user, aspect, user2, aspect2) }
it 'validates that the handle belongs to the person' do
user_status = user.post(:status_message, :message => "hello", :to => aspect.id)
comment = Comment.new(:person_id => user2.person.id, :text => "hey", :post => user_status)
@ -44,8 +46,6 @@ describe Comment do
describe 'comment propagation' do
before do
friend_users(user, aspect, user2, aspect2)
@person = Factory.create(:person)
user.activate_friend(@person, Aspect.first(:id => aspect.id))
@ -60,25 +60,30 @@ describe Comment do
end
it "should send a user's comment on a person's post to that person" do
User::QUEUE.should_receive(:add_post_request)
User::QUEUE.should_receive(:add_post_request).once
user.comment "yo", :on => @person_status
end
it 'should send a user comment on his own post to lots of people' do
User::QUEUE.should_receive(:add_post_request).once
user2.raw_visible_posts.count.should == 0
User::QUEUE.should_receive(:add_post_request).twice
user.comment "yo", :on => @user_status
user2.reload
user2.raw_visible_posts.count.should == 1
end
it 'should send a comment a person made on your post to all people' do
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status)
User::QUEUE.should_receive(:add_post_request).once
user.receive comment.to_diaspora_xml, @person
end
it 'should send a comment a user made on your post to all people' do
comment = user2.comment( "balls", :on => @user_status)
User::QUEUE.should_receive(:add_post_request).twice
User::QUEUE.should_receive(:add_post_request).once
user.receive comment.to_diaspora_xml, user2.person
end
@ -86,20 +91,22 @@ describe Comment do
before(:all) do
stub_comment_signature_verification
end
it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
after(:all) do
unstub_mocha_stubs
end
it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
user.receive comment.to_diaspora_xml, @person
end
after(:all) do
unstub_mocha_stubs
end
end
it 'should not clear the aspect post array on receiving a comment' do
@ -128,12 +135,10 @@ describe Comment do
describe 'comments' do
before do
friend_users(user, aspect, user2, aspect2)
@remote_message = user2.post :status_message, :message => "hello", :to => aspect2.id
@message = user.post :status_message, :message => "hi", :to => aspect.id
end
it 'should attach the creator signature if the user is commenting' do
user.comment "Yeah, it was great", :on => @remote_message
@remote_message.comments.first.signature_valid?.should be true

View file

@ -131,11 +131,12 @@ describe User do
end
it 'does not use the queue for local transfer' do
User::QUEUE.should_receive(:add_post_request).twice
User::QUEUE.should_receive(:add_post_request).once
remote_person = user4.person
remote_person.owner_id = nil
remote_person.save
remote_person.reload
user.push_to_people(post, [user2.person, user3.person, remote_person])
end

View file

@ -14,8 +14,8 @@ describe User do
let(:user3) { make_user }
let(:aspect3) { user3.aspects.create(:name => 'heroes') }
let(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)}
let!(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)}
let(:photo) {user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)}
before do
@ -90,21 +90,20 @@ describe User do
describe 'post refs' do
before do
@status_message = user2.post :status_message, :message => "hi", :to =>aspect2.id
user.receive @status_message.to_diaspora_xml, user2.person
@status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.reload
aspect.reload
end
it "should add a received post to the aspect and visible_posts array" do
user.raw_visible_posts.include?(@status_message).should be true
aspect.reload
user.raw_visible_posts.include?(@status_message).should be_true
aspect.posts.include?(@status_message).should be_true
end
it 'should be removed on unfriending' do
user.unfriend(user2.person)
user.reload
user.raw_visible_posts.count.should == 0
user.raw_visible_posts.count.should == 1
end
it 'should be remove a post if the noone links to it' do
@ -112,8 +111,6 @@ describe User do
user2.delete
lambda {user.unfriend(person)}.should change(Post, :count).by(-1)
user.reload
user.raw_visible_posts.count.should == 0
end
it 'should keep track of user references for one person ' do

View file

@ -83,7 +83,7 @@ describe Diaspora::UserModules::Friending do
user.save
proc { user.receive_friend_request(reversed_request)
}.should change(user.reload.pending_requests, :count).by(0)
}.should raise_error /request from himself/
end
end
@ -249,9 +249,7 @@ describe Diaspora::UserModules::Friending do
context 'with a post' do
before do
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
user2.receive @message.to_diaspora_xml.to_s, user.person
user2.unfriend user.person
user.unfriended_by user2.person
end
it "deletes the unfriended user's posts from visible_posts" do
user.reload.raw_visible_posts.include?(@message.id).should be_false