Basic vsock proxying implementation

Currently just connecting to the host's session bus
This commit is contained in:
Val Packett 2025-07-04 21:52:14 -03:00
parent 11a682e19f
commit 14ce212e81
12 changed files with 1807 additions and 34 deletions

10
sidebus-common/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "sidebus-common"
version = "0.1.0"
edition = "2024"
[dependencies]
tracing = "0.1.41"
tokio = { version = "1.46.0", features = ["macros"] }
tokio-stream = "0.1.17"
zbus = { version = "5.7.1", default-features = false, features = ["tokio", "tokio-vsock", "bus-impl", "p2p"] }

View file

@ -0,0 +1 @@
pub mod raw;

49
sidebus-common/src/raw.rs Normal file
View file

@ -0,0 +1,49 @@
//! Utilities for dealing with raw message streams
use tokio_stream::StreamExt as _;
use tracing::{debug, error, info};
pub async fn handle_msgs<F, E>(
dir: &'static str,
mut from: zbus::MessageStream,
mut cb: impl FnMut(zbus::Message) -> F,
) -> ()
where
F: Future<Output = Result<(), E>>,
E: std::fmt::Debug,
{
loop {
match from.next().await {
Some(Ok(msg)) => {
debug!(%dir, ?msg, "handling msg");
match cb(msg).await {
Ok(()) => debug!(%dir, "success"),
Err(err) => error!(%dir, ?err, "error handling msg"),
}
}
Some(Err(err)) => {
error!(%dir, %err, "error receiving msg");
}
Option::None => {
error!(%dir, "stream ended");
return ();
}
}
}
}
pub async fn splice_conns(client_conn: zbus::Connection, target_conn: zbus::Connection) {
let target_bus_1 = target_conn.clone();
tokio::select! {
_ = handle_msgs("FROM", client_conn.clone().into(), async |msg| {
target_bus_1.send(&msg).await
}) => {
info!("from_client exited");
}
_ = handle_msgs("TO", target_conn.into(), async |msg| {
client_conn.send(&msg).await
}) => {
info!("to_client exited");
}
}
}