VintageNet.Connectivity.CheckLogic (vintage_net v0.11.3) View Source

Core logic for determining internet connectivity based on check results

This module is meant to be used by InternetChecker and others for determining when to run checks and how many failures should change the network interface's state.

It implements a state machine that figures out what the connectivity status is based on internet-connectivity check successes and fails. It also returns how long to wait between checks.

stateDiagram-v2
  direction LR
  [*]-->internet : init

  state connected {
    internet-->lan : max failures
    lan-->internet : check succeeded
  }
  connected-->disconnected : ifdown
  disconnected-->lan : ifup

Link to this section Summary

Functions

Call this when an Internet connectivity check fails

Call this when an Internet connectivity check succeeds

Call this when the interface goes down

Call this when the interface comes up

Initialize check state machine

Link to this section Types

Specs

state() :: %{
  connectivity: VintageNet.connection_status(),
  strikes: non_neg_integer(),
  interval: non_neg_integer() | :infinity
}

Link to this section Functions

Specs

check_failed(state()) :: state()

Call this when an Internet connectivity check fails

Depending on how many failures have happened it a row, the connectivity may be degraded to :lan.

Specs

check_succeeded(state()) :: state()

Call this when an Internet connectivity check succeeds

Specs

ifdown(state()) :: state()

Call this when the interface goes down

The interface will be categorized as :disconnected until ifup/1 gets called again.

Specs

ifup(state()) :: state()

Call this when the interface comes up

It is assumed that the interface has LAN connectivity now and a check will be scheduled to happen shortly.

Specs

Initialize check state machine

Pass in the assumed connection status. This is a best guess to start things out.