diff --git a/src/link/routed/endpoint.rs b/src/link/routed/endpoint.rs index 35249840..39f92b8e 100644 --- a/src/link/routed/endpoint.rs +++ b/src/link/routed/endpoint.rs @@ -148,9 +148,11 @@ impl Clone for Endpoint { struct Inner { table: Table, dial: D, - /// The endpoint's advertised name, pre-encoded (validated at - /// construction) for the `LINK` headers this endpoint writes. - advertised: Vec, + /// The endpoint's advertised name, as given at construction. + local_addr: D::Addr, + /// The advertised name, pre-encoded (validated at construction) for + /// the `LINK` headers this endpoint writes. + encoded: Vec, } impl Endpoint { @@ -209,13 +211,20 @@ impl Endpoint { inner: Arc::new(Inner { table: table.clone(), dial: dial.clone(), - advertised: encoded, + local_addr: advertised, + encoded, }), }; let router = router::drive(listen, dial, table, arrivals, config.pending_headers); Ok((endpoint, Incoming { links: incoming }, router)) } + /// The name peers dial this endpoint at: `advertised`, as given at + /// construction. + pub fn local_addr(&self) -> &D::Addr { + &self.inner.local_addr + } + /// Establish one link to the peer reachable at `peer`. /// /// One round trip: dial the peer's router, announce the link (its @@ -241,7 +250,7 @@ impl Endpoint { // find the token routable. let (token, registration, streams) = router::register(&self.inner.table); let mut conn = self.inner.dial.dial(&peer).await?; - conn.write_all(&header::link_header(&token, &self.inner.advertised)) + conn.write_all(&header::link_header(&token, &self.inner.encoded)) .await?; let mut ack = [0; 1]; match conn.read_exact(&mut ack).await { diff --git a/src/link/routed/tests.rs b/src/link/routed/tests.rs index dd7e6c8d..6ddd0740 100644 --- a/src/link/routed/tests.rs +++ b/src/link/routed/tests.rs @@ -141,6 +141,16 @@ fn establishment_connects_control_and_streams() { }); } +/// `local_addr` is the advertised name given at construction, the name +/// peers dial this endpoint at; callers need it back for policies like +/// dial tiebreaks. +#[test] +fn local_addr_is_the_constructed_name() { + let net = MemoryNet::new(); + let (a, _incoming, _router) = endpoint(&net, "a", Config::default()); + assert_eq!(*a.local_addr(), MemoryName::new("a")); +} + /// A stream connection quoting a token no live link owns is dropped: /// the dialer observes end-of-stream, and no link's queue sees the /// connection.