dnscrypt-proxy/estimators.go

30 lines
811 B
Go
Raw Normal View History

2018-01-09 16:40:37 +01:00
package main
import "sync"
type QuestionSizeEstimator struct {
sync.RWMutex
minQuestionSize int
}
func NewQuestionSizeEstimator() QuestionSizeEstimator {
return QuestionSizeEstimator{minQuestionSize: InitialMinQuestionSize}
}
func (questionSizeEstimator *QuestionSizeEstimator) MinQuestionSize() int {
questionSizeEstimator.RLock()
minQuestionSize := questionSizeEstimator.minQuestionSize
questionSizeEstimator.RUnlock()
return minQuestionSize
}
func (questionSizeEstimator *QuestionSizeEstimator) blindAdjust() {
questionSizeEstimator.Lock()
if MaxDNSPacketSize-questionSizeEstimator.minQuestionSize < questionSizeEstimator.minQuestionSize {
questionSizeEstimator.minQuestionSize = MaxDNSUDPPacketSize
} else {
questionSizeEstimator.minQuestionSize *= 2
}
questionSizeEstimator.Unlock()
}