Skip to main content

Network

Struct Network 

Source
pub struct Network { /* private fields */ }
Expand description

Networking from NetworkManager, from cx.network(). Cloning it is cheap.

Implementations§

Source§

impl Network

Source

pub fn wifi_enabled(&self) -> ReadSignal<bool>

Whether Wi-Fi is on. false while NetworkManager isn’t running.

Source

pub fn connectivity(&self) -> ReadSignal<Connectivity>

How far the host reaches, from NetworkManager’s own checks. Unknown while it isn’t running.

Source

pub fn devices(&self) -> ReadSignal<Vec<NetworkDevice>>

Every device but loopback and those NetworkManager doesn’t manage, in NetworkManager’s numbering. Empty while it isn’t running.

Source

pub fn wifi_networks(&self) -> ReadSignal<Vec<WifiNetwork>>

The Wi-Fi networks each device sees, one per name and device, strongest first. Hidden networks are left out. Empty while NetworkManager isn’t running.

Source

pub fn scanner(&self) -> Scanner

Asks every Wi-Fi device that is on to look for networks now and every 10 s after, while the context that called cx.network() lives, so call it inside the popup that shows the networks. Scanners share one timer. NetworkManager’s refusal of a scan too soon after another is logged only at debug.

Source

pub fn set_wifi_enabled(&self, enabled: bool)

Turns Wi-Fi on or off.

Source

pub fn scan(&self, device: &str)

Asks the Wi-Fi device at device, its path, to look for networks. NetworkManager refuses a scan right after another, and that is logged.

Source

pub fn connect(&self, network: &WifiNetwork, password: Option<&str>)

Connects network’s device to it. Without a password, NetworkManager uses a connection saved for it, and refuses if it has none. With one, it saves a new WPA connection and uses that. A refusal is logged, never the password.

Source

pub fn disconnect(&self, device: &str)

Disconnects the device at device, until it is connected again.

Source

pub fn saved_connections(&self) -> ReadSignal<Vec<SavedConnection>>

The connections NetworkManager saved, in its numbering, at most 256. NetworkManager is asked for them on the first call and followed from then on, so a config that never lists them reads none. Empty while it isn’t running.

Source

pub fn forget(&self, uuid: &str)

Deletes the saved connection uuid names, so NetworkManager forgets that network. A refusal is logged.

Source

pub fn clear_secrets(&self, uuid: &str)

Takes the secrets, such as a Wi-Fi password, out of the saved connection uuid names, so NetworkManager asks for them next time. A refusal is logged.

Source

pub fn add_connection(&self, settings: &Json)

Saves a new connection with settings, by group and name as SavedConnection::settings holds them. Secrets such as a Wi-Fi psk may come too. An SSID or a hardware address may come as text. A value of a shape NetworkManager has no type for, or a refusal, is logged, never the settings.

fn save_cafe(network: &Network, password: &str) {
  network.add_connection(&serde_json::json!({
    "connection": { "id": "cafe", "type": "802-11-wireless" },
    "802-11-wireless": { "ssid": "cafe" },
    "802-11-wireless-security": { "key-mgmt": "wpa-psk", "psk": password },
  }));
}
Source

pub fn update_connection(&self, uuid: &str, settings: &Json)

Replaces the settings of the saved connection uuid names with settings, as add_connection takes them. Those left out go back to NetworkManager’s defaults. NetworkManager keeps the saved secrets when settings carries none, and drops them all once it carries any, so a new psk alone on an 802.1X connection drops its other passwords.

Trait Implementations§

Source§

impl Clone for Network

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more