47 lines
1.5 KiB
Rust
47 lines
1.5 KiB
Rust
|
|
use clap::Parser;
|
||
|
|
use tokio::net::UnixListener;
|
||
|
|
use tracing::info;
|
||
|
|
|
||
|
|
#[derive(Parser)]
|
||
|
|
#[command(version, about, long_about = None)]
|
||
|
|
struct AgentCli {
|
||
|
|
listen_path: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[tokio::main]
|
||
|
|
async fn main() -> eyre::Result<()> {
|
||
|
|
tracing_subscriber::fmt::init();
|
||
|
|
|
||
|
|
let cli = AgentCli::parse();
|
||
|
|
|
||
|
|
let unix_addr = cli.listen_path;
|
||
|
|
let unix_listener = UnixListener::bind(unix_addr.clone())?;
|
||
|
|
info!(%unix_addr, "listening for unix clients");
|
||
|
|
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, 4269),
|
||
|
|
));
|
||
|
|
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(())
|
||
|
|
}
|