Skip to content

Commit

Permalink
Poll network status from SystemRegistry
Browse files Browse the repository at this point in the history
This fixes an issue where you'd only get back a subset of the interface
state when calling Nerves.Network.status/1 and most importantly it
now tells you the IP address.

This also removes the direct status call to Nerves.Network.Interface,
since it would be good to remove that eventually.

This fixes #18.
  • Loading branch information
fhunleth committed Aug 15, 2017
1 parent 36fbed6 commit 5bb84bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/nerves_network.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ defmodule Nerves.Network do
end

@doc """
Return a map with the current configuration and interface status.
Convenience function for returning the current status of a network interface
from SystemRegistry.
"""
def status(ifname) do
Nerves.Network.IFSupervisor.status ifname
SystemRegistry.match(:_)
|> get_in([:state, :network_interface, ifname])
end

@doc """
Expand Down
9 changes: 0 additions & 9 deletions lib/nerves_network/if_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ defmodule Nerves.Network.IFSupervisor do
end
end

def status(ifname) do
pidname = pname(ifname)
if Process.whereis(pidname) do
Nerves.NetworkInterface.status(ifname)
else
{:error, :not_started}
end
end

defp pname(ifname) do
String.to_atom("Nerves.Network.Interface." <> ifname)
end
Expand Down

0 comments on commit 5bb84bb

Please sign in to comment.