Skip to content

Commit

Permalink
Improve D-Bus network interface (#961)
Browse files Browse the repository at this point in the history
## Problem

Until now, the communication between our network model and its D-Bus
interface worked only in one direction (from D-Bus to the model). And
that was pretty limiting.

## Solution

In #885 we introduce the usage of `oneshot::channel()` to enable
bi-directional communication between the model and the D-Bus interface.
It worked rather well, so it is time to extend this approach.

Some use cases that are covered:

* Perform a complex validation in the model (considering the whole
model) and return the result to the D-Bus interface.
* Return the D-Bus path of a new connection (implemented in this PR).

But there is another interesting implication: the model is the single
source of truth (no more cloned data in the interface). In the future,
we are expected to listen to NetworkManager and update some parts of our
model accordingly. Not having to replicate that information to D-Bus
(except when new things add or disappear) makes things easier.

Note: `org.opensuse.Agama1.Network.Device` and
`org.opensuse.Agama1.Network.Devices` are excluded by now.

## Testing

- *Added a new unit test*
- *Tested manually*


## To do

- [x] Reduce the boilerplate associated to the usage of channels.
  • Loading branch information
imobachgs authored Dec 27, 2023
2 parents 5e882f8 + 3eb41cd commit 3deeadc
Show file tree
Hide file tree
Showing 15 changed files with 829 additions and 730 deletions.
5 changes: 3 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/agama-dbus-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ gettext-rs = { version = "0.7.0", features = ["gettext-system"] }
regex = "1.10.2"
once_cell = "1.18.0"
macaddr = "1.0"
async-trait = "0.1.75"
15 changes: 12 additions & 3 deletions rust/agama-dbus-server/src/network/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::network::model::Connection;
use agama_lib::network::types::DeviceType;
use tokio::sync::oneshot;
use uuid::Uuid;
use zbus::zvariant::OwnedObjectPath;

use super::error::NetworkStateError;

Expand All @@ -15,7 +16,11 @@ pub type ControllerConnection = (Connection, Vec<String>);
#[derive(Debug)]
pub enum Action {
/// Add a new connection with the given name and type.
AddConnection(String, DeviceType),
AddConnection(
String,
DeviceType,
Responder<Result<OwnedObjectPath, NetworkStateError>>,
),
/// Gets a connection
GetConnection(Uuid, Responder<Option<Connection>>),
/// Gets a controller connection
Expand All @@ -25,9 +30,13 @@ pub enum Action {
),
/// Sets a controller's ports. It uses the Uuid of the controller and the IDs or interface names
/// of the ports.
SetPorts(Uuid, Vec<String>, Responder<Result<(), NetworkStateError>>),
SetPorts(
Uuid,
Box<Vec<String>>,
Responder<Result<(), NetworkStateError>>,
),
/// Update a connection (replacing the old one).
UpdateConnection(Connection),
UpdateConnection(Box<Connection>),
/// Remove the connection with the given Uuid.
RemoveConnection(String),
/// Apply the current configuration.
Expand Down
Loading

0 comments on commit 3deeadc

Please sign in to comment.