notify/client_config.go
starainrt 98ef9e7fcc
feat(transport): 完成安全架构拆分并收口 stream/bulk 传输优化
- 新增 managed/external/nested 三种传输保护模式
  - 新增 peer attach 显式认证、抗重放、channel binding 和可选前向保密协商
  - 明确单连接注入与可重拨连接源的语义边界
  - 禁止 ConnectByConn 场景下 dedicated bulk 走 sidecar,auto 模式自动回退 shared
  - 修正 dedicated attach 在 bootstrap/steady profile 切换下的处理逻辑
  - 优化 shared bulk super-batch 与批量 framed write 路径
  - 降低 stream/bulk fast path 的复制和分发损耗
  - 补齐 benchmark、回归测试、运行时快照和 README 文档
2026-04-20 16:35:44 +08:00

177 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 {
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.defaultFns = fn
}
func (c *ClientCommon) SetLink(key string, fn func(*Message)) {
c.mu.Lock()
defer c.mu.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
}