Class: LIFX::TransportManager::LAN Private
- Defined in:
- lib/lifx/transport_manager/lan.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DISCOVERY_INTERVAL_WHEN_NO_SITES_FOUND =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
seconds
1- DISCOVERY_INTERVAL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
seconds
15
Instance Method Summary collapse
- #broadcast(message) ⇒ Object private
- #broadcast_to_peers(message) ⇒ Object private
- #discover ⇒ Object private
- #flush(**options) ⇒ Object private
- #gateways ⇒ Object private
-
#initialize(bind_ip: '0.0.0.0', send_ip: '255.255.255.255', port: 56700, peer_port: 56750) ⇒ LAN
constructor
private
A new instance of LAN.
- #on_network? ⇒ Boolean private
- #sites ⇒ Object private
- #stop ⇒ Object private
- #stop_discovery ⇒ Object private
- #write(message) ⇒ Object private
Constructor Details
#initialize(bind_ip: '0.0.0.0', send_ip: '255.255.255.255', port: 56700, peer_port: 56750) ⇒ LAN
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of LAN.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/lifx/transport_manager/lan.rb', line 6 def initialize(bind_ip: '0.0.0.0', send_ip: '255.255.255.255', port: 56700, peer_port: 56750) super @bind_ip = bind_ip @send_ip = send_ip @port = port @peer_port = peer_port @sites = {} initialize_transports end |
Instance Method Details
#broadcast(message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 80 81 82 |
# File 'lib/lifx/transport_manager/lan.rb', line 77 def broadcast() if !@transport.connected? create_broadcast_transport end @transport.write() end |
#broadcast_to_peers(message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 88 89 |
# File 'lib/lifx/transport_manager/lan.rb', line 84 def broadcast_to_peers() if !@peer_transport.connected? create_peer_transport end @peer_transport.write() end |
#discover ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lifx/transport_manager/lan.rb', line 27 def discover stop_discovery Thread.abort_on_exception = true @discovery_thread = Thread.new do @last_request_seen = Time.at(0) = Message.new(path: ProtocolPath.new(tagged: true), payload: Protocol::Device::GetPanGateway.new) logger.info("Discovering gateways on #{@bind_ip}:#{@port}") loop do interval = @sites.empty? ? DISCOVERY_INTERVAL_WHEN_NO_SITES_FOUND : DISCOVERY_INTERVAL if Time.now - @last_request_seen > interval write() end sleep(interval / 2.0) end end end |
#flush(**options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 22 23 |
# File 'lib/lifx/transport_manager/lan.rb', line 17 def flush(**) @sites.values.map do |site| Thread.new do site.flush(**) end end.each(&:join) end |
#gateways ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/lifx/transport_manager/lan.rb', line 95 def gateways @sites.values.map(&:gateways) end |
#on_network? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/lifx/transport_manager/lan.rb', line 73 def on_network? Socket.getifaddrs.any? { |ifaddr| ifaddr.broadaddr } end |
#sites ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'lib/lifx/transport_manager/lan.rb', line 91 def sites @sites.dup end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 56 |
# File 'lib/lifx/transport_manager/lan.rb', line 50 def stop stop_discovery @transport.close @sites.values.each do |site| site.stop end end |
#stop_discovery ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/lifx/transport_manager/lan.rb', line 46 def stop_discovery Thread.kill(@discovery_thread) if @discovery_thread end |
#write(message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lifx/transport_manager/lan.rb', line 58 def write() return unless on_network? if .path.all_sites? broadcast() else site = @sites[.path.site_id] if site site.write() else broadcast() end end broadcast_to_peers() end |