AEAD-2022 TCP 编写器在 Pending 后报告重试缓冲区长度,丢弃附加数据
use shadowsocks::{config::{ServerType}, context::{Context as SsContext}, crypto::{CipherKind}, relay::{tcprelay::{crypto_io::{CryptoStream, CryptoWrite, StreamType}, _}},}; use std::{io, pin::{Pin}, task::{Context, Poll, Waker},}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
#[derive(Default)] struct Sink { blocked: bool, bytes: Vec, waker: Option, }
impl AsyncRead for Sink { fn poll_read( self: Pin<&mut Self>, _: &mut Context<'_>, _: &mut ReadBuf<'_>, ) -> Poll<io::Result<()>> { Poll::Ready(Ok(())) } }
impl AsyncWrite for Sink { fn poll_write( mut self: Pin<&mut Self>, cx: &mut Context<'_>, data: &[u8], ) -> Poll<io::Result> { if self.blocked { self.waker = Some(cx.waker().clone()); return Poll::Pending; } self.bytes.extend_from_slice(data); Poll::Ready(Ok(data.len())) }
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
if self.blocked {
self.waker = Some(cx.waker().clone());
return Poll::Pending;
}
self.bytes.extend_from_slice(data);
Poll::Ready(Ok(()))
}
}
内容来源: shadowsocks/shadowsocks-rust