better logging for receiving
This commit is contained in:
parent
a8af94f192
commit
0c4307a4de
4 changed files with 32 additions and 11 deletions
|
|
@ -2,6 +2,8 @@ module DiasporaFederation
|
||||||
module Federation
|
module Federation
|
||||||
# this module is for parse and receive entities.
|
# this module is for parse and receive entities.
|
||||||
module Receiver
|
module Receiver
|
||||||
|
extend Logging
|
||||||
|
|
||||||
# receive a public message
|
# receive a public message
|
||||||
# @param [String] data message to receive
|
# @param [String] data message to receive
|
||||||
# @param [Boolean] legacy use old slap parser
|
# @param [Boolean] legacy use old slap parser
|
||||||
|
|
@ -13,6 +15,10 @@ module DiasporaFederation
|
||||||
Salmon::MagicEnvelope.unenvelop(magic_env_xml)
|
Salmon::MagicEnvelope.unenvelop(magic_env_xml)
|
||||||
end
|
end
|
||||||
Public.new(magic_env).receive
|
Public.new(magic_env).receive
|
||||||
|
rescue => e
|
||||||
|
logger.error "failed to receive public message: #{e.class}: #{e.message}"
|
||||||
|
logger.debug "received data:\n#{data}"
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
# receive a private message
|
# receive a private message
|
||||||
|
|
@ -30,6 +36,10 @@ module DiasporaFederation
|
||||||
Salmon::MagicEnvelope.unenvelop(magic_env_xml)
|
Salmon::MagicEnvelope.unenvelop(magic_env_xml)
|
||||||
end
|
end
|
||||||
Private.new(magic_env, recipient_id).receive
|
Private.new(magic_env, recipient_id).receive
|
||||||
|
rescue => e
|
||||||
|
logger.error "failed to receive private message for #{recipient_id}: #{e.class}: #{e.message}"
|
||||||
|
logger.debug "received data:\n#{data}"
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ module DiasporaFederation
|
||||||
module Receiver
|
module Receiver
|
||||||
# common functionality for receivers
|
# common functionality for receivers
|
||||||
class AbstractReceiver
|
class AbstractReceiver
|
||||||
|
include Logging
|
||||||
|
|
||||||
# create a new receiver
|
# create a new receiver
|
||||||
# @param [MagicEnvelope] magic_envelope the received magic envelope
|
# @param [MagicEnvelope] magic_envelope the received magic envelope
|
||||||
# @param [Object] recipient_id the identifier of the recipient of a private message
|
# @param [Object] recipient_id the identifier of the recipient of a private message
|
||||||
|
|
@ -14,16 +16,25 @@ module DiasporaFederation
|
||||||
|
|
||||||
# validate and receive the entity
|
# validate and receive the entity
|
||||||
def receive
|
def receive
|
||||||
validate
|
validate_and_receive
|
||||||
DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
|
rescue => e
|
||||||
|
logger.error "failed to receive #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)}"
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :entity, :sender, :recipient_id
|
attr_reader :entity, :sender, :recipient_id
|
||||||
|
|
||||||
|
def validate_and_receive
|
||||||
|
validate
|
||||||
|
DiasporaFederation.callbacks.trigger(:receive_entity, entity, recipient_id)
|
||||||
|
logger.info "successfully received #{entity.class}#{":#{entity.guid}" if entity.respond_to?(:guid)}" \
|
||||||
|
"from person #{sender}#{" for #{recipient_id}" if recipient_id}"
|
||||||
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
raise InvalidSender unless sender_valid?
|
raise InvalidSender, "invalid sender: #{sender}" unless sender_valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
def sender_valid?
|
def sender_valid?
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env, recipient).receive
|
described_class.new(bad_env, recipient).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates the recipient" do
|
it "validates the recipient" do
|
||||||
|
|
@ -51,7 +51,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env, recipient).receive
|
described_class.new(bad_env, recipient).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env, recipient).receive
|
described_class.new(bad_env, recipient).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env, recipient).receive
|
described_class.new(bad_env, recipient).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env).receive
|
described_class.new(bad_env).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with relayable" do
|
context "with relayable" do
|
||||||
|
|
@ -44,7 +44,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env).receive
|
described_class.new(bad_env).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env).receive
|
described_class.new(bad_env).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(bad_env).receive
|
described_class.new(bad_env).receive
|
||||||
}.to raise_error Federation::Receiver::InvalidSender
|
}.to raise_error Federation::Receiver::InvalidSender, "invalid sender: #{sender}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue