82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
|
|
package notify
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
const defaultFileSendRetry = 3
|
||
|
|
|
||
|
|
const defaultFileAckTimeout = 5 * time.Second
|
||
|
|
|
||
|
|
type fileTransferConfig struct {
|
||
|
|
ChunkSize int
|
||
|
|
AckTimeout time.Duration
|
||
|
|
SendRetry int
|
||
|
|
ReceiveCompletedLimit int
|
||
|
|
MonitorCompletedLimit int
|
||
|
|
}
|
||
|
|
|
||
|
|
func defaultFileTransferConfig() fileTransferConfig {
|
||
|
|
return fileTransferConfig{
|
||
|
|
ChunkSize: defaultFileChunkSize,
|
||
|
|
AckTimeout: defaultFileAckTimeout,
|
||
|
|
SendRetry: defaultFileSendRetry,
|
||
|
|
ReceiveCompletedLimit: defaultFileReceiveCompletedLimit,
|
||
|
|
MonitorCompletedLimit: defaultFileTransferCompletedLimit,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func normalizeFileTransferConfig(cfg fileTransferConfig) fileTransferConfig {
|
||
|
|
defaults := defaultFileTransferConfig()
|
||
|
|
if cfg.ChunkSize <= 0 {
|
||
|
|
cfg.ChunkSize = defaults.ChunkSize
|
||
|
|
}
|
||
|
|
if cfg.AckTimeout <= 0 {
|
||
|
|
cfg.AckTimeout = defaults.AckTimeout
|
||
|
|
}
|
||
|
|
if cfg.SendRetry <= 0 {
|
||
|
|
cfg.SendRetry = defaults.SendRetry
|
||
|
|
}
|
||
|
|
if cfg.ReceiveCompletedLimit <= 0 {
|
||
|
|
cfg.ReceiveCompletedLimit = defaults.ReceiveCompletedLimit
|
||
|
|
}
|
||
|
|
if cfg.MonitorCompletedLimit <= 0 {
|
||
|
|
cfg.MonitorCompletedLimit = defaults.MonitorCompletedLimit
|
||
|
|
}
|
||
|
|
return cfg
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *ClientCommon) getFileTransferConfig() fileTransferConfig {
|
||
|
|
c.mu.Lock()
|
||
|
|
defer c.mu.Unlock()
|
||
|
|
c.fileTransferCfg = normalizeFileTransferConfig(c.fileTransferCfg)
|
||
|
|
return c.fileTransferCfg
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *ServerCommon) getFileTransferConfig() fileTransferConfig {
|
||
|
|
s.mu.Lock()
|
||
|
|
defer s.mu.Unlock()
|
||
|
|
s.fileTransferCfg = normalizeFileTransferConfig(s.fileTransferCfg)
|
||
|
|
return s.fileTransferCfg
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *ClientCommon) setFileTransferConfig(cfg fileTransferConfig) {
|
||
|
|
cfg = normalizeFileTransferConfig(cfg)
|
||
|
|
c.mu.Lock()
|
||
|
|
c.fileTransferCfg = cfg
|
||
|
|
state := c.logicalSession
|
||
|
|
c.mu.Unlock()
|
||
|
|
if state != nil {
|
||
|
|
state.applyFileTransferConfig(cfg)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *ServerCommon) setFileTransferConfig(cfg fileTransferConfig) {
|
||
|
|
cfg = normalizeFileTransferConfig(cfg)
|
||
|
|
s.mu.Lock()
|
||
|
|
s.fileTransferCfg = cfg
|
||
|
|
state := s.logicalSession
|
||
|
|
s.mu.Unlock()
|
||
|
|
if state != nil {
|
||
|
|
state.applyFileTransferConfig(cfg)
|
||
|
|
}
|
||
|
|
}
|