New feature: sleep mode

This commit is contained in:
Frank Denis 2022-03-31 20:51:34 +02:00
parent ed2c880648
commit e931b234b7
3 changed files with 16 additions and 0 deletions

View File

@ -49,6 +49,7 @@ type Config struct {
BlockIPv6 bool `toml:"block_ipv6"`
BlockUnqualified bool `toml:"block_unqualified"`
BlockUndelegated bool `toml:"block_undelegated"`
SleepMode bool `toml:"sleep_mode"`
Cache bool
CacheSize int `toml:"cache_size"`
CacheNegTTL uint32 `toml:"cache_neg_ttl"`
@ -474,6 +475,8 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
proxy.pluginBlockIPv6 = config.BlockIPv6
proxy.pluginBlockUnqualified = config.BlockUnqualified
proxy.pluginBlockUndelegated = config.BlockUndelegated
proxy.sleepMode = config.SleepMode
proxy.cache = config.Cache
proxy.cacheSize = config.CacheSize

View File

@ -55,6 +55,11 @@ max_clients = 250
# user_name = 'nobody'
## Sleep mode: add an incremental delay to queries so that you eventually get some sleep instead of watching videos all night long.
sleep_mode = false
## Require servers (from remote sources) to satisfy specific properties
# Use servers reachable over IPv4

View File

@ -71,6 +71,7 @@ type Proxy struct {
certRefreshDelayAfterFailure time.Duration
timeout time.Duration
certRefreshDelay time.Duration
sleepDelay time.Duration
cacheSize int
logMaxBackups int
logMaxAge int
@ -94,6 +95,7 @@ type Proxy struct {
anonDirectCertFallback bool
pluginBlockUndelegated bool
child bool
sleepMode bool
requiredProps stamps.ServerInformalProperties
ServerNames []string
DisabledServerNames []string
@ -617,6 +619,12 @@ func (proxy *Proxy) processIncomingQuery(
if len(query) < MinDNSPacketSize {
return response
}
if proxy.sleepMode {
time.Sleep(proxy.sleepDelay)
proxy.sleepDelay += 10 * time.Microsecond
}
pluginsState := NewPluginsState(proxy, clientProto, clientAddr, serverProto, start)
serverName := "-"
needsEDNS0Padding := false