Skip to content

Commit

Permalink
🐛 Expose the socket address clients can use
Browse files Browse the repository at this point in the history
Until now, `--print-address` would print the address specification,
that is, the input used to determine how and where the server would
listen. This would be useful for clients for `unix:path=...`, but for
`unix:dir=...` and `unix:tmpdir=...` this would not work. So now we
share the socket address that is produced from the address
specification.
  • Loading branch information
jokeyrhyme committed Dec 25, 2024
1 parent e7998ba commit 0e6497a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/bus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ enum Listener {
impl Bus {
pub async fn for_address(address: &str) -> Result<Self> {
let mut address = Address::from_str(address)?;
let guid: OwnedGuid = match address.guid() {
Some(guid) => guid.to_owned().into(),
None => {
let guid = Guid::generate();
address = address.set_guid(guid.clone())?;

guid.into()
}
};
let (listener, auth_mechanism) = match address.transport() {
#[cfg(unix)]
Transport::Unix(unix) => {
// resolve address specification into address that clients can use
let addr = Self::unix_addr(unix)?;

(Self::unix_stream(addr).await?, AuthMechanism::External)
address = Address::try_from(
format!("unix:path={}", addr.as_pathname().unwrap().display()).as_str(),
)?;

(
Self::unix_stream(addr.clone()).await?,
AuthMechanism::External,
)
}
Transport::Tcp(tcp) => {
#[cfg(not(windows))]
Expand All @@ -75,6 +74,16 @@ impl Bus {
_ => bail!("Unsupported address `{}`.", address),
};

let guid: OwnedGuid = match address.guid() {
Some(guid) => guid.to_owned().into(),
None => {
let guid = Guid::generate();
address = address.set_guid(guid.clone())?;

guid.into()
}
};

let peers = Peers::new();

let dbus = DBus::new(peers.clone(), guid.clone());
Expand Down

0 comments on commit 0e6497a

Please sign in to comment.