Files
notify/client_config.go
T
b612 1f2e74acca fix(notify): 修复传输生命周期竞态,完善背压与协议边界
- 完善 stream/bulk DataID 分配、预留和双向命名空间,修复并发打开及 dedicated/shared 回退时的 ID 冲突
- 将收发、回复、恢复任务和 sidecar 绑定原始会话与物理连接,防止重连后的旧消息误操作新连接
- 加强 close/reset 身份校验及实例移除检查,修复 dedicated attach 失败、通道引用和资源回收竞态
- 收紧批量发送器停止准入,确保在途入队完成后统一清理请求、缓冲区和等待者
- 修复 record 满队列死锁、取消时序号消耗及关闭竞态,确保关闭有界并返回真实错误
- 增加协商式 record 逻辑半关闭,保留反向 ACK;通过 reset 传递 RecordFailure,避免背压掩盖原始失败原因
- 补齐帧长度、批次数量、序号溢出和未确认窗口校验,提前拒绝超限数据并按字节预算拆批
- 为入站分发增加全局及单连接的条数、字节预算和阻塞背压,关闭时唤醒等待者,消除正常断连日志噪音
- 完善 bulk 窗口释放失败处理与传输诊断,补充并发、重连、背压、协议边界及真实 TCP 回归覆盖
2026-09-23 15:33:17 +08:00

181 lines
4.7 KiB
Go

package notify
import (
"context"
"time"
)
func (c *ClientCommon) DebugMode(dmg bool) {
c.mu.Lock()
c.debugMode = dmg
c.mu.Unlock()
}
func (c *ClientCommon) IsDebugMode() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.debugMode
}
// Deprecated: SkipExchangeKey only controls the legacy RSA-based key exchange.
func (c *ClientCommon) SkipExchangeKey() bool {
return c.skipKeyExchange
}
// Deprecated: SetSkipExchangeKey only controls the legacy RSA-based key exchange.
func (c *ClientCommon) SetSkipExchangeKey(val bool) {
c.skipKeyExchange = val
}
func (c *ClientCommon) ShowError(std bool) {
c.mu.Lock()
c.showError = std
c.mu.Unlock()
}
func (c *ClientCommon) SetDefaultLink(fn func(message *Message)) {
c.linkMu.Lock()
defer c.linkMu.Unlock()
c.defaultFns = fn
}
func (c *ClientCommon) SetLink(key string, fn func(*Message)) {
c.linkMu.Lock()
defer c.linkMu.Unlock()
c.linkFns[key] = fn
}
func (c *ClientCommon) SetFileHandler(fn func(FileEvent)) {
c.mu.Lock()
defer c.mu.Unlock()
c.onFileEvent = normalizeFileEventCallback(fn)
}
func (c *ClientCommon) SetFileReceiveDir(dir string) error {
return c.getFileReceivePool().setDir(dir)
}
func (c *ClientCommon) SetTransferResumeStore(store TransferResumeStore) {
if runtime := c.getTransferRuntime(); runtime != nil {
runtime.setResumeStore(store)
}
}
func (c *ClientCommon) RecoverTransferSnapshots(ctx context.Context) error {
if runtime := c.getTransferRuntime(); runtime != nil {
return runtime.recover(ctx)
}
return nil
}
func (c *ClientCommon) GetMsgEn() func([]byte, []byte) []byte {
return c.clientTransportProtectionSnapshot().msgEn
}
// Deprecated: SetMsgEn overrides the transport codec directly.
// Prefer UseModernPSKClient or UseLegacySecurityClient.
func (c *ClientCommon) SetMsgEn(fn func([]byte, []byte) []byte) {
profile := c.clientTransportProtectionSnapshot()
profile.mode = ProtectionManaged
profile.msgEn = fn
profile.fastStreamEncode = nil
profile.fastBulkEncode = nil
profile.fastPlainEncode = nil
profile.runtime = nil
c.setClientTransportProtectionProfile(profile)
c.clearClientSecurityProfiles()
c.securityReadyCheck = false
}
func (c *ClientCommon) GetMsgDe() func([]byte, []byte) []byte {
return c.clientTransportProtectionSnapshot().msgDe
}
// Deprecated: SetMsgDe overrides the transport codec directly.
// Prefer UseModernPSKClient or UseLegacySecurityClient.
func (c *ClientCommon) SetMsgDe(fn func([]byte, []byte) []byte) {
profile := c.clientTransportProtectionSnapshot()
profile.mode = ProtectionManaged
profile.msgDe = fn
profile.fastStreamEncode = nil
profile.fastBulkEncode = nil
profile.fastPlainEncode = nil
profile.runtime = nil
c.setClientTransportProtectionProfile(profile)
c.clearClientSecurityProfiles()
c.securityReadyCheck = false
}
func (c *ClientCommon) HeartbeatPeroid() time.Duration {
return c.heartbeatPeriod
}
func (c *ClientCommon) SetHeartbeatPeroid(duration time.Duration) {
c.heartbeatPeriod = duration
}
func (c *ClientCommon) GetSecretKey() []byte {
return c.clientTransportProtectionSnapshot().secretKey
}
// Deprecated: SetSecretKey injects a raw transport key directly.
// Prefer UseModernPSKClient or UseLegacySecurityClient.
func (c *ClientCommon) SetSecretKey(key []byte) {
profile := c.clientTransportProtectionSnapshot()
profile.mode = ProtectionManaged
profile.secretKey = cloneTransportProtectionKey(key)
if len(key) == 0 {
profile.runtime = nil
} else if runtime, err := newModernPSKCodecRuntime(key, defaultModernPSKAAD); err == nil {
profile.runtime = runtime
} else {
profile.runtime = nil
}
c.setClientTransportProtectionProfile(profile)
c.clearClientSecurityProfiles()
c.securityReadyCheck = len(key) == 0
c.skipKeyExchange = true
}
// Deprecated: RsaPubKey exposes the legacy RSA handshake key. Prefer UseModernPSKClient.
func (c *ClientCommon) RsaPubKey() []byte {
return c.handshakeRsaPubKey
}
// Deprecated: SetRsaPubKey configures the legacy RSA handshake key. Prefer UseModernPSKClient.
func (c *ClientCommon) SetRsaPubKey(key []byte) {
c.handshakeRsaPubKey = key
}
func (c *ClientCommon) Stop() error {
if !sessionIsAlive(&c.alive) {
return nil
}
c.stopClientSession("recv stop signal from user", nil)
return nil
}
func (c *ClientCommon) StopMonitorChan() <-chan struct{} {
return sessionStopChan(c.clientStopContextSnapshot())
}
func (c *ClientCommon) Status() Status {
return sessionStatusValue(&c.mu, &c.status)
}
func (c *ClientCommon) GetSequenceEn() func(interface{}) ([]byte, error) {
return c.sequenceEn
}
func (c *ClientCommon) SetSequenceEn(fn func(interface{}) ([]byte, error)) {
c.sequenceEn = fn
}
func (c *ClientCommon) GetSequenceDe() func([]byte) (interface{}, error) {
return c.sequenceDe
}
func (c *ClientCommon) SetSequenceDe(fn func([]byte) (interface{}, error)) {
c.sequenceDe = fn
}