Ravn::BDE::
Beacon
module
A network broadcaster that sends messages about the state of the BDE
.
Return a multicast socket suitable for sending beacon messages.
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
Clear any pre-existing socket.
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
.
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.
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