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_shutdown_handler: Option<AdminShutdownHandler>,
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_shutdown_handler: Option<AdminShutdownHandler>v1.4.111 daemon admin shutdown handler(/api/admin/shutdown 用)
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
impl RestState
pub fn new( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, ) -> Self
pub fn with_key_store( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, key_store: Arc<KeyStore>, ) -> Self
Sourcepub fn with_auth(
router: Arc<RequestRouter>,
ws_broadcaster: Arc<WsBroadcaster>,
key_store: Arc<KeyStore>,
counters: Arc<RuntimeCounters>,
) -> Self
pub fn with_auth( router: Arc<RequestRouter>, ws_broadcaster: Arc<WsBroadcaster>, key_store: Arc<KeyStore>, counters: Arc<RuntimeCounters>, ) -> Self
v1.2 推荐入口:同时接 KeyStore + 共享 RuntimeCounters
Sourcepub fn with_filter_registry(self, registry: Arc<FilterRegistry>) -> Self
pub fn with_filter_registry(self, registry: Arc<FilterRegistry>) -> Self
v1.4.104 阶段 7-1: 注入显式 FilterRegistry (跨 surface 共享同一份). 默认 with_defaults 已注册 proto 2001; 此 setter 让调用方覆盖.
Sourcepub fn with_admin_status_provider(self, provider: AdminStatusProvider) -> Self
pub fn with_admin_status_provider(self, provider: AdminStatusProvider) -> Self
v1.4.32+ 注入 admin status provider(一般在 futu-opend main 里
注入一个捕获 Arc<GatewayBridge> 的 closure)。
Sourcepub fn with_admin_shutdown_handler(self, handler: AdminShutdownHandler) -> Self
pub fn with_admin_shutdown_handler(self, handler: AdminShutdownHandler) -> Self
v1.4.111 注入 admin shutdown handler。
Sourcepub fn with_admin_reload_handler(self, handler: AdminReloadHandler) -> Self
pub fn with_admin_reload_handler(self, handler: AdminReloadHandler) -> Self
v1.4.32+ 注入 admin reload handler
Sourcepub fn with_push_health_snapshot_provider(
self,
provider: PushHealthSnapshotProvider,
) -> Self
pub fn with_push_health_snapshot_provider( self, provider: PushHealthSnapshotProvider, ) -> Self
v1.4.83 §9 Phase 2 F5: 注入 push health snapshot provider.
Sourcepub fn with_card_num_resolver(self, resolver: CardNumResolver) -> Self
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).
Sourcepub fn next_conn_id(&self) -> u64
pub fn next_conn_id(&self) -> u64
分配虚拟连接 ID
Sourcepub fn next_serial(&self) -> u32
pub fn next_serial(&self) -> u32
分配序列号
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RestState
impl !UnwindSafe for RestState
impl Freeze for RestState
impl Send for RestState
impl Sync for RestState
impl Unpin for RestState
impl UnsafeUnpin for RestState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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