1
//! Functions to help working with onion services.
2

            
3
use crate::internal_prelude::*;
4

            
5
/// 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.
11
pub fn handle_rend_requests<S>(rend_requests: S) -> impl Stream<Item = StreamRequest>
12
where
13
    S: Stream<Item = RendRequest>,
14
{
15
    rend_requests.flat_map_unordered(None, |rend_request| {
16
        Box::pin(rend_request.accept())
17
            .map(|outcome| match outcome {
18
                Ok(stream_requests) => Either::Left(stream_requests),
19
                Err(e) => {
20
                    warn_report!(e, "Problem while accepting rendezvous request");
21
                    Either::Right(futures::stream::empty())
22
                }
23
            })
24
            .flatten_stream()
25
    })
26
}