diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mauve/processor.rb | 2 | ||||
-rw-r--r-- | lib/mauve/sender.rb | 39 |
2 files changed, 26 insertions, 15 deletions
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index 86aaaec..9a5c84b 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -48,7 +48,7 @@ module Mauve update.parse_from_string(data) if @transmission_id_cache[update.transmission_id.to_s] - @logger.debug("Ignoring duplicate transmission id #{data.transmission_id}") + @logger.debug("Ignoring duplicate transmission id #{update.transmission_id}") # # Continue with next packet. # diff --git a/lib/mauve/sender.rb b/lib/mauve/sender.rb index 6abe44d..0a481d5 100644 --- a/lib/mauve/sender.rb +++ b/lib/mauve/sender.rb @@ -70,21 +70,20 @@ module Mauve list.each do |d,p| r = [] + # + # Try IPv6 first. + # + dns.getresources(d, AAAA).map do |a| + r << [a.address.to_s, p] + end # - # Try IPv4 first. + # Try IPv4 too. # dns.getresources(d, A).each do |a| r << [a.address.to_s, p] end - # - # Try IPv6 too. - # - dns.getresources(d, AAAA).map do |a| - r << [a.address.to_s, p] - end - results += r unless r.empty? end end @@ -102,7 +101,10 @@ module Mauve end end - + + # + # Returns the number of packets sent. + # def send(update, verbose=0) # @@ -131,15 +133,24 @@ module Mauve print "Sending #{update.inspect.chomp} to #{@destinations.join(", ")}\n" end + # + # Keep a count of the number of alerts sent. + # + sent = 0 + @destinations.each do |ip, port| begin - UDPSocket.open(ip.family) do |sock| - sock.send(data, 0, ip.to_s, port) - end - rescue StandardError => ex - warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}" + UDPSocket.open(ip.family).send(data, 0, ip.to_s, port) + sent += 1 + rescue Errno::ENETUNREACH => ex + # Catch and ignore unreachable network errors. + warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}" if verbose > 0 end end + + raise "Failed to send any packets to any destinations!" unless sent > 0 + + sent end end end |