Module: DiasporaFederation::Entities::Relayable
- Includes:
- Logging
- Included in:
- Comment, Like, Message, Participation, PollParticipation
- Defined in:
- lib/diaspora_federation/entities/relayable.rb
Overview
This is a module that defines common properties for relayable entities which include Like, Comment, Participation, Message, etc. Each relayable has a parent, identified by guid. Relayables are also signed and signing/verification logic is embedded into Salmon XML processing code.
Defined Under Namespace
Modules: ParseXML Classes: AuthorPrivateKeyNotFound, PublicKeyNotFound, SignatureVerificationFailed
Constant Summary collapse
- DIGEST =
Digest instance used for signing
OpenSSL::Digest::SHA256.new
Instance Attribute Summary collapse
-
#additional_xml_elements ⇒ Hash
readonly
Additional properties from parsed xml.
-
#author ⇒ String
readonly
The diaspora* ID of the author.
-
#author_signature ⇒ String
readonly
Contains a signature of the entity using the private key of the author of a post itself The presence of this signature is mandatory.
-
#guid ⇒ String
readonly
A random string of at least 16 chars.
-
#parent ⇒ RelatedEntity
readonly
Meta information about the parent object.
-
#parent_author_signature ⇒ String
readonly
Contains a signature of the entity using the private key of the author of a parent post This signature is required only when federating from upstream (parent) post author to downstream subscribers.
-
#parent_guid ⇒ String
readonly
Parent guid.
-
#xml_order ⇒ Array
readonly
Order from the parsed xml for signature.
Class Method Summary collapse
-
.included(klass) ⇒ Object
On inclusion of this module the required properties for a relayable are added to the object that includes it.
Instance Method Summary collapse
-
#initialize(data, xml_order = nil, additional_xml_elements = {}) ⇒ Object
Initializes a new relayable Entity with order and additional xml elements.
- #sender_valid?(sender) ⇒ Boolean
-
#to_s ⇒ String
String representation of this object.
-
#verify_signatures ⇒ Object
Verifies the signatures (
author_signature
andparent_author_signature
if needed).
Instance Attribute Details
#additional_xml_elements ⇒ Hash (readonly)
Additional properties from parsed xml
19 20 21 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 19 def additional_xml_elements @additional_xml_elements end |
#author ⇒ String (readonly)
The diaspora* ID of the author
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#author_signature ⇒ String (readonly)
Contains a signature of the entity using the private key of the author of a post itself The presence of this signature is mandatory. Without it the entity won’t be accepted by a target pod.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#guid ⇒ String (readonly)
A random string of at least 16 chars
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#parent ⇒ RelatedEntity (readonly)
Meta information about the parent object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#parent_author_signature ⇒ String (readonly)
Contains a signature of the entity using the private key of the author of a parent post This signature is required only when federating from upstream (parent) post author to downstream subscribers. This is the case when the parent author has to resend a relayable received from one of their subscribers to all others.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#parent_guid ⇒ String (readonly)
Returns parent guid.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
#xml_order ⇒ Array (readonly)
Order from the parsed xml for signature
15 16 17 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 15 def xml_order @xml_order end |
Class Method Details
.included(klass) ⇒ Object
On inclusion of this module the required properties for a relayable are added to the object that includes it.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 55 def self.included(klass) klass.class_eval do property :author, xml_name: :diaspora_handle property :guid property :parent_guid property :author_signature, default: nil property :parent_author_signature, default: nil entity :parent, Entities::RelatedEntity end klass.extend ParseXML end |
Instance Method Details
#initialize(data, xml_order = nil, additional_xml_elements = {}) ⇒ Object
Initializes a new relayable Entity with order and additional xml elements
74 75 76 77 78 79 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 74 def initialize(data, xml_order=nil, additional_xml_elements={}) @xml_order = xml_order.try(:reject) {|name| name =~ /signature/ } @additional_xml_elements = additional_xml_elements super(data) end |
#sender_valid?(sender) ⇒ Boolean
90 91 92 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 90 def sender_valid?(sender) sender == || sender == parent. end |
#to_s ⇒ String
Returns string representation of this object.
95 96 97 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 95 def to_s "#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}" end |
#verify_signatures ⇒ Object
Verifies the signatures (author_signature
and parent_author_signature
if needed).
83 84 85 86 87 88 |
# File 'lib/diaspora_federation/entities/relayable.rb', line 83 def verify_signatures verify_signature(, :author_signature) # This happens only on downstream federation. verify_signature(parent., :parent_author_signature) unless parent.local end |