1
//! Implementation of [`PowManager`], for tracking proof-of-work seeds and data
2
//! for adjusting difficulty.
3

            
4
#[cfg_attr(not(feature = "hs-pow-full"), path = "pow/v1_stub.rs")]
5
pub(crate) mod v1;
6

            
7
use std::{pin::Pin, sync::Arc};
8

            
9
pub(crate) use self::v1::PowManager;
10

            
11
use futures::{channel::mpsc, Stream};
12
use tor_async_utils::mpsc_channel_no_memquota;
13
use tor_hscrypto::time::TimePeriod;
14

            
15
use crate::RendRequest;
16

            
17
/// Struct to hold various things you get when you make a new [`PowManager`].
18
pub(crate) struct NewPowManager<R> {
19
    /// The PoW manager.
20
    pub(crate) pow_manager: Arc<PowManager<R>>,
21
    /// Sender for rendezvous requests.
22
    pub(crate) rend_req_tx: mpsc::Sender<RendRequest>,
23
    /// Receiver for rendezvous requests.
24
    pub(crate) rend_req_rx: Pin<Box<dyn Stream<Item = RendRequest> + Send + Sync>>,
25
    /// Receiver used for the publisher to hear when it needs to republish for a TP because of a
26
    /// seed update.
27
    pub(crate) publisher_update_rx: mpsc::Receiver<TimePeriod>,
28
}
29

            
30
/// Depth of the [`RendRequest`] queue.
31
// TODO #1779: allow clients to configure this?
32
const REND_QUEUE_DEPTH: usize = 32;
33

            
34
/// Make a MPSC channel for the rendevouz request queue.
35
///
36
/// This is the underlying object in both the stub and non-stub case, so we share the code.
37
fn make_rend_queue() -> (mpsc::Sender<RendRequest>, mpsc::Receiver<RendRequest>) {
38
    // If the HS implementation is stalled somehow, this is a local problem.
39
    // We shouldn't kill the HS even if this is the oldest data in the system.
40
    mpsc_channel_no_memquota(REND_QUEUE_DEPTH)
41
}