iptoasn 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/iptoasn/iptoasn.rb +10 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d832e981a75509b4b3d425c946c9acf45b8805bef9efa92d1261ec1331203f71
4
- data.tar.gz: 455040daee6e754da6ffbb49cc53577bb5a5a8bb95b01e099ee14086dc322212
3
+ metadata.gz: a30920b9c52f4805314a9d3572f8a3a8b5152b9d8f9b610172e9e8a78b40b31b
4
+ data.tar.gz: 448626dfaa1ff8c0ca1d20f23a4389ec6596c4e7a0b1e692b427a4f0477acf66
5
5
  SHA512:
6
- metadata.gz: a02163999424c204244d864e311faba72e523f0ba07a30b60a726cc3f88cd35c6e9a82bccd37634a42cb91b7f9568ef1cb7c3104799bed92b869e588a8941956
7
- data.tar.gz: 9b7f3740a6a3e51b1f4f04c21f07dbfbe70210c36199ef6f217408563a6f1b7073bb280214da67d60c717d97f8ba5274c71c29cde0682d88f49d71f3aeb77f98
6
+ metadata.gz: 7708e778a762e03e6e0fa774a029a69c242389e7a945811d97aafcfa0026bb7e66772341a96abdc7897daff622d9bd638126446e956c428621bccc15b8310f48
7
+ data.tar.gz: 9d10f6ed471ae834ef7f529784c9a36f641528e8fa1a2da8a40684208c477267ff29a7b5d075dd8491c1b95d55774fb97365e260889a6c1f282c6d9953e60575
@@ -3,9 +3,12 @@
3
3
  module IpToAsn
4
4
  class Lookup
5
5
  def initialize(db_ip2asn: nil, db_country: nil, db_names: nil) # rubocop:disable Metrics/AbcSize
6
- db_ip2asn ||= File.expand_path('../../data/ip2asn.dat', __dir__)
7
- db_country ||= File.expand_path('../../data/countries.dat', __dir__)
8
- db_names ||= File.expand_path('../../data/asnames.dat', __dir__)
6
+ if db_ip2asn.nil? || db_country.nil? || db_names.nil?
7
+ require 'iptoasn/data'
8
+ db_ip2asn = IpToAsn::Data.ip2asn
9
+ db_country = IpToAsn::Data.countries
10
+ db_names = IpToAsn::Data.asnames
11
+ end
9
12
 
10
13
  @db_ip2asn = File.open(db_ip2asn, 'r')
11
14
  @db_country = File.read(db_country)
@@ -24,6 +27,7 @@ module IpToAsn
24
27
  @db_ip2asn.seek(0, IO::SEEK_END)
25
28
  @db_total_entries = @db_ip2asn.size / @entry_size
26
29
  @db_ip2asn.seek(0)
30
+ @mutex = Mutex.new
27
31
  end
28
32
 
29
33
  def ip_to_int(ip)
@@ -47,7 +51,9 @@ module IpToAsn
47
51
 
48
52
  return { as_number: 0, country_code: 'XX', as_name: reserved_range_name } unless reserved_range_name.nil?
49
53
 
50
- search_db(ip)
54
+ @mutex.synchronize do
55
+ search_db(ip)
56
+ end
51
57
  end
52
58
 
53
59
  def search_db(ip) # rubocop:disable Metrics/AbcSize
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iptoasn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OMAR
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-06 00:00:00.000000000 Z
11
+ date: 2025-02-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem wraps the IP to ASN dataset. It uses lazy loading so it doesn't
14
14
  load the entire ~25M dataset all at once.