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

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

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

Types

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

Functions

@spec 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.

@spec check_succeeded(state()) :: state()

Call this when an Internet connectivity check succeeds

@spec ifdown(state()) :: state()

Call this when the interface goes down

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

@spec 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.

@spec init(VintageNet.connection_status()) :: state()

Initialize check state machine

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