Ravn::BDE::

Beacon module

A network broadcaster that sends messages about the state of the BDE.

Public Instance Methods

multicast_socket()

Return a multicast socket suitable for sending beacon messages.

# File lib/ravn/bde/beacon.rb, line 55
def multicast_socket
        @multicast_socket ||= begin
                sock = UDPSocket.open
                sock.setsockopt( :IPPROTO_IP, :IP_MULTICAST_TTL, self.multicast_ttl )
                sock
        end

        return @multicast_socket
end
reset()

Clear any pre-existing socket.

# File lib/ravn/bde/beacon.rb, line 67
def reset
        @multicast_socket.close if @multicast_socket
        @multicast_socket = nil
end
send_exception( exception, type:, **other )

Send a beacon message built from the given exception.

# File lib/ravn/bde/beacon.rb, line 85
def send_exception( exception, type:, **other )
        self.log.debug "Sending a %p exception beacon message (%s): %p" %
                [ exception.class, type, other ]

        info = other.merge(
                error: "%p: %s" % [ exception.class, exception.message ],
                type: type,
        )

        self.send_message( type: type, **info )
end
send_message( type:, **info )

Send a beacon message when the BDE starts up.

# File lib/ravn/bde/beacon.rb, line 74
def send_message( type:, **info )
        if Ravn::BDE::Beacon.enabled?
                self.log.debug "Sending a %s beacon message to %s:%d" %
                        [ type, self.multicast_address.to_s, self.multicast_port ]
                encoded = MessagePack.pack( info.merge(type: type, callsign: Ravn::BDE.callsign) )
                self.multicast_socket.send( encoded, 0, self.multicast_address.to_s, self.multicast_port )
        end
end