Class: Irrc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/irrc/client.rb

Overview

Public: IRR / Whois client to manage child client workers and queues.

Instance Method Summary collapse

Constructor Details

#initialize(threads = 1, &block) ⇒ Client

Public: Create a new IRR / Whois client worker manager.

You can customize the logger by specifying a block.
The default logger is STDERR printer of more severe messages than INFO.

threads - Number of threads to resolve prefixes per IRR / Whois server. (default: 1) block - An optional block that can be used to customize the logger.

Examples

Irrc::Client.new(2) {|c|
  c.logger = Logger.new('irrc.log')
}

22
23
24
25
# File 'lib/irrc/client.rb', line 22

def initialize(threads=1, &block)
  @thread_limit = threads.to_i
  @block = block
end

Instance Method Details

#performObject

Public: Run the query threads.

Returns Decorated result Hash. See an example below:

{"as-jpnic"=>                 # IRR object to query
  {:ipv4=>                    # protocol
    {"AS2515"=>               # origin aut-num object
      ["202.12.30.0/24",      # prefixes
       "192.41.192.0/24",     #
       "211.120.240.0/21",    #
       "211.120.248.0/24"]},  #
   :ipv6=>
     {"AS2515"=>
       ["2001:dc2::/32",
        "2001:0fa0::/32",
        "2001:DC2::/32"]}}}

85
86
87
# File 'lib/irrc/client.rb', line 85

def perform
  decorate(run)
end

#query(host, objects, options = {}) ⇒ Object

Public: Enqueue an IRR / Whois query.

host - FQDN of IRR / Whois server. IRR name is also acceptable. (eg: jpirr) objects - IRR objects to extract. (eg: as-set, route-set, aut-num object)

Array form is also acceptable for multiple objects.

options - The Hash options to pass to IRR. (default: [:ipv4, :ipv6])

:source   - Specify authoritative IRR source names.
            If not given, any source will be accepted. (optional)
:protocol - :ipv4, :ipv6 or [:ipv4, :ipv6]
            A String or Symbol of protcol name is acceptable. (optional)

Examples

client.query :jpirr, 'AS-JPNIC', source: :jpirr, protocol: :ipv4
client.query :jpirr, 'AS-JPNIC', source: [:jpirr, :radb]

Raises:

  • (ArgumentError)

42
43
44
45
46
47
48
49
# File 'lib/irrc/client.rb', line 42

def query(host, objects, options={})
  raise ArgumentError, 'host is required.' unless host
  fqdn = Irrc::Irr.host(host) || host

  Array(objects).map {|object|
    queue(fqdn) << Irrc::Query.new(object, options)
  }
end

#runObject

Public: Run the query threads.

Returns Raw level Array of Queries.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/irrc/client.rb', line 54

def run
  done = []

  queues.each_with_object([]) {|(fqdn, queue), workers|
    @thread_limit.times.map.with_index {|i|
      workers << Thread.start {
        Thread.current[:id] = i+1
        done.push *worker_class(fqdn).new(fqdn, queue(fqdn), cache(fqdn), &@block).run(@thread_limit)
      }
    }
  }.each {|t| t.join }

  done
end