nerves-project-attic/nerves_network

Ideal api for usage

Closed this issue · 5 comments

This is an issue to discuss the general usage API of nerves_network and what it should look like relative to what it is currently.

So i think there are a few levels to this issue. Id like to address and discuss them here.

Working with WPA Supplicant

Right now when you call Nerves.Network.setup("wlan0", [some: :settings]) it just get passed pretty much untouched to Nerves.WpaSupplicant Ideally these settings would be verified somewhere. Nerves.Network kind of knows too much about what goes on inside Nerves.WpaSupplicant. This probably warrants an issue on that repository, but ideally
We should use something like SystemRegistry to interact with WpaSupplicant. This will save situations where an event is missed or ignored.

Lose API spec.

Even after typespecing the API, it is still too lose. You can pass pretty much any ole data into the setup/2 function and things may or may not happen the way you want them. I think we need a comprehensive list of all available settings for things like:

  • ip addressing for static and dhcp.
  • wpa_supplicant
  • subscription to events (see below)

The big SystemRegistry discussion.

Right now Nerves.Network pretty much just wraps Nerves.WpaSupplicant and Nerves.NetworkInterface. Unfortunately those libs haven't been updated to use SystemRegistry, so as an end user trying to use this lib, one has to not only subscribe to SystemRegistry, but use Elixir.Registry to subscribe to the above two projects. Ideally their state would also be in SystemRegistry. Now another discussion related to using SystemRegistry is if we should force the end user to use SystemRegistry. I think it would be nicer to have a first class registration system for just Nerves.Network events so users don't have to watch three different state trees inside SystemRegistry. This would obviously be the most work to implement but i think would give the best user experience. IE something like this for the end user.

def handle_info({:nerves_network, _iface, {:udhcpc, {:bound, ip}}, state)
def handle_info({:nerves_network, _iface, {:wpa_supplicant, {:network_disconnect}}}, state)

Other notes

I would really like an api for blocking until internet (or an ip address) is confirmed, or some variant of wait_for_event(iface, pattern) that you could just put into Shoehorn. This would make initial bring up of a Nerves project way easier in my opinion.

Please anyone feel free to chime in on things you want/don't want.

While thinking about how the api should be structured i think these issues are important to keep in mind:
#72 - Multiple access points for wireless interfaces
#35 - Teardown not really doing anything
#62 - Setting up a non existent interface doesn't raise an error. (do we even want it too?)

For #62, you'll need to handle this somehow since interfaces come up asynchronously. It may look like they always exist, but there's a period of time at startup where the USB bus is enumerated, wifi drivers loaded, wifi firmware initialized, etc. and then they show up. It's also important for devices that power down their USB Wifi Dongles to save power when not in use or reset them if WiFi is wonky. I've had to do the latter on shipped devices to work around WiFi driver/firmware images that couldn't be resolved in time.

Ah that last part is a use case i hadn't really considered. Good to know about.

Closing due to lack of discussion.
#72 and #35 have been fixed and the API for setup has been pretty well normalized since May.