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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#additional_xml_elementsHash (readonly)

Additional properties from parsed xml

Returns:

  • (Hash)

    additional xml elements



19
20
21
# File 'lib/diaspora_federation/entities/relayable.rb', line 19

def additional_xml_elements
  @additional_xml_elements
end

#authorString (readonly)

The diaspora* ID of the author

Returns:

  • (String)

    diaspora* ID

See Also:



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_signatureString (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.

Returns:

  • (String)

    author signature



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

#guidString (readonly)

A random string of at least 16 chars

Returns:

  • (String)

    comment guid

See Also:



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

#parentRelatedEntity (readonly)

Meta information about the parent object

Returns:



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_signatureString (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.

Returns:

  • (String)

    parent author signature



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_guidString (readonly)

Returns parent guid.

Returns:

  • (String)

    parent guid

See Also:



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_orderArray (readonly)

Order from the parsed xml for signature

Returns:

  • (Array)

    order from xml



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.

Parameters:

  • klass (Entity)

    the entity in which it is included



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

Parameters:

  • data (Hash)

    entity data

  • xml_order (Array) (defaults to: nil)

    order from xml

  • additional_xml_elements (Hash) (defaults to: {})

    additional xml elements

See Also:



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

Returns:

  • (Boolean)


90
91
92
# File 'lib/diaspora_federation/entities/relayable.rb', line 90

def sender_valid?(sender)
  sender == author || sender == parent.author
end

#to_sString

Returns string representation of this object.

Returns:

  • (String)

    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_signaturesObject

Verifies the signatures (author_signature and parent_author_signature if needed).

Raises:



83
84
85
86
87
88
# File 'lib/diaspora_federation/entities/relayable.rb', line 83

def verify_signatures
  verify_signature(author, :author_signature)

  # This happens only on downstream federation.
  verify_signature(parent.author, :parent_author_signature) unless parent.local
end