153 lines
3.7 KiB
Go
153 lines
3.7 KiB
Go
|
|
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) {
|
||
|
|
s.defaultMsgEn = fn
|
||
|
|
s.defaultFastStreamEncode = nil
|
||
|
|
s.defaultFastBulkEncode = nil
|
||
|
|
s.defaultFastPlainEncode = nil
|
||
|
|
s.securityReadyCheck = false
|
||
|
|
}
|
||
|
|
|
||
|
|
// Deprecated: SetDefaultCommDecode overrides the transport codec directly.
|
||
|
|
// Prefer UseModernPSKServer or UseLegacySecurityServer.
|
||
|
|
func (s *ServerCommon) SetDefaultCommDecode(fn func([]byte, []byte) []byte) {
|
||
|
|
s.defaultMsgDe = fn
|
||
|
|
s.defaultFastStreamEncode = nil
|
||
|
|
s.defaultFastBulkEncode = nil
|
||
|
|
s.defaultFastPlainEncode = nil
|
||
|
|
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) {
|
||
|
|
s.SecretKey = key
|
||
|
|
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
|
||
|
|
}
|