-
What's the best way to require a peer to perform additional negotiation on a new connection? For example, perhaps there is the need to authenticate by requiring the peer knows a certain secret. Another example could be exchanging application version hashes and rejecting a connection if the versions do not match. Here are some potential solutions I gathered:
Is there a good solution above, or is it something else entirely? Thanks for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I ended up going with the first option, the fn dial(addr) {
match self.inner.dial(addr) {
Ok(original_future) => Ok(Box::pin(async move {
// Wait the original future
let stream = original_future.await?;
// Open a substream for your secondary handshake
let mut substream =
poll_fn(|cx| stream.1.poll_outbound_unpin(cx)).await?;
// You now have access to a stream with `AsyncRead`/`AsyncWrite`
// .. your handshake logic ..
}
}
} On the other side, |
Beta Was this translation helpful? Give feedback.
-
interesting! And thanks for answering your own question, btw can you describe what is your use case? |
Beta Was this translation helpful? Give feedback.
I ended up going with the first option, the
Transport
wrapper. With a bit of magic, you can wrapdial
andpoll
futures to add a secondary negotiation layer:On the other side,
poll
, you would need to…