mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 10:24:40 +01:00
Only start accepting connections after everyting has been initialized
Fixes #1295 And more. The estimator, key and servers list were not initialized either.
This commit is contained in:
parent
7d0e1440e1
commit
4a50736457
1 changed files with 24 additions and 5 deletions
|
@ -16,6 +16,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
|
udpListeners []*net.UDPConn
|
||||||
|
tcpListeners []*net.TCPListener
|
||||||
|
localDoHListeners []*net.TCPListener
|
||||||
userName string
|
userName string
|
||||||
child bool
|
child bool
|
||||||
proxyPublicKey [32]byte
|
proxyPublicKey [32]byte
|
||||||
|
@ -143,10 +146,10 @@ func (proxy *Proxy) addDNSListener(listenAddrStr string) {
|
||||||
FileDescriptorNum++
|
FileDescriptorNum++
|
||||||
|
|
||||||
dlog.Noticef("Now listening to %v [UDP]", listenUDPAddr)
|
dlog.Noticef("Now listening to %v [UDP]", listenUDPAddr)
|
||||||
go proxy.udpListener(listenerUDP.(*net.UDPConn))
|
proxy.udpListeners = append(proxy.udpListeners, listenerUDP.(*net.UDPConn))
|
||||||
|
|
||||||
dlog.Noticef("Now listening to %v [TCP]", listenAddrStr)
|
dlog.Noticef("Now listening to %v [TCP]", listenAddrStr)
|
||||||
go proxy.tcpListener(listenerTCP.(*net.TCPListener))
|
proxy.tcpListeners = append(proxy.tcpListeners, listenerTCP.(*net.TCPListener))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) addLocalDoHListener(listenAddrStr string) {
|
func (proxy *Proxy) addLocalDoHListener(listenAddrStr string) {
|
||||||
|
@ -218,6 +221,7 @@ func (proxy *Proxy) StartProxy() {
|
||||||
dlog.Error(err)
|
dlog.Error(err)
|
||||||
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.startAcceptingClients()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
clocksmith.Sleep(PrefetchSources(proxy.xTransport, proxy.sources))
|
clocksmith.Sleep(PrefetchSources(proxy.xTransport, proxy.sources))
|
||||||
|
@ -267,7 +271,7 @@ func (proxy *Proxy) udpListenerFromAddr(listenAddr *net.UDPAddr) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dlog.Noticef("Now listening to %v [UDP]", listenAddr)
|
dlog.Noticef("Now listening to %v [UDP]", listenAddr)
|
||||||
go proxy.udpListener(clientPc)
|
proxy.udpListeners = append(proxy.udpListeners, clientPc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,8 +308,8 @@ func (proxy *Proxy) tcpListenerFromAddr(listenAddr *net.TCPAddr) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
proxy.tcpListeners = append(proxy.tcpListeners, acceptPc)
|
||||||
dlog.Noticef("Now listening to %v [TCP]", listenAddr)
|
dlog.Noticef("Now listening to %v [TCP]", listenAddr)
|
||||||
go proxy.tcpListener(acceptPc)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,10 +319,25 @@ func (proxy *Proxy) localDoHListenerFromAddr(listenAddr *net.TCPAddr) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dlog.Noticef("Now listening to https://%v%v [DoH]", listenAddr, proxy.localDoHPath)
|
dlog.Noticef("Now listening to https://%v%v [DoH]", listenAddr, proxy.localDoHPath)
|
||||||
go proxy.localDoHListener(acceptPc)
|
proxy.tcpListeners = append(proxy.localDoHListeners, acceptPc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (proxy *Proxy) startAcceptingClients() {
|
||||||
|
for _, clientPc := range proxy.udpListeners {
|
||||||
|
proxy.udpListener(clientPc)
|
||||||
|
}
|
||||||
|
proxy.udpListeners = nil
|
||||||
|
for _, acceptPc := range proxy.tcpListeners {
|
||||||
|
proxy.tcpListener(acceptPc)
|
||||||
|
}
|
||||||
|
proxy.tcpListeners = nil
|
||||||
|
for _, acceptPc := range proxy.localDoHListeners {
|
||||||
|
proxy.localDoHListener(acceptPc)
|
||||||
|
}
|
||||||
|
proxy.localDoHListeners = nil
|
||||||
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) prepareForRelay(ip net.IP, port int, encryptedQuery *[]byte) {
|
func (proxy *Proxy) prepareForRelay(ip net.IP, port int, encryptedQuery *[]byte) {
|
||||||
anonymizedDNSHeader := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00}
|
anonymizedDNSHeader := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00}
|
||||||
relayedQuery := append(anonymizedDNSHeader, ip.To16()...)
|
relayedQuery := append(anonymizedDNSHeader, ip.To16()...)
|
||||||
|
|
Loading…
Add table
Reference in a new issue