Skip to content

Commit e931b23

Browse files
committed
New feature: sleep mode
1 parent ed2c880 commit e931b23

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

dnscrypt-proxy/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
BlockIPv6 bool `toml:"block_ipv6"`
5050
BlockUnqualified bool `toml:"block_unqualified"`
5151
BlockUndelegated bool `toml:"block_undelegated"`
52+
SleepMode bool `toml:"sleep_mode"`
5253
Cache bool
5354
CacheSize int `toml:"cache_size"`
5455
CacheNegTTL uint32 `toml:"cache_neg_ttl"`
@@ -474,6 +475,8 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
474475
proxy.pluginBlockIPv6 = config.BlockIPv6
475476
proxy.pluginBlockUnqualified = config.BlockUnqualified
476477
proxy.pluginBlockUndelegated = config.BlockUndelegated
478+
proxy.sleepMode = config.SleepMode
479+
477480
proxy.cache = config.Cache
478481
proxy.cacheSize = config.CacheSize
479482

dnscrypt-proxy/example-dnscrypt-proxy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ max_clients = 250
5555
# user_name = 'nobody'
5656

5757

58+
## Sleep mode: add an incremental delay to queries so that you eventually get some sleep instead of watching videos all night long.
59+
60+
sleep_mode = false
61+
62+
5863
## Require servers (from remote sources) to satisfy specific properties
5964

6065
# Use servers reachable over IPv4

dnscrypt-proxy/proxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Proxy struct {
7171
certRefreshDelayAfterFailure time.Duration
7272
timeout time.Duration
7373
certRefreshDelay time.Duration
74+
sleepDelay time.Duration
7475
cacheSize int
7576
logMaxBackups int
7677
logMaxAge int
@@ -94,6 +95,7 @@ type Proxy struct {
9495
anonDirectCertFallback bool
9596
pluginBlockUndelegated bool
9697
child bool
98+
sleepMode bool
9799
requiredProps stamps.ServerInformalProperties
98100
ServerNames []string
99101
DisabledServerNames []string
@@ -617,6 +619,12 @@ func (proxy *Proxy) processIncomingQuery(
617619
if len(query) < MinDNSPacketSize {
618620
return response
619621
}
622+
623+
if proxy.sleepMode {
624+
time.Sleep(proxy.sleepDelay)
625+
proxy.sleepDelay += 10 * time.Microsecond
626+
}
627+
620628
pluginsState := NewPluginsState(proxy, clientProto, clientAddr, serverProto, start)
621629
serverName := "-"
622630
needsEDNS0Padding := false

0 commit comments

Comments
 (0)