Skip to main content

RestState

Struct RestState 

Source
pub struct RestState {
    pub router: Arc<RequestRouter>,
    pub ws_broadcaster: Arc<WsBroadcaster>,
    pub key_store: Arc<KeyStore>,
    pub counters: Arc<RuntimeCounters>,
    pub filter_registry: Arc<FilterRegistry>,
    pub admin_status_provider: Option<AdminStatusProvider>,
    pub admin_reload_handler: Option<AdminReloadHandler>,
    pub push_health_snapshot_provider: Option<PushHealthSnapshotProvider>,
    pub card_num_resolver: Option<CardNumResolver>,
    pub rest_acc_subscriptions: Arc<RwLock<HashMap<String, HashSet<u64>>>>,
    /* private fields */
}
Expand description

REST 服务共享状态

Fields§

§router: Arc<RequestRouter>

复用 OpenD 的请求路由器

§ws_broadcaster: Arc<WsBroadcaster>

WebSocket 推送广播器

§key_store: Arc<KeyStore>

Bearer Token KeyStore(未配置 → is_configured() == false,WS 握手也放行)

§counters: Arc<RuntimeCounters>

v1.2:handler 层 full CheckCtx 用的限额计数器(与 auth middleware 共享同一份 Arc,rate window 跨 auth/handler 一致)

§filter_registry: Arc<FilterRegistry>

v1.4.104 阶段 7-1: 跨 surface response filter 注册表 (proto 2001 TRD_GET_ACC_LIST 默认装入). 替代 routes/trd.rs::get_acc_list 内联 JSON-level filter (35 LoC), 走 proto-bytes-level filter unified with gRPC + WS surface (FilterRegistry::apply). 加新 filter 只在 registry 注册一次, 4 surface 自动生效.

§admin_status_provider: Option<AdminStatusProvider>

v1.4.32+ daemon admin 状态快照 provider(/api/admin/status 用)

§admin_reload_handler: Option<AdminReloadHandler>

v1.4.32+ daemon admin reload handler(/api/admin/reload 用)

§push_health_snapshot_provider: Option<PushHealthSnapshotProvider>

v1.4.83 §9 Phase 2 F5: Push channel health snapshot provider (/api/push-subscriber-info 真实 state — 不是 stub 文案)

§card_num_resolver: Option<CardNumResolver>

v1.4.105 D12 (Phase 2): card_num → acc_ids 解析器, REST trade handler 在 dispatch 前用于解析 user 传 card_num 字段 → acc_id. 未注入 → trade endpoint 收到 card_num 字段时 503 reject (loud — 让 user 知道 daemon 配置问题, 不 silent fall back acc_id).

§rest_acc_subscriptions: Arc<RwLock<HashMap<String, HashSet<u64>>>>

v1.4.102 codex 46 F2/F3 (P1): REST sub-acc-push 状态 (per API key).

之前 REST sub-acc-push 透 dispatch 到 gateway SubscriptionManager 但用 REST 临时虚拟 conn_id, unsub 用新 conn_id 删不到; 即使 sub OK, REST WsBroadcaster 也没基于这个 state 过滤 trade push (只按 scope), 等于 所有 acc:read 持有者收所有 trade push, sub-acc-push/unsub-acc-push 是空操作.

此 map 是 REST 层 per-key acc subscription 真相源:

  • /api/sub-acc-push 写入 (key_id → set of acc_id)
  • /api/unsub-acc-push 删除
  • WsBroadcaster trade push delivery 检查: key 已 sub 此 acc 才 forward

None (key 未 sub-acc-push) → 默认 deliver 所有 acc:read scope 的 push (向后兼容, 兼容未升级老 client).

Implementations§

Source§

impl RestState

Source

pub fn new( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, ) -> Self

Source

pub fn with_key_store( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, key_store: Arc<KeyStore>, ) -> Self

Source

pub fn with_auth( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, key_store: Arc<KeyStore>, counters: Arc<RuntimeCounters>, ) -> Self

v1.2 推荐入口:同时接 KeyStore + 共享 RuntimeCounters

Source

pub fn with_filter_registry(self, registry: Arc<FilterRegistry>) -> Self

v1.4.104 阶段 7-1: 注入显式 FilterRegistry (跨 surface 共享同一份). 默认 with_defaults 已注册 proto 2001; 此 setter 让调用方覆盖.

Source

pub fn with_admin_status_provider(self, provider: AdminStatusProvider) -> Self

v1.4.32+ 注入 admin status provider(一般在 futu-opend main 里 注入一个捕获 Arc<GatewayBridge> 的 closure)。

Source

pub fn with_admin_reload_handler(self, handler: AdminReloadHandler) -> Self

v1.4.32+ 注入 admin reload handler

Source

pub fn with_push_health_snapshot_provider( self, provider: PushHealthSnapshotProvider, ) -> Self

v1.4.83 §9 Phase 2 F5: 注入 push health snapshot provider.

Source

pub fn with_card_num_resolver(self, resolver: CardNumResolver) -> Self

v1.4.105 D12 (Phase 2): 注入 card_num → acc_ids 解析器 closure. opend 启动时由 main.rs 注入捕获 bridge.caches.trd_cache 的 closure. 未注入 → trade endpoint 收 card_num 字段时 503 reject (loud).

Source

pub fn next_conn_id(&self) -> u64

分配虚拟连接 ID

Source

pub fn next_serial(&self) -> u32

分配序列号

Trait Implementations§

Source§

impl Clone for RestState

Source§

fn clone(&self) -> RestState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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