Skip to content

noise: rewrite to use tokio-codec#143

Open
npry wants to merge 3 commits intomainfrom
npry/noise.codec
Open

noise: rewrite to use tokio-codec#143
npry wants to merge 3 commits intomainfrom
npry/noise.codec

Conversation

@npry
Copy link
Copy Markdown
Collaborator

@npry npry commented Apr 24, 2026

Saw #139, had a feeling we still had bugs here -- rewrote control_noise to use tokio-codec as had been a rough plan. This eliminates the manual AsyncRead/AsyncWrite implementations at the cost of potential minimal increases to allocation. I think this is well worth having code that's much easier to reason about. I added tests here, including some proptests, which should cover the error from #139 if I'm reading it right.

Also cut down the messages module — we read the header and the body in two steps, so I don't think we need the dedicated *Message types containing both.

Also documented and made most of the crate pub, since I think that gives a more complete representation of the pieces of ts2021.

FramedIo

I did a dumb copy-paste out of tokio because the adapters from Stream<impl AsRef<[u8]>> and Sink<impl AsRef<[u8]>> to AsyncRead/AsyncWrite are mutually exclusive, and our codec type is duplex (we would need both wrapping it, and we can't nest them to get both trait impls).

With existing tools we would've needed to use something like StreamExt::split to separate BiCodec into stream and sink parts, which introduces a mutex that we know a priori is unnecessary, wrap each part in SinkWriter and StreamReader, then join them back together.

@npry npry force-pushed the npry/noise.codec branch 4 times, most recently from 0f9f0a1 to 1fc8b42 Compare April 24, 2026 22:31
npry added 3 commits April 27, 2026 18:49
Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: I7556c1452053f1cc02549e3ad425672c6a6a6964
Simplify the handshake to read the header and then the body in two
successive steps. Drop most of the message types, as they rewrap the
body, which is handled on its own by `codec`.

Export more of the internals -- this is an internals crate anyway, might
as well open the definitions if other people might want to use it.
Improve docs as part of that.

Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: I5a037e0ac35dd969812d7ab68cf6ca3c6a6a6964
Signed-off-by: Nathan Perry <nathan@tailscale.com>
Change-Id: Ia83e08aff37ad6303ba57c31dea773c86a6a6964
@npry npry force-pushed the npry/noise.codec branch from 1fc8b42 to 50e6d75 Compare April 27, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant