156 lines
3.8 KiB
Go
156 lines
3.8 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.msgEn
|
||
|
|
}
|
||
|
|
|
||
|
|
// Deprecated: SetMsgEn overrides the transport codec directly.
|
||
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
||
|
|
func (c *ClientCommon) SetMsgEn(fn func([]byte, []byte) []byte) {
|
||
|
|
c.msgEn = fn
|
||
|
|
c.fastStreamEncode = nil
|
||
|
|
c.fastBulkEncode = nil
|
||
|
|
c.fastPlainEncode = nil
|
||
|
|
c.securityReadyCheck = false
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *ClientCommon) GetMsgDe() func([]byte, []byte) []byte {
|
||
|
|
return c.msgDe
|
||
|
|
}
|
||
|
|
|
||
|
|
// Deprecated: SetMsgDe overrides the transport codec directly.
|
||
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
||
|
|
func (c *ClientCommon) SetMsgDe(fn func([]byte, []byte) []byte) {
|
||
|
|
c.msgDe = fn
|
||
|
|
c.fastStreamEncode = nil
|
||
|
|
c.fastBulkEncode = nil
|
||
|
|
c.fastPlainEncode = nil
|
||
|
|
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.SecretKey
|
||
|
|
}
|
||
|
|
|
||
|
|
// Deprecated: SetSecretKey injects a raw transport key directly.
|
||
|
|
// Prefer UseModernPSKClient or UseLegacySecurityClient.
|
||
|
|
func (c *ClientCommon) SetSecretKey(key []byte) {
|
||
|
|
c.SecretKey = key
|
||
|
|
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
|
||
|
|
}
|