Skip to main content

BackendConn

Struct BackendConn 

Source
pub struct BackendConn {
    pub user_id: AtomicU32,
    pub client_type: u8,
    pub client_ver: u16,
    pub lang_id: u8,
    /* private fields */
}
Expand description

后端连接

Fields§

§user_id: AtomicU32§client_type: u8§client_ver: u16§lang_id: u8

Implementations§

Source§

impl BackendConn

Source

pub const CONNECT_TIMEOUT: Duration

连接 TCP 的超时时间。

Linux 默认 tcp_syn_retries=6TcpStream::connect 等到 ETIMEDOUT 需要约 127 秒——用户启动 opend 时如果选到一个不通的 IP 就卡 2 分钟后 才报错 offline mode(某位 Rocky Linux 用户踩过)。加 10s 超时快速失败, 让上层(bridge.rs 的 connect 循环)有机会 fallback 到下一个候选 IP。

Source

pub const CLIENT_VER_FTGTW: u16 = 1030

Backend 侧可识别的 Rust OpenD 客户端版本号。

Rust OpenD 的后台诊断版本号。

该值与普通 C++ OpenD 拉开,便于后台排查时区分 Rust 链路。服务端若要求 version >= 800,低版本会返回 error_code=45 "当前应用版本过低"

Source

pub async fn connect(addr: &str, push_callback: PushCallback) -> Result<Self>

连接到后端服务器(带 10s 超时)

Source

pub async fn connect_race( addrs: &[String], push_callback: PushCallback, ) -> 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 字段。

Source

pub fn from_duplex( stream: DuplexStream, push_callback: PushCallback, ) -> Result<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() 不变。

Source

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 字段原始长度。

Source

pub fn set_sec_data(&self, val: u32)

设置 sec_data 初始值(登录成功后调用)

Source

pub fn set_client_ip(&self, ip: String)

设置登录响应里的客户端外网 IP。

Source

pub fn client_ip(&self) -> String

读取登录响应里的客户端外网 IP。

Source

pub async fn request(&self, cmd_id: u16, body: Vec<u8>) -> Result<NNFrame>

发送请求并等待响应

Source

pub async fn request_with_reserved( &self, cmd_id: u16, body: Vec<u8>, reserved: [u8; 10], ) -> Result<NNFrame>

发送请求并等待响应(带 header reserved 字段,用于行情命令传递市场类型)

Source

pub async fn send_fire_and_forget( &self, cmd_id: u16, body: Vec<u8>, ) -> Result<()>

发送无需等待响应的消息

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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, 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