Skip to main content

CoreState

Struct CoreState 

Source
pub struct CoreState {
    pub script_interceptor: Arc<ScriptInterceptor>,
    pub policy_tx: Sender<ProxyPolicy>,
    pub flows_dropped: Arc<AtomicUsize>,
    /* private fields */
}

Fields§

§script_interceptor: Arc<ScriptInterceptor>§policy_tx: Sender<ProxyPolicy>§flows_dropped: Arc<AtomicUsize>

Implementations§

Source§

impl CoreState

Source

pub async fn new(db_url: Option<String>) -> Self

Source

pub async fn get_metrics(&self) -> CoreMetrics

Source

pub async fn get_metrics_prometheus_text(&self) -> String

Source

pub fn status_snapshot(&self) -> CoreStatusSnapshot

Source

pub async fn status_report(&self) -> CoreStatusReport

Source

pub async fn intercept_snapshot(&self) -> CoreInterceptSnapshot

Source

pub fn audit_snapshot(&self, limit: usize) -> CoreAuditSnapshot

Source

pub async fn query_audit_snapshot( &self, query: CoreAuditQuery, ) -> CoreAuditSnapshot

Source

pub async fn get_flow(&self, id: String) -> Option<Flow>

Source

pub async fn get_rules(&self) -> Vec<Rule>

Source

pub async fn set_rules(&self, rules: Vec<Rule>)

Source

pub async fn upsert_rule_from( &self, actor: AuditActor, operation: &str, target: String, details: Value, rule: Rule, ) -> Result<(), String>

Source

pub async fn delete_rule_from( &self, actor: AuditActor, operation: &str, target: String, details: Value, rule_id: &str, ) -> Result<bool, String>

Source

pub async fn create_mock_response_rule_from( &self, actor: AuditActor, target: String, details: Value, config: MockResponseRuleConfig, ) -> Result<String, String>

Source

pub async fn create_intercept_rule_from( &self, actor: AuditActor, target: String, details: Value, config: InterceptRuleConfig, ) -> Result<String, String>

Source

pub async fn upsert_legacy_intercept_rule_from( &self, actor: AuditActor, target: String, details: Value, rule: InterceptRule, ) -> Result<(), String>

Source

pub async fn set_rules_from( &self, actor: AuditActor, operation: &str, target: String, details: Value, rules: Vec<Rule>, ) -> Result<(), String>

Source

pub async fn set_legacy_rules(&self, rules: Vec<InterceptRule>)

Source

pub async fn get_rule_engine(&self) -> Arc<RuleEngine>

Source

pub fn update_policy(&self, policy: ProxyPolicy)

Source

pub fn patch_policy_from( &self, actor: AuditActor, target: String, patch: ProxyPolicyPatch, )

Source

pub fn policy_snapshot(&self) -> ProxyPolicy

Source

pub fn update_policy_from( &self, actor: AuditActor, target: String, policy: ProxyPolicy, )

Source

pub async fn register_intercept( &self, key: String, tx: Sender<InterceptionResult>, )

Source

pub async fn resolve_intercept( &self, key: String, result: InterceptionResult, ) -> Result<(), String>

Source

pub async fn get_pending_ws_message( &self, key: String, ) -> Option<WebSocketMessage>

Source

pub async fn set_pending_ws_message( &self, key: String, message: WebSocketMessage, )

Source

pub async fn is_intercept_pending(&self, key: String) -> bool

Source

pub async fn is_flow_intercepted(&self, flow_id: String) -> bool

Source

pub fn upsert_flow(&self, flow: Box<Flow>)

Source

pub fn append_ws_message(&self, flow_id: String, message: WebSocketMessage)

Source

pub fn update_http_body( &self, flow_id: String, body: BodyData, direction: Direction, )

Source

pub fn subscribe_flow_updates(&self) -> Receiver<FlowUpdate>

订阅 FlowUpdate 广播。调用者获得独立 Receiver,lag 时自动跳过过期消息。

Source

pub fn subscribe_audit_events(&self) -> Receiver<AuditEvent>

Source

pub fn record_flow_events_lagged(&self, skipped: u64)

Source

pub fn record_audit_events_lagged(&self, skipped: u64)

Source

pub fn lifecycle(&self) -> RuntimeLifecycle

Source

pub fn subscribe_lifecycle(&self) -> Receiver<RuntimeLifecycle>

Source

pub fn stop_proxy(&self) -> Result<ProxyStopResult, String>

Source

pub fn recent_audit_events(&self) -> Vec<AuditEvent>

Source

pub async fn search_flows(&self, query: FlowQuery) -> Vec<FlowSummary>

搜索内存中的 Flow 列表,返回轻量摘要。

Source

pub fn redact_flow_update_for_output(&self, update: FlowUpdate) -> FlowUpdate

Source

pub async fn resolve_intercept_with_modifications( &self, key: String, action: &str, mods: Option<FlowModification>, ) -> Result<(), String>

解除截获并可选地应用修改。

action"drop" 时直接丢弃;其他值(含 "continue")则:

  • mods 为 None,直接 Continue;
  • mods 存在,根据 key 格式决定修改请求/响应还是 WebSocket 消息。

key 格式约定:

  • "<flow_id>:<phase>" — 修改请求或响应(phase 以 “request”/“response” 开头)
  • "<flow_id>:ws_msg:<msg_id>" — 修改 WebSocket 消息
Source

pub async fn resolve_intercept_with_modifications_from( &self, actor: AuditActor, key: String, action: &str, mods: Option<FlowModification>, ) -> Result<(), String>

Source

pub async fn load_script_from( &self, actor: AuditActor, target: String, script: &str, ) -> Result<(), String>

Source

pub fn spawn_proxy( self: &Arc<Self>, config: ProxyConfig, sink: Sender<FlowUpdate>, extra_interceptor: Option<Arc<dyn Interceptor>>, ) -> Result<ProxySpawnResult, String>

Source

pub async fn start_proxy( self: &Arc<Self>, config: ProxyConfig, sink: Sender<FlowUpdate>, extra_interceptor: Option<Arc<dyn Interceptor>>, ) -> Result<(), String>

Trait Implementations§

Source§

impl AuditService for CoreState

Source§

fn audit_snapshot(&self, limit: usize) -> CoreAuditSnapshot

Source§

fn query_audit_snapshot<'life0, 'async_trait>( &'life0 self, query: CoreAuditQuery, ) -> Pin<Box<dyn Future<Output = CoreAuditSnapshot> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn subscribe_audit_events(&self) -> Receiver<AuditEvent>

Source§

fn record_audit_events_lagged(&self, skipped: u64)

Source§

impl FlowEventHub for CoreState

Source§

impl FlowReadService for CoreState

Source§

fn get_flow<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<Flow>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn search_flows<'life0, 'async_trait>( &'life0 self, query: FlowQuery, ) -> Pin<Box<dyn Future<Output = Vec<FlowSummary>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl InterceptService for CoreState

Source§

fn register_intercept<'life0, 'async_trait>( &'life0 self, key: String, tx: Sender<InterceptionResult>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn resolve_intercept_with_modifications_from<'life0, 'life1, 'async_trait>( &'life0 self, actor: AuditActor, key: String, action: &'life1 str, mods: Option<FlowModification>, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn is_flow_intercepted<'life0, 'async_trait>( &'life0 self, flow_id: String, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn intercept_snapshot<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CoreInterceptSnapshot> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl PolicyService for CoreState

Source§

fn policy_snapshot(&self) -> ProxyPolicy

Source§

fn update_policy_from( &self, actor: AuditActor, target: String, policy: ProxyPolicy, )

Source§

fn patch_policy_from( &self, actor: AuditActor, target: String, patch: ProxyPolicyPatch, )

Source§

impl RuleService for CoreState

Source§

fn get_rules<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<Rule>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_rule_engine<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<RuleEngine>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn upsert_rule_from<'life0, 'life1, 'async_trait>( &'life0 self, actor: AuditActor, operation: &'life1 str, target: String, details: Value, rule: Rule, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_rule_from<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, actor: AuditActor, operation: &'life1 str, target: String, details: Value, rule_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn create_mock_response_rule_from<'life0, 'async_trait>( &'life0 self, actor: AuditActor, target: String, details: Value, config: MockResponseRuleConfig, ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn create_intercept_rule_from<'life0, 'async_trait>( &'life0 self, actor: AuditActor, target: String, details: Value, config: InterceptRuleConfig, ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl RuntimeStatusService for CoreState

Source§

fn status_snapshot(&self) -> CoreStatusSnapshot

Source§

fn status_report<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CoreStatusReport> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_metrics<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CoreMetrics> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_metrics_prometheus_text<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn subscribe_lifecycle(&self) -> Receiver<RuntimeLifecycle>

Source§

impl ScriptService for CoreState

Source§

fn load_script_from<'life0, 'life1, 'async_trait>( &'life0 self, actor: AuditActor, target: String, script: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more