netevents

package
v0.78.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package netevents owns the OS network event handling shared by the mobile bindings: availability changes park or wake the reconnection loops and drive the NoNetwork listener state, and both losing the last network and switching networks sweep the stale connections so their owners redial immediately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager ties the network availability state, the connection sweeper and the status recorder together; it outlives engine restarts. A nil *Manager is the valid no-events value for consumers: the read methods report always-online and never sweep. Only the event sources hold a real Manager, so the write methods do not tolerate a nil receiver.

func NewManager

func NewManager(recorder Recorder) *Manager

NewManager creates a Manager reporting into recorder, starting online.

func (*Manager) Changed

func (m *Manager) Changed() <-chan struct{}

Changed returns a channel closed on the next availability transition.

func (*Manager) IsOnline

func (m *Manager) IsOnline() bool

IsOnline reports whether the OS reports at least one usable network.

func (*Manager) NotifyNetworkChange

func (m *Manager) NotifyNetworkChange()

NotifyNetworkChange marks the management, signal and relay connections stale after the OS switched networks and schedules a sweep that cuts whatever has not redialed on the new network by then. The engine and the TUN device stay untouched.

Panics on a nil receiver: only the mobile bindings that own a Manager report network changes.

func (*Manager) QuickRetryBackoff

func (m *Manager) QuickRetryBackoff(ctx context.Context, bo backoff.BackOff) backoff.BackOff

QuickRetryBackoff wraps bo for a quick retry after a network change; see sweep.Sweeper.QuickRetryBackoff.

func (*Manager) SetNetworkAvailable

func (m *Manager) SetNetworkAvailable(available bool)

SetNetworkAvailable records OS-reported network availability. While unavailable, the reconnection loops suspend their attempts and the connection listener reports NoNetwork instead of Connecting; when availability returns, the loops resume immediately with a fresh backoff. Losing the last network also sweeps the registered connections: nothing can redial while offline, so the stale sockets would otherwise stay silently "connected" until their own timeouts and the client would keep reporting Connected with no network at all.

Panics on a nil receiver: only the mobile bindings that own a Manager report availability.

func (*Manager) StartDial

func (m *Manager) StartDial(ctx context.Context) *sweep.Dial

StartDial registers an in-flight dial with the sweeper; see sweep.Sweeper.StartDial.

func (*Manager) Wait

func (m *Manager) Wait(ctx context.Context) (bool, error)

Wait blocks while the network is offline; see netstate.State.Wait.

func (*Manager) WaitSettled

func (m *Manager) WaitSettled(ctx context.Context, budget, settleWindow time.Duration) bool

WaitSettled waits until an online verdict holds for a full settleWindow, or while offline until the budget runs out. Returns false when ctx is cancelled. The settle window exists because a disconnect often precedes the OS offline flag by a few milliseconds, so a fresh online verdict cannot be trusted immediately. A nil Manager has no events to watch: it degrades to a fixed budget-long sleep.

type Recorder

type Recorder interface {
	SetNetworkAvailable(available bool)
}

Recorder receives the availability changes for listener state reporting.

Directories

Path Synopsis
Package netstate tracks OS-reported network availability for the client.
Package netstate tracks OS-reported network availability for the client.
Package sweep cuts network-bound activity when the OS switches networks: a sweep closes the registered connections and aborts the in-flight dials, so their owners redial immediately instead of waiting for the old sockets to time out.
Package sweep cuts network-bound activity when the OS switches networks: a sweep closes the registered connections and aborts the in-flight dials, so their owners redial immediately instead of waiting for the old sockets to time out.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL