mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-29 21:14:18 +00:00
http: add RateLimitedStream::inner, drop peer_addr
instead of implementing 'peer_addr' specifically for RateLimitedStream<tokio::net::TcpStream>, just provide .inner() and .inner_mut() so the user can reach the inner stream directly. This way we can drop the tokio/net feature as well Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
b2c26f74a6
commit
d7ed04f8e5
@ -36,7 +36,6 @@ rate-limited-stream = [
|
|||||||
"dep:tokio",
|
"dep:tokio",
|
||||||
"hyper?/client",
|
"hyper?/client",
|
||||||
"rate-limiter",
|
"rate-limiter",
|
||||||
"tokio?/net",
|
|
||||||
"tokio?/time",
|
"tokio?/time",
|
||||||
]
|
]
|
||||||
client = [
|
client = [
|
||||||
|
@ -29,12 +29,6 @@ pub struct RateLimitedStream<S> {
|
|||||||
stream: S,
|
stream: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RateLimitedStream<tokio::net::TcpStream> {
|
|
||||||
pub fn peer_addr(&self) -> std::io::Result<std::net::SocketAddr> {
|
|
||||||
self.stream.peer_addr()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S> RateLimitedStream<S> {
|
impl<S> RateLimitedStream<S> {
|
||||||
/// Creates a new instance with reads and writes limited to the same `rate`.
|
/// Creates a new instance with reads and writes limited to the same `rate`.
|
||||||
pub fn new(stream: S, rate: u64, bucket_size: u64) -> Self {
|
pub fn new(stream: S, rate: u64, bucket_size: u64) -> Self {
|
||||||
@ -97,6 +91,14 @@ impl<S> RateLimitedStream<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inner(&self) -> &S {
|
||||||
|
&self.stream
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inner_mut(&mut self) -> &mut S {
|
||||||
|
&mut self.stream
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_traffic(limiter: &(dyn ShareableRateLimit), count: usize) -> Option<Pin<Box<Sleep>>> {
|
fn register_traffic(limiter: &(dyn ShareableRateLimit), count: usize) -> Option<Pin<Box<Sleep>>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user