pub struct BackendConn {
pub user_id: AtomicU32,
pub client_ver: u16,
/* private fields */
}Expand description
后端连接
Fields§
§user_id: AtomicU32§client_ver: u16Implementations§
Source§impl BackendConn
impl BackendConn
Source§impl BackendConn
impl BackendConn
pub fn pending_request_count_for_test(&self) -> usize
Source§impl BackendConn
impl BackendConn
Sourcepub const CONNECT_TIMEOUT: Duration
pub const CONNECT_TIMEOUT: Duration
连接 TCP 的超时时间。
Linux 默认 tcp_syn_retries=6 时 TcpStream::connect 等到 ETIMEDOUT
需要约 127 秒——用户启动 opend 时如果选到一个不通的 IP 就卡 2 分钟后
才报错 offline mode(某位 Rocky Linux 用户踩过)。加 10s 超时快速失败,
让上层(bridge.rs 的 connect 循环)有机会 fallback 到下一个候选 IP。
Sourcepub const CLIENT_VER_FTGTW: u16 = 1031
pub const CLIENT_VER_FTGTW: u16 = 1031
Backend 侧可识别的 Rust OpenD 固定客户端版本号。
C++ 同时把 AppConfig::GetClientVersion() 写入 protocol header 与
ReqEncryptData.client_ex_ver;为便于后台识别,Rust OpenD 于 2026-07-14
将识别版本提升为 1031。该身份在首次建连和鉴权请求发出前必须已知,
不能从服务端动态配置取得;尚未识别 1031 的 backend 环境可能拒绝登录。
若后台重新分配版本,
只更新本常量,并由契约测试保证所有 wire/HTTP 出口同步变化。
Ref: f3c/FTNet/Src/ftnet/channel/impl/protocol_header.cpp:25-32 and
f3c/FTlogin/Src/ftlogin/login/logger.cpp:304-310.
Sourcepub async fn connect(
addr: &str,
push_callback: PushCallback,
protocol_identity: BackendProtocolIdentity,
) -> Result<Self>
pub async fn connect( addr: &str, push_callback: PushCallback, protocol_identity: BackendProtocolIdentity, ) -> Result<Self>
连接到后端服务器(带 10s 超时)
Sourcepub async fn connect_race(
addrs: &[String],
push_callback: PushCallback,
protocol_identity: BackendProtocolIdentity,
) -> Result<(Self, String)>
pub async fn connect_race( addrs: &[String], push_callback: PushCallback, protocol_identity: BackendProtocolIdentity, ) -> Result<(Self, String)>
并发连接多个候选地址,谁先通用谁(对齐 C++ connector.cpp:175-189
ConnectStrategyAddr 的 concurrency_ip 语义)。
- 每个候选独立带
CONNECT_TIMEOUT(10s)超时 - 第一个
Ok(stream)胜出,其余 pending task drop 时会关闭半连接 - 全部失败返回最后一个错误
返回 (BackendConn, winner_addr),调用方用 winner_addr 做登录协议里的
host_ip/host_port 字段。
Sourcepub fn from_duplex(
stream: DuplexStream,
push_callback: PushCallback,
protocol_identity: BackendProtocolIdentity,
) -> Self
pub fn from_duplex( stream: DuplexStream, push_callback: PushCallback, protocol_identity: BackendProtocolIdentity, ) -> Self
v1.4.70 D1: test-only 从 tokio::io::DuplexStream 构造 BackendConn
用于 integration tests(crates/futu-gateway/tests/common/mock_backend.rs)
替代真 TcpStream。生产路径通过 connect() → from_stream() 不变。
pub const fn protocol_identity(&self) -> BackendProtocolIdentity
Sourcepub fn set_session_key(&self, key: Vec<u8>)
pub fn set_session_key(&self, key: Vec<u8>)
设置 session key(登录成功后调用)。接受变长字节,16/24/32 分别对应
AES-128/192/256。对齐 C++ Logger::session_key_ 是 std::string,
长度取决于服务端下发的 RspEncryptData.session_key 字段原始长度。
Sourcepub fn set_sec_data(&self, val: u32)
pub fn set_sec_data(&self, val: u32)
设置 sec_data 初始值(登录成功后调用)
Sourcepub fn apply_login_sec_data(&self, val: Option<u32>)
pub fn apply_login_sec_data(&self, val: Option<u32>)
应用登录响应里的 sec_data。
C++ 只有在 RspEncryptData.has_sec_data() 时更新 secure_num_;
字段缺失时保留当前计数,避免 reconnect/login 响应裁剪时把安全数回退。
Ref: f3c/FTlogin/Src/ftlogin/login/logger.cpp:553-555.
Sourcepub fn set_client_ip(&self, ip: String)
pub fn set_client_ip(&self, ip: String)
设置登录响应里的客户端外网 IP。
Sourcepub fn connection_generation(&self) -> u64
pub fn connection_generation(&self) -> u64
Immutable identity of this transport instance, included with every backend push so consumers can reject delivery from a retired route.
pub fn pause_writer_admission_for_test(&self) -> LifecyclePauseHook
pub fn is_connected(&self) -> bool
Sourcepub fn subscribe_connection_state(&self) -> Receiver<bool>
pub fn subscribe_connection_state(&self) -> Receiver<bool>
Subscribe to low-level connection liveness changes.
C++ FTLogin publishes a connection-closed event immediately
(GTWCmdAndPushReply::OMEvProc_ConnClosed) and lets the gateway enter
reconnecting state without waiting for a later business request. Rust
uses this watch channel to wake the reconnect monitor as soon as the
recv/send task marks the TCP channel disconnected.
Sourcepub fn mark_disconnected_for_reconnect(&self, reason: &'static str)
pub fn mark_disconnected_for_reconnect(&self, reason: &'static str)
Mark this connection disconnected so owner-side reconnect loops stop routing business requests through a stale session.
Used when a higher-level channel event invalidates the session semantics even if the TCP socket has not closed yet. C++ channel state transitions publish disconnect/re-establish events; Rust exposes the same liveness edge through the existing connection-state watch channel.
Trait Implementations§
Source§impl Drop for BackendConn
impl Drop for BackendConn
Auto Trait Implementations§
impl !Freeze for BackendConn
impl !RefUnwindSafe for BackendConn
impl !UnwindSafe for BackendConn
impl Send for BackendConn
impl Sync for BackendConn
impl Unpin for BackendConn
impl UnsafeUnpin for BackendConn
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
§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