lmnet

package
v0.0.0-...-19fda0b Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

README

Interface with low-level local mesh network

Communication uses messages.

The driver subscribes to the /wifi topic, and receives messages setting the desired state and commands. Implementation uses Android Wifi, BLE, BT and NAN, exposing discovery, connection, messages. On Linux the 'wpa' package is used for wpa_supplicant, using a separate root process. Other features may be added later, but Wifi P2P is the main mechanism.

The driver sends "/net" messages, with details about the network status.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByLevel

type ByLevel []*mesh.MeshDevice

func (ByLevel) Len

func (a ByLevel) Len() int

func (ByLevel) Less

func (a ByLevel) Less(i, j int) bool

func (ByLevel) Swap

func (a ByLevel) Swap(i, j int)

type MeshInfo

type MeshInfo struct {
	SSID     string    `json:"s,omitempty"`
	PSK      string    `json:"p,omitempty"`
	LastSeen time.Time `json:"-"`
	Name     string    `json:"N,omitempty"`
}

Persisted device info.

type Wifi

type Wifi struct {
	Mesh *local.LLDiscovery

	// Full database of found devices (by anyone). May be trimmed periodically
	// ( x hours ). Will be saved to speed up discovery. Will be sent to parent
	// and children.
	MeshInfo map[string]*MeshInfo

	// Current visible wifi devices, with last level (from this device perspective)
	MeshDevices map[string]*mesh.MeshDevice

	// Mesh devices visible from this device.
	VisibleDevices map[string]*mesh.MeshDevice

	// Connection to the master. Only used on non-android
	SendMessage *msgs.MsgConnection

	// Last scan results (raw). Includes known and DIRECT networks.
	Scan     map[string]*mesh.MeshDevice
	ScanTime time.Time

	DiscoveryTime time.Time
	DiscoveryCnt  int

	// True if the database needs to be saved, for fast reload.
	// Periodic thread will save.
	NeedsSave bool
	// contains filtered or unexported fields
}

Wifi controls the Wifi interface - DMesh currently uses P2P and APs with DM- names and fixed PSK. The actual low level implementation is part of the native android app, or a separate process running as root (or net_admin CAP) and using WPA directly. Messages are used to communicate with the real wifi implementation.

func NewWifi

func NewWifi(cb WifiCallbacks, u *msgs.MsgConnection,
	msh *local.LLDiscovery) *Wifi

Create the Wifi object, using the UDS channel for communication.

func (*Wifi) HTTPCon

func (wifi *Wifi) HTTPCon(w http.ResponseWriter, r *http.Request)

Connect to strongest signal - /wifi/con

func (*Wifi) HandleMessage

func (wifi *Wifi) HandleMessage(ctx context2.Context, cmdS string, meta map[string]string, data []byte)

Message from the wpa layer: /wifi/status

func (*Wifi) JsonScan

func (wifi *Wifi) JsonScan(w http.ResponseWriter, r *http.Request)

Return the raw result of the last Wifi SCAN. /debug/scan

func (*Wifi) OnConnect

func (wifi *Wifi) OnConnect(ssid string)

Notification that the device SSID changed. Empty if no wifi connection.

func (*Wifi) OnNetStatus

func (wifi *Wifi) OnNetStatus(meta map[string]string, scanR *mesh.ScanResults)

OnNetStatus is called when the WPA or Android layer gets a Wifi update - changed list of visible Mesh nodes, or periodic update, or changed signal.

Will decide if a connection should be started or changed. This moved to native side, since it has better visibility of the mesh and can avoid discovery.

func (*Wifi) ScanStatus

func (wifi *Wifi) ScanStatus() string

TODO: json, updates

type WifiCallbacks

type WifiCallbacks interface {
	// Called when a network event is received that would require network refresh.
	RefreshNetworks()
}

type WifiCtl

type WifiCtl interface {
	Scan()
	Connect(ssid, pass string)
	StartAP(t time.Duration)
}

Jump to

Keyboard shortcuts

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