Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/link/routed/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ impl<D: Dial> Clone for Endpoint<D> {
struct Inner<D: Dial> {
table: Table<D::Conn>,
dial: D,
/// The endpoint's advertised name, pre-encoded (validated at
/// construction) for the `LINK` headers this endpoint writes.
advertised: Vec<u8>,
/// 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<u8>,
}

impl<D: Dial> Endpoint<D> {
Expand Down Expand Up @@ -209,13 +211,20 @@ impl<D: Dial> Endpoint<D> {
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
Expand All @@ -241,7 +250,7 @@ impl<D: Dial> Endpoint<D> {
// 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 {
Expand Down
10 changes: 10 additions & 0 deletions src/link/routed/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading