Class: OpenASN::Configuration

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

Constant Summary collapse

TIER_B_DEFAULTS =
{
  apple_relay: true,
  tor: true,
  clouds: true,
  zscaler: false,       # ASN-level enterprise_gateway overrides already cover Zscaler
  vpn_providers: true,
  vpn_heavy: false,     # e.g. NordVPN's ~35MB API response; opt in deliberately
  vpn_dns: false,       # provider-published hostnames resolved by local DNS; opt in deliberately
  public_relays: false, # volunteer relays like VPN Gate; useful, but high-churn
  nazgul_mixed: false   # semantics broader than VPN; opt-in only
}.freeze
TIER_B_SOURCE_MAP =

Feature switch → fetch-manifest source ids.

{
  apple_relay: %w[apple_private_relay],
  tor: %w[tor_exits],
  clouds: %w[aws gcp azure oracle digitalocean linode vultr cloudflare_ranges],
  zscaler: %w[zscaler],
  vpn_providers: %w[protonvpn mullvad_relays ivpn_servers pia_servers airvpn_status windscribe_servers
                    privadovpn riseup_vpn wlvpn_server_list worldvpn_servers ovpn_status_servers
                    anonine_status],
  vpn_heavy: %w[nordvpn_servers],
  vpn_dns: %w[surfshark_generic surfshark_static surfshark_obfuscated ipvanish_openvpn
              privatevpn_openvpn purevpn_openvpn torguard_openvpn_tcp torguard_openvpn_udp
              fastestvpn_tcp fastestvpn_udp vpnsecure_locations tunnelbear_openvpn strongvpn_locations
              vyprvpn_openvpn giganews_vyprvpn_hosts slickvpn_locations azirevpn_locations
              vpnac_status trustzone_servers],
  public_relays: %w[vpngate vpnbook_openvpn freevpn_us_servers],
  nazgul_mixed: %w[nazgul_mixed]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/openasn/configuration.rb', line 103

def initialize
  @data_dir = nil
  @memory_mode = :packed
  @auto_update = true
  @release_url = nil
  @tier_b = TIER_B_DEFAULTS.dup
  @pin_version = nil
  @trusted_header = nil
  @logger = nil
  @api_key = nil
end

Instance Attribute Details

#api_keyObject

Reserved for future OpenASN Pro editions. Deliberately inert in the open gem — configuring it does nothing today and never will for the free dataset (see the data repo's open-data contract).

Tier C BYOD adapters (bring-your-own MaxMind/IP2Location databases) are post-MVP and deliberately ship NO placeholder keys here: new config keys are additive and non-breaking to introduce later, whereas a placeholder whose shape turns out wrong would force a breaking rename. They'll appear alongside the adapters themselves.



70
71
72
# File 'lib/openasn/configuration.rb', line 70

def api_key
  @api_key
end

#auto_updateObject

Whether UpdateJob/boot staleness checks may refresh data automatically.



25
26
27
# File 'lib/openasn/configuration.rb', line 25

def auto_update
  @auto_update
end

#data_dirObject



115
116
117
118
119
120
121
# File 'lib/openasn/configuration.rb', line 115

def data_dir
  @data_dir ||= if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
                  File.join(Rails.root.to_s, "storage", "openasn")
                else
                  File.join(Dir.tmpdir, "openasn")
                end
end

#loggerObject



147
148
149
150
151
152
153
# File 'lib/openasn/configuration.rb', line 147

def logger
  @logger ||= if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
                Rails.logger
              else
                Logger.new($stdout, level: Logger::INFO, progname: "openasn")
              end
end

#memory_modeObject

Measured on the real dataset, full classify (parse + all layers): :packed → ~11MB data resident; ~15µs/lookup on Apple Silicon, ~24µs on GitHub's shared CI runners (default; right for web apps) :arrays → several× the memory; ~9µs/lookup (~1.6x faster — the raw range probe is ~2µs, but IP parsing + overlay checks dominate, so the full-lookup win is smaller than that suggests). For lookup-heavy batch pipelines.



22
23
24
# File 'lib/openasn/configuration.rb', line 22

def memory_mode
  @memory_mode
end

#pin_versionObject

Pin data to a dated release tag (e.g. "v2026.07.05") instead of the rolling latest. For reproducible environments and gradual rollouts.



53
54
55
# File 'lib/openasn/configuration.rb', line 53

def pin_version
  @pin_version
end

#release_urlObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/openasn/configuration.rb', line 129

def release_url
  return @release_url if @release_url
  return "https://github.com/openasn/openasn/releases/download/#{pin_version}/" if pin_version

  # Tag-addressed form: the rolling release's TAG is literally "latest",
  # so this path stays pinned to it no matter which release holds
  # GitHub's "Latest" BADGE. The superficially equivalent
  # `releases/latest/download/...` resolves via that badge (whatever
  # release was created last - REST `make_latest` defaults to "true"),
  # and the first weekly dated snapshot stole it once (2026-07-05):
  # default-config clients would have silently fetched up-to-6-day-old
  # data until the next snapshot. Do not "simplify" this back.
  # Refs: https://docs.github.com/en/repositories/releasing-projects-on-github/linking-to-releases
  #       https://docs.github.com/en/rest/releases/releases#create-a-release
  #       data repo DECISIONS.md D-REL-1
  "https://github.com/openasn/openasn/releases/download/latest/"
end

#tier_bObject

Per-source Tier B switches (see fetch-manifest.json in the data repo). Keys are FEATURE names, not source ids — they fan out:

apple_relay    → apple_private_relay        (:relay)
tor            → tor_exits                  (:tor_exit)
clouds         → aws gcp azure oracle digitalocean linode vultr
               + cloudflare_ranges context flag
vpn_providers  → protonvpn mullvad ivpn pia airvpn windscribe
               privado riseup wlvpn worldvpn ovpn
               anonine
               (exact provider-attributed VPN exit/server IPs)
vpn_heavy      → nordvpn                    (large/fragile provider API)
vpn_dns        → surfshark ipvanish privatevpn purevpn torguard fastestvpn vpnsecure
               tunnelbear strongvpn vyprvpn giganews slickvpn
               azirevpn vpn.ac trust.zone
               (provider hostnames resolved locally; opt-in)
public_relays  → vpngate vpnbook freevpn.us (volunteer/free public VPN relays)
zscaler        → zscaler                    (:enterprise_gateway ranges)
nazgul_mixed   → nazgul_mixed               (flag only, never :vpn)


49
50
51
# File 'lib/openasn/configuration.rb', line 49

def tier_b
  @tier_b
end

#trusted_headerObject

Reserved for the post-MVP edge companion (a CDN worker that stamps a trusted classification header). No behavior in this version.



57
58
59
# File 'lib/openasn/configuration.rb', line 57

def trusted_header
  @trusted_header
end

Instance Method Details

#enabled_tier_b_source_idsObject



155
156
157
# File 'lib/openasn/configuration.rb', line 155

def enabled_tier_b_source_ids
  tier_b.flat_map { |feature, on| on ? TIER_B_SOURCE_MAP.fetch(feature, []) : [] }
end

#user_agentObject



159
160
161
# File 'lib/openasn/configuration.rb', line 159

def user_agent
  "openasn-ruby/#{VERSION} (+https://github.com/openasn/openasn)"
end