PeerNet.NetworkMonitor.Polling (PeerNet v0.1.0)

Copy Markdown View Source

Default PeerNet.NetworkMonitor implementation. Polls :inet.getifaddrs/0 on a configurable interval (default 5 seconds) and notifies subscribers when the local IP set changes.

What's filtered out

  • Loopback (127.0.0.0/8, ::1) — never useful to peers.
  • 0.0.0.0, 255.255.255.255 — degenerate.
  • Interfaces in :down state — Erlang reports them, peers can't use them.

Probing

The probe function is injectable via the :probe option for testability. The default reads :inet.getifaddrs/0 and projects out a flat list of usable IPs.

Polling.start_link(
  probe: fn -> [{192, 168, 1, 50}] end,
  poll_interval_ms: 100
)

Subscribers

Subscribers can come and go. The polling process monitors each one and drops it from the dispatch list on :DOWN, so a subscriber crashing doesn't accumulate dead pids in state.

Summary

Functions

Returns a specification to start this module under a supervisor.

Default IP probe — reads :inet.getifaddrs/0 and returns a flat list of usable, non-loopback IPv4/IPv6 addresses on up interfaces.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

default_probe()

@spec default_probe() :: [PeerNet.NetworkMonitor.ip()]

Default IP probe — reads :inet.getifaddrs/0 and returns a flat list of usable, non-loopback IPv4/IPv6 addresses on up interfaces.

Public so tests and alternate impls can call it directly.