- 新增 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 文档
175 lines
4.4 KiB
Go
175 lines
4.4 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) {
|
|
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
|
|
}
|