Class: DiasporaFederation::Federation::Sender::HydraWrapper

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/diaspora_federation/federation/sender/hydra_wrapper.rb

Overview

A wrapper for [Typhoeus::Hydra]

Uses parallel http requests to send out the salmon-messages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(sender_id, obj_str) ⇒ HydraWrapper

Create a new instance for a message

Parameters:

  • sender_id (String)

    sender diaspora-ID

  • obj_str (String)

    object string representation for logging (e.g. type@guid)



45
46
47
48
49
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 45

def initialize(sender_id, obj_str)
  @sender_id = sender_id
  @obj_str = obj_str
  @urls_to_retry = []
end

Class Method Details

.hydra_optsHash

Hydra default opts

Returns:

  • (Hash)

    hydra opts



16
17
18
19
20
21
22
23
24
25
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 16

def self.hydra_opts
  @hydra_opts ||= {
    followlocation: false,
    timeout:        DiasporaFederation.http_timeout,
    method:         :post,
    verbose:        DiasporaFederation.http_verbose,
    cainfo:         DiasporaFederation.certificate_authorities,
    forbid_reuse:   true
  }
end

.json_headersObject



34
35
36
37
38
39
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 34

def self.json_headers
  @json_headers ||= {
    "Content-Type" => "application/json",
    "User-Agent"   => DiasporaFederation.http_user_agent
  }
end

.xml_headersObject



27
28
29
30
31
32
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 27

def self.xml_headers
  @xml_headers ||= {
    "Content-Type" => "application/magic-envelope+xml",
    "User-Agent"   => DiasporaFederation.http_user_agent
  }
end

Instance Method Details

#insert_enc_magic_env_request(url, json) ⇒ Object

Prepares and inserts a private encrypted MagicEnvelope job into the hydra queue

Parameters:

  • url (String)

    the receive-url for the message

  • json (String)

    encrypted MagicEnvelope json



61
62
63
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 61

def insert_enc_magic_env_request(url, json)
  insert_job(url, HydraWrapper.hydra_opts.merge(body: json, headers: HydraWrapper.json_headers))
end

#insert_magic_env_request(url, xml) ⇒ Object

Prepares and inserts a public MagicEnvelope job into the hydra queue

Parameters:

  • url (String)

    the receive-url for the xml

  • xml (String)

    MagicEnvelope xml



54
55
56
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 54

def insert_magic_env_request(url, xml)
  insert_job(url, HydraWrapper.hydra_opts.merge(body: xml, headers: HydraWrapper.xml_headers))
end

#sendArray<String>

Sends all queued messages

Returns:

  • (Array<String>)

    urls to retry



67
68
69
70
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 67

def send
  hydra.run
  @urls_to_retry
end