futomi / node-lifx-lan

The node-lifx-lan is a Node.js module which allows you to communicate with the Wi-Fi LED smart light products "LIFX" using the LAN protocol.
MIT License
68 stars 33 forks source link

Unwanted network interface used for discovery #7

Closed danielHHHH closed 6 years ago

danielHHHH commented 6 years ago

On the host I'm using node-lifx-lan with, I have two network interfaces. LifxLanAddress.get returns the address for the unwanted network (the network without LIFX devices). This is due to LifxLanAddress.get defaulting to the network interface with the higher netmask/mask_bit_num. In my case, /24 for the unwanted interface and /16 for the wanted interface.

Could logic be added to perform discovery on all found network interfaces? Maybe add an option to restrict to a specific interface?

I added some debugging to the code to illustrate. The 172.25.1.0 network is the unwanted interface, the 10.10.0.0 is the wanted interface.

> require('node-lifx-lan').discover()
lifx-lan-address.js line 52 { network_address: '10.10.0.0/16' }
lifx-lan-address.js line 53 { source_address: '10.10.1.104' }
lifx-lan-address.js line 54 { mask_bit_num_max: 16, mask_bit_num: 16 }
lifx-lan-address.js line 52 { network_address: '172.25.1.0/24' }
lifx-lan-address.js line 53 { source_address: '172.25.1.7' }
lifx-lan-address.js line 54 { mask_bit_num_max: 24, mask_bit_num: 24 }
lifx-lan-address.js line 64 (LifxLanAddress.get return): { source: '172.25.1.7',
  network: '172.25.1.0/24',
  broadcast: '172.25.1.255' }
futomi commented 6 years ago

Thank you so much for your feedback.

As you know, the node-lifx-lan does not work well if more than 2 network interfaces are found in the host for now. But I think that supporting multiple network interfaces is essential.

I'm planning to update the node-lifx-lan to work well even if multiple network interfaces are found. Give me some time.

ristomatti commented 6 years ago

@futomi You might get some ideas on how to fix this from checking how this is implemented on node-lifx. I'm in a bit of a hurry so I just quickly compared the implementations but it seemed node-lifx-lan has quite a complex logic for getting the interface address. node-lifx client seems to just bind to 0.0.0.0 by default.

futomi commented 6 years ago

@ristomatti, Thank you so much for your advice. I have not came up with any idea yet. Your advice is really helpful. I'll try that.

futomi commented 6 years ago

I updated the node-lifx-lan. Now it supports multihomed host. Try the latest version (v.0.2.0).

danielHHHH commented 6 years ago

Thanks, working here!