Skip to content

Custom connection handshake #5518

Closed Answered by rob-maron
rob-maron asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up going with the first option, the Transport wrapper. With a bit of magic, you can wrap dial and poll futures to add a secondary negotiation layer:

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, poll, you would need to…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rob-maron
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants