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) def push_to_people(post, people)
salmon = salmon(post) salmon = salmon(post)
people.each { |person| people.each do |person|
xml = salmon.xml_for person push_to_person(salmon, post, person)
push_to_person(person, xml) end
}
end end
def push_to_person(person, xml) def push_to_person(salmon, post, person)
Rails.logger.debug("#{self.real_name} is adding xml to message queue to #{person.receive_url}") # person.owner will always return a ProxyObject.
QUEUE.add_post_request(person.receive_url, xml) # calling nil? performs a necessary evaluation.
QUEUE.process 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 end
def push_to_hub(post) def push_to_hub(post)

View file

@ -22,7 +22,6 @@ module Diaspora
aspect.requests << request aspect.requests << request
aspect.save aspect.save
push_to_people request, [desired_friend] push_to_people request, [desired_friend]
end end
request request
@ -37,8 +36,7 @@ module Diaspora
end end
def dispatch_friend_acceptance(request, requester) def dispatch_friend_acceptance(request, requester)
friend_acceptance = salmon(request) push_to_people request, [requester]
push_to_person requester, friend_acceptance.xml_for(requester)
request.destroy unless request.callback_url.include? url request.destroy unless request.callback_url.include? url
end end
@ -79,7 +77,7 @@ module Diaspora
friend_request.save friend_request.save
Notifier.new_request(self, friend_request.person).deliver Notifier.new_request(self, friend_request.person).deliver
else 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 end
friend_request friend_request
end end
@ -121,8 +119,8 @@ module Diaspora
new_contact = Contact.create(:user => self, :person => person, :aspects => [aspect]) new_contact = Contact.create(:user => self, :person => person, :aspects => [aspect])
new_contact.aspects << aspect new_contact.aspects << aspect
friends << new_contact friends << new_contact
save save!
aspect.save aspect.save!
end end
def request_from_me?(request) def request_from_me?(request)

View file

@ -32,7 +32,7 @@ module Diaspora
end end
if (salmon_author.diaspora_handle != xml_author) 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 end
if object.is_a?(Comment) || object.is_a?(Post)|| object.is_a?(Request) || object.is_a?(Retraction) || object.is_a?(Profile) 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 def receive_request request, person
request.person = person request.person = person
request.person.save! request.person.save!
old_request = Request.find_by_diaspora_handle(request.diaspora_handle) request.save!
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
receive_friend_request(request) receive_friend_request(request)
end end

View file

@ -29,12 +29,20 @@ module HelperMethods
def friend_users(user1, aspect1, user2, aspect2) def friend_users(user1, aspect1, user2, aspect2)
request = user1.send_friend_request_to(user2.person, aspect1) 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 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 user1.reload
aspect1.reload aspect1.reload
user2.reload user2.reload

View file

@ -66,5 +66,10 @@ describe 'making sure the spec runner works' do
@aspect2.people.include?(contact).should be_true @aspect2.people.include?(contact).should be_true
contact.aspects.include?( @aspect2 ).should be true contact.aspects.include?( @aspect2 ).should be true
end 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
end end

View file

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

View file

@ -131,11 +131,12 @@ describe User do
end end
it 'does not use the queue for local transfer' do 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 = user4.person
remote_person.owner_id = nil remote_person.owner_id = nil
remote_person.save remote_person.save
remote_person.reload
user.push_to_people(post, [user2.person, user3.person, remote_person]) user.push_to_people(post, [user2.person, user3.person, remote_person])
end end

View file

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

View file

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