notify/server_config.go

175 lines
4.4 KiB
Go
Raw Permalink Normal View History

package notify
import "context"
func (s *ServerCommon) DebugMode(dmg bool) {
s.mu.Lock()
s.debugMode = dmg
s.mu.Unlock()
}
func (s *ServerCommon) IsDebugMode() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.debugMode
}
func (s *ServerCommon) ShowError(std bool) {
s.mu.Lock()
s.showError = std
s.mu.Unlock()
}
func (s *ServerCommon) Stop() error {
if !sessionIsAlive(&s.alive) {
return nil
}
s.markSessionStopped("recv stop signal from user", nil)
return nil
}
// Deprecated: SetDefaultCommEncode overrides the transport codec directly.
// Prefer UseModernPSKServer or UseLegacySecurityServer.
func (s *ServerCommon) SetDefaultCommEncode(fn func([]byte, []byte) []byte) {
profile := transportProtectionProfile{
mode: ProtectionManaged,
msgEn: fn,
msgDe: s.defaultMsgDe,
secretKey: s.SecretKey,
}
s.setServerDefaultTransportProtectionProfile(profile)
s.clearServerSecurityProfiles()
s.securityReadyCheck = false
}
// Deprecated: SetDefaultCommDecode overrides the transport codec directly.
// Prefer UseModernPSKServer or UseLegacySecurityServer.
func (s *ServerCommon) SetDefaultCommDecode(fn func([]byte, []byte) []byte) {
profile := transportProtectionProfile{
mode: ProtectionManaged,
msgEn: s.defaultMsgEn,
msgDe: fn,
secretKey: s.SecretKey,
}
s.setServerDefaultTransportProtectionProfile(profile)
s.clearServerSecurityProfiles()
s.securityReadyCheck = false
}
func (s *ServerCommon) SetDefaultLink(fn func(message *Message)) {
s.defaultFns = fn
}
func (s *ServerCommon) SetLink(key string, fn func(*Message)) {
s.mu.Lock()
defer s.mu.Unlock()
s.linkFns[key] = fn
}
func (s *ServerCommon) SetFileHandler(fn func(FileEvent)) {
s.mu.Lock()
defer s.mu.Unlock()
s.onFileEvent = normalizeFileEventCallback(fn)
}
func (s *ServerCommon) SetFileReceiveDir(dir string) error {
return s.getFileReceivePool().setDir(dir)
}
func (s *ServerCommon) SetTransferResumeStore(store TransferResumeStore) {
if runtime := s.getTransferRuntime(); runtime != nil {
runtime.setResumeStore(store)
}
}
func (s *ServerCommon) RecoverTransferSnapshots(ctx context.Context) error {
if runtime := s.getTransferRuntime(); runtime != nil {
return runtime.recover(ctx)
}
return nil
}
func (s *ServerCommon) StopMonitorChan() <-chan struct{} {
return sessionStopChan(s.serverStopContextSnapshot())
}
func (s *ServerCommon) Status() Status {
return sessionStatusValue(&s.mu, &s.status)
}
func (s *ServerCommon) GetSecretKey() []byte {
return s.SecretKey
}
// Deprecated: SetSecretKey injects a raw transport key directly.
// Prefer UseModernPSKServer or UseLegacySecurityServer.
func (s *ServerCommon) SetSecretKey(key []byte) {
profile := transportProtectionProfile{
mode: ProtectionManaged,
msgEn: s.defaultMsgEn,
msgDe: s.defaultMsgDe,
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
}
s.setServerDefaultTransportProtectionProfile(profile)
s.clearServerSecurityProfiles()
s.securityReadyCheck = len(key) == 0
}
// Deprecated: RsaPrivKey exposes the legacy RSA handshake key. Prefer UseModernPSKServer.
func (s *ServerCommon) RsaPrivKey() []byte {
return s.handshakeRsaKey
}
// Deprecated: SetRsaPrivKey configures the legacy RSA handshake key. Prefer UseModernPSKServer.
func (s *ServerCommon) SetRsaPrivKey(key []byte) {
s.handshakeRsaKey = key
}
func (s *ServerCommon) GetSequenceEn() func(interface{}) ([]byte, error) {
return s.sequenceEn
}
func (s *ServerCommon) SetSequenceEn(fn func(interface{}) ([]byte, error)) {
s.sequenceEn = fn
}
func (s *ServerCommon) GetSequenceDe() func([]byte) (interface{}, error) {
return s.sequenceDe
}
func (s *ServerCommon) SetSequenceDe(fn func([]byte) (interface{}, error)) {
s.sequenceDe = fn
}
func (s *ServerCommon) HeartbeatTimeoutSec() int64 {
return s.maxHeartbeatLostSeconds
}
func (s *ServerCommon) SetHeartbeatTimeoutSec(sec int64) {
s.mu.Lock()
defer s.mu.Unlock()
s.maxHeartbeatLostSeconds = sec
}
func (s *ServerCommon) DetachedClientKeepSec() int64 {
s.mu.RLock()
defer s.mu.RUnlock()
return s.detachedClientKeepSeconds
}
func (s *ServerCommon) SetDetachedClientKeepSec(sec int64) {
if sec < 0 {
sec = 0
}
s.mu.Lock()
defer s.mu.Unlock()
s.detachedClientKeepSeconds = sec
}