use std::marker::PhantomData;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker};
use tor_memquota::memory_cost_structural_copy;
use tor_rtcompat::{DynTimeProvider, SleepProvider};
use crate::Error;
use crate::HopNum;
use crate::util::err::ExcessPadding;
#[derive(Clone, Debug)]
pub(crate) struct PaddingController<S: SleepProvider = DynTimeProvider> {
_phantom: PhantomData<S>,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct SendPadding(void::Void);
#[derive(Clone, Copy, Debug)]
pub(crate) struct QueuedCellPaddingInfo(void::Void);
memory_cost_structural_copy!(QueuedCellPaddingInfo);
#[derive(Clone, Copy, Debug)]
pub(crate) struct StartBlocking(void::Void);
#[derive(Clone, Copy, Debug)]
pub(crate) struct PaddingEvent(pub(crate) void::Void);
impl<S: SleepProvider> PaddingController<S> {
pub(crate) fn queued_data(&self, _hop: HopNum) -> Option<QueuedCellPaddingInfo> {
None
}
pub(crate) fn queued_data_as_padding(
&self,
_hop: HopNum,
sendpadding: SendPadding,
) -> Option<QueuedCellPaddingInfo> {
void::unreachable(sendpadding.0);
}
pub(crate) fn queued_padding(
&self,
_hop: HopNum,
sendpadding: SendPadding,
) -> Option<QueuedCellPaddingInfo> {
void::unreachable(sendpadding.0);
}
pub(crate) fn flushed_relay_cell(&self, _info: QueuedCellPaddingInfo) {}
pub(crate) fn flushed_channel_cell(&self) {}
pub(crate) fn decrypted_data(&self, _hop: HopNum) {}
pub(crate) fn decrypted_padding(&self, hop: HopNum) -> Result<(), crate::Error> {
Err(crate::Error::ExcessPadding(
ExcessPadding::NoPaddingNegotiated,
hop,
))
}
}
pub(crate) struct PaddingEventStream<S: SleepProvider = DynTimeProvider> {
_phantom: PhantomData<S>,
}
impl futures::Stream for PaddingEventStream {
type Item = super::PaddingEvent;
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending
}
}
impl futures::stream::FusedStream for PaddingEventStream {
fn is_terminated(&self) -> bool {
false
}
}
pub(crate) fn new_padding<S: SleepProvider>(runtime: S) -> (PaddingController, PaddingEventStream) {
drop(runtime);
(
PaddingController {
_phantom: PhantomData,
},
PaddingEventStream {
_phantom: PhantomData,
},
)
}