1//! Functions to help working with onion services.
23use crate::internal_prelude::*;
45/// Consume a stream of [`RendRequest`], accepting them all, and produce a
6/// stream of [`StreamRequest`].
7///
8/// If you want to reject certain [`RendRequest`]s, you can use
9/// [`StreamExt::filter`](futures::StreamExt::filter) or
10/// similar in order to remove them from the incoming stream.
11pub fn handle_rend_requests<S>(rend_requests: S) -> impl Stream<Item = StreamRequest>
12where
13S: Stream<Item = RendRequest>,
14{
15 rend_requests.flat_map_unordered(None, |rend_request| {
16 Box::pin(rend_request.accept())
17 .map(|outcome| match outcome {
18Ok(stream_requests) => Either::Left(stream_requests),
19Err(e) => {
20warn_report!(e, "Problem while accepting rendezvous request");
21 Either::Right(futures::stream::empty())
22 }
23 })
24 .flatten_stream()
25 })
26}