Class: OpenASN::TierB

Inherits:
Object
  • Object
show all
Defined in:
lib/openasn/tier_b.rb

Overview

Executes fetch-manifest.json: pulls each enabled Tier B source from its ORIGINAL authority (Apple, the Tor Project, AWS…), parses, merges, and packs it into the local overlay store.

Prime directives (each encodes a production lesson):

* Per-source isolation: one source failing NEVER touches the others
and NEVER raises out of the executor. Failures keep last-good data
("keep_stale") and are recorded in state.json — visible via
OpenASN.dataset_info[:tier_b_status].
* Honor cadence_hours: a 12h source isn't refetched on every deploy's
update run. `force: true` overrides (manual OpenASN.update!(force:)).
* Unknown source ids / parser ids are skipped with a warning — old
gem versions must survive fetch-manifest evolution.
* Every request carries the descriptive User-Agent. These are mostly
free/volunteer endpoints; being a good citizen is part of the deal.

Constant Summary collapse

DEFAULT_DNS_THREADS =
16
MAX_DNS_THREADS =
32
DNS_TIMEOUT_SECONDS =
4

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, http) ⇒ TierB

Returns a new instance of TierB.



36
37
38
39
40
41
# File 'lib/openasn/tier_b.rb', line 36

def initialize(config, http)
  @config = config
  @http = http
  @logger = config.logger
  @store = OverlayStore.new(config.data_dir)
end

Class Attribute Details

.dns_resolverObject

Returns the value of attribute dns_resolver.



30
31
32
# File 'lib/openasn/tier_b.rb', line 30

def dns_resolver
  @dns_resolver
end

Instance Method Details

#execute(force: false) ⇒ Object

-> true when any overlay changed (snapshot reload needed)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/openasn/tier_b.rb', line 44

def execute(force: false)
  manifest = load_manifest
  return false unless manifest

  enabled = @config.enabled_tier_b_source_ids
  changed = false
  (manifest["sources"] || []).each do |source|
    id = source["id"]
    next unless enabled.include?(id)

    unless Parsers.known?(source["parser"])
      @logger.warn("openasn: tier B source #{id} uses unknown parser #{source['parser'].inspect}" \
                   "skipping (update the openasn gem to pick it up)")
      next
    end

    changed |= refresh_source(source, force: force)
  end
  changed
end