parent
4a3be6086e
commit
c73e95256d
|
@ -70,6 +70,7 @@ type Config struct {
|
||||||
TLSCipherSuite []uint16 `toml:"tls_cipher_suite"`
|
TLSCipherSuite []uint16 `toml:"tls_cipher_suite"`
|
||||||
NetprobeAddress string `toml:"netprobe_address"`
|
NetprobeAddress string `toml:"netprobe_address"`
|
||||||
NetprobeTimeout int `toml:"netprobe_timeout"`
|
NetprobeTimeout int `toml:"netprobe_timeout"`
|
||||||
|
OfflineMode bool `toml:"offline_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfig() Config {
|
func newConfig() Config {
|
||||||
|
@ -104,6 +105,7 @@ func newConfig() Config {
|
||||||
TLSCipherSuite: nil,
|
TLSCipherSuite: nil,
|
||||||
NetprobeAddress: "9.9.9.9:53",
|
NetprobeAddress: "9.9.9.9:53",
|
||||||
NetprobeTimeout: 30,
|
NetprobeTimeout: 30,
|
||||||
|
OfflineMode: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,13 +399,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
netProbe(config.NetprobeAddress, config.NetprobeTimeout)
|
netProbe(config.NetprobeAddress, config.NetprobeTimeout)
|
||||||
|
if !config.OfflineMode {
|
||||||
if err := config.loadSources(proxy); err != nil {
|
if err := config.loadSources(proxy); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(proxy.registeredServers) == 0 {
|
if len(proxy.registeredServers) == 0 {
|
||||||
return errors.New("No servers configured")
|
return errors.New("No servers configured")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if *list || *listAll {
|
if *list || *listAll {
|
||||||
config.printRegisteredServers(proxy, *jsonOutput)
|
config.printRegisteredServers(proxy, *jsonOutput)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -186,6 +186,13 @@ ignore_system_dns = false
|
||||||
netprobe_timeout = 30
|
netprobe_timeout = 30
|
||||||
|
|
||||||
|
|
||||||
|
## Offline mode - Do not use any remote encrypted servers.
|
||||||
|
## The proxy will remain fully functional to respond to queries that
|
||||||
|
## plugins can handle directly (forwarding, cloaking, ...)
|
||||||
|
|
||||||
|
# offline_mode = false
|
||||||
|
|
||||||
|
|
||||||
## Automatic log files rotation
|
## Automatic log files rotation
|
||||||
|
|
||||||
# Maximum log files size in MB
|
# Maximum log files size in MB
|
||||||
|
|
|
@ -3,9 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ func (proxy *Proxy) StartProxy() {
|
||||||
dlog.Notice("dnscrypt-proxy is waiting for at least one server to be reachable")
|
dlog.Notice("dnscrypt-proxy is waiting for at least one server to be reachable")
|
||||||
}
|
}
|
||||||
proxy.prefetcher(&proxy.urlsToPrefetch)
|
proxy.prefetcher(&proxy.urlsToPrefetch)
|
||||||
|
if len(proxy.serversInfo.registeredServers) > 0 {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
delay := proxy.certRefreshDelay
|
delay := proxy.certRefreshDelay
|
||||||
|
@ -170,6 +171,7 @@ func (proxy *Proxy) StartProxy() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) prefetcher(urlsToPrefetch *[]URLToPrefetch) {
|
func (proxy *Proxy) prefetcher(urlsToPrefetch *[]URLToPrefetch) {
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -318,7 +320,7 @@ func (proxy *Proxy) clientsCountDec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn) {
|
func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn) {
|
||||||
if len(query) < MinDNSPacketSize || serverInfo == nil {
|
if len(query) < MinDNSPacketSize {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pluginsState := NewPluginsState(proxy, clientProto, clientAddr)
|
pluginsState := NewPluginsState(proxy, clientProto, clientAddr)
|
||||||
|
@ -342,7 +344,7 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
||||||
} else {
|
} else {
|
||||||
pluginsState.returnCode = PluginsReturnCodeForward
|
pluginsState.returnCode = PluginsReturnCodeForward
|
||||||
}
|
}
|
||||||
if len(response) == 0 {
|
if len(response) == 0 && serverInfo != nil {
|
||||||
var ttl *uint32
|
var ttl *uint32
|
||||||
if serverInfo.Proto == stamps.StampProtoTypeDNSCrypt {
|
if serverInfo.Proto == stamps.StampProtoTypeDNSCrypt {
|
||||||
sharedKey, encryptedQuery, clientNonce, err := proxy.Encrypt(serverInfo, query, serverProto)
|
sharedKey, encryptedQuery, clientNonce, err := proxy.Encrypt(serverInfo, query, serverProto)
|
||||||
|
@ -408,6 +410,14 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
||||||
serverInfo.noticeSuccess(proxy)
|
serverInfo.noticeSuccess(proxy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(response) < MinDNSPacketSize || len(response) > MaxDNSPacketSize {
|
||||||
|
pluginsState.returnCode = PluginsReturnCodeParseError
|
||||||
|
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
|
||||||
|
if serverInfo != nil {
|
||||||
|
serverInfo.noticeFailure(proxy)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
if clientProto == "udp" {
|
if clientProto == "udp" {
|
||||||
if len(response) > MaxDNSUDPPacketSize {
|
if len(response) > MaxDNSUDPPacketSize {
|
||||||
response, err = TruncatedResponse(response)
|
response, err = TruncatedResponse(response)
|
||||||
|
@ -428,7 +438,9 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pluginsState.returnCode = PluginsReturnCodeParseError
|
pluginsState.returnCode = PluginsReturnCodeParseError
|
||||||
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
|
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
|
||||||
|
if serverInfo != nil {
|
||||||
serverInfo.noticeFailure(proxy)
|
serverInfo.noticeFailure(proxy)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clientPc.Write(response)
|
clientPc.Write(response)
|
||||||
|
|
Loading…
Reference in New Issue