Switch over to a reverse connection scheme (bridge to a guest bus)
This commit is contained in:
parent
ea34b7b08c
commit
52c3ea7cd3
5 changed files with 53 additions and 82 deletions
|
|
@ -1,5 +1,3 @@
|
|||
use eyre::OptionExt;
|
||||
use tokio::net::UnixListener;
|
||||
use tracing::info;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -10,38 +8,23 @@ async fn main() -> eyre::Result<()> {
|
|||
let vsock_port = std::fs::read_to_string(creds_dir.join("sidebus.port"))?
|
||||
.trim()
|
||||
.parse::<u32>()?;
|
||||
let vsock_addr = zbus::Address::from(zbus::address::Transport::Vsock(
|
||||
zbus::address::transport::Vsock::new(2, vsock_port),
|
||||
));
|
||||
|
||||
let unix_listener = UnixListener::from_std(
|
||||
listenfd::ListenFd::from_env()
|
||||
.take_unix_listener(0)?
|
||||
.ok_or_eyre("no unix listener provided")?,
|
||||
)?;
|
||||
info!("listening for unix clients");
|
||||
info!("connecting to session bus");
|
||||
let session_conn = zbus::connection::Builder::session()?.p2p().build().await?;
|
||||
|
||||
let vsock_conn = zbus::connection::Builder::address(vsock_addr)?
|
||||
.server(session_conn.server_guid())
|
||||
.unwrap()
|
||||
.p2p()
|
||||
.auth_mechanism(zbus::AuthMechanism::Anonymous)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
info!(guid = %vsock_conn.server_guid(), "connected to vsock bus");
|
||||
sidebus_common::raw::splice_conns(vsock_conn, session_conn).await;
|
||||
|
||||
while let Ok((unix_client, client_addr)) = unix_listener.accept().await {
|
||||
info!(?client_addr, "new unix client");
|
||||
tokio::spawn(async move {
|
||||
let vsock_addr = zbus::Address::from(zbus::address::Transport::Vsock(
|
||||
zbus::address::transport::Vsock::new(2, vsock_port),
|
||||
));
|
||||
let vsock_conn = zbus::connection::Builder::address(vsock_addr)
|
||||
.unwrap()
|
||||
.p2p()
|
||||
.auth_mechanism(zbus::AuthMechanism::Anonymous)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
info!(guid = %vsock_conn.server_guid(), "connected to vsock bus");
|
||||
let client_conn = zbus::connection::Builder::unix_stream(unix_client)
|
||||
.server(vsock_conn.server_guid())
|
||||
.unwrap()
|
||||
.p2p()
|
||||
.auth_mechanism(zbus::AuthMechanism::External)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
sidebus_common::raw::splice_conns(client_conn, vsock_conn).await;
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue