Skip to content

Draft: Special-purpose stream copiers made from composable parts

Micah Elizabeth Scott requested to merge beth/arti:ticket786_mr into main

Background: We have two places (arti's socks proxy and onionmasq) where a stream-copying activity needs to take place which is very similar but not quite idential to what futures::io::copy is doing. This is arti issue #786 (closed).

We could make a copy of that code with the modifications we need, or we could library-ize one of the two similar implementations we have written. This patch explores an alternate approach using mix-in behaviors which can be used to build up a custom copier.

This rewrites arti's copy_interactive using the mix-in approach, with the copier and its component parts now living in the tor-async-utils crate.

Status: Passes tests and seems to work, but I'm still not sure this is the right approach. At the very least it needs more tests. Besides this approach and the copy-paste approach, another option to consider would be a composition structure based on some new trait, where the mutable reference to writer wouldn't need to be split like this but could be given up between polls.

Merge request reports