lib/irrc/irrd/client.rb in irrc-0.1.0 vs lib/irrc/irrd/client.rb in irrc-0.2.0
- old
+ new
@@ -18,13 +18,11 @@
include Irrc::Parameter
include Irrc::Prefix
include Irrc::Runner
include Irrc::Irrd::Api
- attr_reader :host, :queue
-
private
def connect
super
connection.puts persist_command
@@ -33,57 +31,76 @@
def process(query)
set_source query
case query.object_type
when 'as-set'
- resolve_aut_nums_from_as_set query
- resolve_prefixes_from_aut_nums query
+ expand_as_set query
when 'route-set'
- resolve_prefixes_from_route_set query
+ expand_route_set query
when 'aut-num'
- query.add_aut_num_result query.object
- resolve_prefixes_from_aut_nums query
+ expand_aut_num query
end
+
+ query
end
def set_source(query)
command = set_source_command(query.sources)
if execute(command) =~ error_code
- raise "'#{command}' failed on '#{host}' (#{$1})."
+ raise "'#{command}' failed on '#{@fqdn}' (#{$1})."
end
end
- def resolve_aut_nums_from_as_set(query)
- command = expand_set_command(query.object)
- result = execute(command)
- query.add_aut_num_result parse_aut_nums_from_as_set(result)
- rescue
- raise "'#{command}' failed on '#{host}' (#{$!.message})."
+ # Public: Expand an as-set object into aut-nums
+ def expand_as_set(query)
+ result = cache(query.object, query.sources) {
+ begin
+ command = expand_set_command(query.object)
+ execute(command)
+ rescue
+ raise "'#{command}' failed on '#{@fqdn}' (#{$!.message})."
+ end
+ }
+
+ parse_aut_nums_from_as_set(result).each do |autnum|
+ child = query.fork(autnum)
+ query.add_aut_num_result autnum if child.aut_num?
+ end
end
- def resolve_prefixes_from_route_set(query)
- command = expand_set_command(query.object)
- result = execute(command)
+ # Public: Expand a route-set into routes
+ def expand_route_set(query)
+ result = cache(query.object, query.sources) {
+ begin
+ command = expand_set_command(query.object)
+ execute(command)
+ rescue
+ raise "'#{command}' failed on '#{@fqdn}' (#{$!.message})."
+ end
+ }
+
prefixes = classify_by_protocol(parse_prefixes_from_route_set(result))
query.protocols.each do |protocol|
query.add_prefix_result prefixes[protocol], nil, protocol
end
- rescue
- raise "'#{command}' failed on '#{host}' (#{$!.message})."
end
- def resolve_prefixes_from_aut_nums(query)
- unless query.protocols.empty?
- # ipv4 and ipv6 should have the same result so far
- (query.result[:ipv4] || query.result[:ipv6]).keys.each do |autnum|
- command = expand_aut_num_command(autnum)
- result = execute(command)
+ # Public: Expand an aut-num object into routes
+ def expand_aut_num(query)
+ return if query.protocols.empty?
- query.protocols.each do |protocol|
- query.add_prefix_result parse_prefixes_from_aut_num(result, protocol), autnum, protocol
- end
+ result = cache(query.object, query.sources) {
+ begin
+ command = expand_aut_num_command(query.object)
+ execute(command)
+ rescue
+ raise "'#{command}' failed on '#{@fqdn}' (#{$!.message})."
end
+ }
+
+ query.protocols.each do |protocol|
+ query.add_prefix_result parse_prefixes_from_aut_num(result, protocol), query.object, protocol
end
end
end
end
end