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)



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

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



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

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

.json_headersObject



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

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

.xml_headersObject



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

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



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

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



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

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



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

def send
  hydra.run
  @urls_to_retry
end