pub struct Guard { /* private fields */ }Expand description
出口码率 + 媒体准入控制器。线程安全;整个进程共用一个(见 global)。
Implementations§
Source§impl Guard
impl Guard
pub fn new(config: GuardConfig) -> Self
pub fn config(&self) -> GuardConfig
Sourcepub fn set_config(&self, config: GuardConfig)
pub fn set_config(&self, config: GuardConfig)
运行期替换策略(测试放宽、应用热更新)。已累计的封禁/令牌桶状态保留。
Sourcepub fn note_egress(&self, bytes: u64)
pub fn note_egress(&self, bytes: u64)
累计出口字节(单调递增)。
pub fn egress_total(&self) -> u64
Sourcepub fn egress_bps(&self) -> u64
pub fn egress_bps(&self) -> u64
当前出口码率(字节/秒);窗口 1 秒,取最近若干次测量与当前值的最大值。
Sourcepub fn egress_limited(&self) -> bool
pub fn egress_limited(&self) -> bool
出口是否已达阈值(此时应拒绝新的媒体连接)。
Sourcepub fn check_egress(&self) -> Result<(), &'static str>
pub fn check_egress(&self) -> Result<(), &'static str>
只要出口准入(HLS 分片这类不占长连接的请求用)。
Sourcepub fn admit_media(
&self,
peer: IpAddr,
kind: MediaKind,
) -> Result<(), &'static str>
pub fn admit_media( &self, peer: IpAddr, kind: MediaKind, ) -> Result<(), &'static str>
媒体连接准入:出口码率 / 单 IP 并发 / 建连速率 / 封禁。
Sourcepub fn release_media(&self, peer: IpAddr, kind: MediaKind)
pub fn release_media(&self, peer: IpAddr, kind: MediaKind)
释放一个媒体名额(与 admit_media 配对)。
pub fn snapshot(&self) -> GuardSnapshot
Auto Trait Implementations§
impl !Freeze for Guard
impl Forget for Guard
impl Move for Guard
impl RefUnwindSafe for Guardwhere
RwLock<GuardConfig>: RefUnwindSafe,
Atomic<bool>: RefUnwindSafe,
Atomic<u64>: RefUnwindSafe,
Mutex<[u32; 4]>: RefUnwindSafe,
Mutex<Window>: RefUnwindSafe,
Mutex<Bucket>: RefUnwindSafe,
Mutex<HashMap<IpAddr, IpState>>: RefUnwindSafe,
Mutex<HashMap<Box<str>, IdentityBucket>>: RefUnwindSafe,
impl Send for Guard
impl Sync for Guard
impl Unpin for Guard
impl UnsafeUnpin for Guardwhere
Align4<u32>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
Align8<u64>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<(IpAddr, IpState)>: UnsafeUnpin,
PhantomData<(Box<str>, IdentityBucket)>: UnsafeUnpin,
impl UnwindSafe for Guardwhere
RwLock<GuardConfig>: UnwindSafe,
Align1<u8>: UnwindSafe,
Align8<u64>: UnwindSafe,
Mutex<[u32; 4]>: UnwindSafe,
Mutex<Window>: UnwindSafe,
Mutex<Bucket>: UnwindSafe,
Mutex<HashMap<IpAddr, IpState>>: UnwindSafe,
Mutex<HashMap<Box<str>, IdentityBucket>>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more