Class: BSV::Overlay::HTTPSBroadcastFacilitator

Inherits:
BroadcastFacilitator show all
Defined in:
lib/bsv/overlay/broadcast_facilitator.rb

Overview

Default HTTPS-based broadcast facilitator using Net::HTTP.

POSTs to {url}/submit with a binary BEEF body, Content-Type: application/octet-stream, and an X-Topics header containing the JSON-encoded list of topics for the tagged BEEF.

HTTPS is enforced by default; pass allow_http: true to permit plain HTTP (useful for local development and testing).

An injectable http_client may be supplied for testing. It must respond to #request(uri, net_http_request) and return an object with #code and #body.

Constant Summary collapse

DEFAULT_TIMEOUT =
30

Instance Method Summary collapse

Constructor Details

#initialize(allow_http: false, http_client: nil, timeout: DEFAULT_TIMEOUT) ⇒ HTTPSBroadcastFacilitator

Returns a new instance of HTTPSBroadcastFacilitator.

Parameters:

  • allow_http (Boolean) (defaults to: false)

    permit non-HTTPS URLs (default: false)

  • http_client (#request, nil) (defaults to: nil)

    injectable HTTP client for testing

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    request timeout in seconds (default: 30)



46
47
48
49
50
51
# File 'lib/bsv/overlay/broadcast_facilitator.rb', line 46

def initialize(allow_http: false, http_client: nil, timeout: DEFAULT_TIMEOUT)
  super()
  @allow_http  = allow_http
  @http_client = http_client
  @timeout     = timeout
end

Instance Method Details

#send_beef(url, tagged_beef) ⇒ Hash{String => AdmittanceInstructions}?

Send a tagged BEEF to {url}/submit and return the parsed STEAK hash.

Parameters:

  • url (String)

    base URL of the Overlay Services host

  • tagged_beef (TaggedBEEF)

    the tagged BEEF to broadcast

Returns:

  • (Hash{String => AdmittanceInstructions}, nil)

    parsed STEAK response, or nil if the host returned an error or the response could not be parsed

Raises:

  • (ArgumentError)

    if the URL is not HTTPS and allow_http is false



61
62
63
64
65
66
67
68
69
# File 'lib/bsv/overlay/broadcast_facilitator.rb', line 61

def send_beef(url, tagged_beef)
  validate_url!(url)

  uri     = URI("#{url.chomp('/')}/submit")
  request = build_request(uri, tagged_beef)
  response = execute(uri, request)

  parse_steak(response)
end