2026-04-15 15:24:36 +08:00
|
|
|
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 {
|
2026-04-20 16:35:44 +08:00
|
|
|
return c.clientTransportProtectionSnapshot().msgEn
|
2026-04-15 15:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deprecated: SetMsgEn overrides the transport codec directly.
|
|
|
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
|
|
|
|
func (c *ClientCommon) SetMsgEn(fn func([]byte, []byte) []byte) {
|
2026-04-20 16:35:44 +08:00
|
|
|
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()
|
2026-04-15 15:24:36 +08:00
|
|
|
c.securityReadyCheck = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientCommon) GetMsgDe() func([]byte, []byte) []byte {
|
2026-04-20 16:35:44 +08:00
|
|
|
return c.clientTransportProtectionSnapshot().msgDe
|
2026-04-15 15:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deprecated: SetMsgDe overrides the transport codec directly.
|
|
|
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
|
|
|
|
func (c *ClientCommon) SetMsgDe(fn func([]byte, []byte) []byte) {
|
2026-04-20 16:35:44 +08:00
|
|
|
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()
|
2026-04-15 15:24:36 +08:00
|
|
|
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 {
|
2026-04-20 16:35:44 +08:00
|
|
|
return c.clientTransportProtectionSnapshot().secretKey
|
2026-04-15 15:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deprecated: SetSecretKey injects a raw transport key directly.
|
|
|
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
|
|
|
|
func (c *ClientCommon) SetSecretKey(key []byte) {
|
2026-04-20 16:35:44 +08:00
|
|
|
profile := c.clientTransportProtectionSnapshot()
|
|
|
|
|
profile.mode = ProtectionManaged
|
|
|
|
|
profile.secretKey = cloneTransportProtectionKey(key)
|
2026-04-18 16:05:57 +08:00
|
|
|
if len(key) == 0 {
|
2026-04-20 16:35:44 +08:00
|
|
|
profile.runtime = nil
|
2026-04-18 16:05:57 +08:00
|
|
|
} else if runtime, err := newModernPSKCodecRuntime(key, defaultModernPSKAAD); err == nil {
|
2026-04-20 16:35:44 +08:00
|
|
|
profile.runtime = runtime
|
2026-04-18 16:05:57 +08:00
|
|
|
} else {
|
2026-04-20 16:35:44 +08:00
|
|
|
profile.runtime = nil
|
2026-04-18 16:05:57 +08:00
|
|
|
}
|
2026-04-20 16:35:44 +08:00
|
|
|
c.setClientTransportProtectionProfile(profile)
|
|
|
|
|
c.clearClientSecurityProfiles()
|
2026-04-15 15:24:36 +08:00
|
|
|
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
|
|
|
|
|
}
|