mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-04-01 07:25:41 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3f4468325 | ||
|
|
fa2bcf74a9 | ||
|
|
01d60df9cd | ||
|
|
4c0cae7111 | ||
|
|
95fe3e3b4e | ||
|
|
35ddf43505 | ||
|
|
3083b668ca | ||
|
|
dd8ea973f4 | ||
|
|
0df0002e6b |
@@ -4,12 +4,16 @@ This Changelog records major changes between versions.
|
|||||||
|
|
||||||
Not all changes are recorded. Please check git log for details.
|
Not all changes are recorded. Please check git log for details.
|
||||||
|
|
||||||
|
## Version 1.4.2
|
||||||
|
|
||||||
|
- Add PID file feature for systems which lacks a cgroup-based process tracker.
|
||||||
|
- Remove dns.ErrTruncated according to <https://github.com/miekg/dns/pull/815>.
|
||||||
|
|
||||||
## Version 1.4.1
|
## Version 1.4.1
|
||||||
|
|
||||||
- Add a configuration option: `debug_http_headers` (e.g. Add `CF-Ray` to diagnose CloudFlare's resolver)
|
- Add a configuration option: `debug_http_headers` (e.g. Add `CF-Ray` to diagnose Cloudflare's resolver)
|
||||||
- Add a configuration option: `passrthrough`
|
- Add a configuration option: `passrthrough`
|
||||||
- macOS logger is rebuilt with static libswiftCore
|
- macOS logger is rebuilt with static libswiftCore
|
||||||
- Fix a segfault when `no_cookies=true`
|
|
||||||
- Fix HTTP stream leaking problem, which may cause massive half-open connections if HTTP/1 is in use
|
- Fix HTTP stream leaking problem, which may cause massive half-open connections if HTTP/1 is in use
|
||||||
- Utilize Go's cancelable context to detect timeouts more reliably.
|
- Utilize Go's cancelable context to detect timeouts more reliably.
|
||||||
- Fix interoperation problems with gDNS
|
- Fix interoperation problems with gDNS
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ func NewClient(conf *config) (c *Client, err error) {
|
|||||||
func (c *Client) newHTTPClient() error {
|
func (c *Client) newHTTPClient() error {
|
||||||
c.httpClientMux.Lock()
|
c.httpClientMux.Lock()
|
||||||
defer c.httpClientMux.Unlock()
|
defer c.httpClientMux.Unlock()
|
||||||
if !c.httpClientLastCreate.IsZero() && time.Now().Sub(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second {
|
if !c.httpClientLastCreate.IsZero() && time.Since(c.httpClientLastCreate) < time.Duration(c.conf.Timeout)*time.Second {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if c.httpTransport != nil {
|
if c.httpTransport != nil {
|
||||||
@@ -220,7 +220,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.conf.Timeout)*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.conf.Timeout)*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if r.Response == true {
|
if r.Response {
|
||||||
log.Println("Received a response packet")
|
log.Println("Received a response packet")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
} else {
|
} else {
|
||||||
reply, _, err = c.tcpClient.Exchange(r, upstream)
|
reply, _, err = c.tcpClient.Exchange(r, upstream)
|
||||||
}
|
}
|
||||||
if err == nil || err == dns.ErrTruncated {
|
if err == nil {
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ func (c *Client) parseResponseIETF(ctx context.Context, w dns.ResponseWriter, r
|
|||||||
|
|
||||||
fullReply := new(dns.Msg)
|
fullReply := new(dns.Msg)
|
||||||
err = fullReply.Unpack(body)
|
err = fullReply.Unpack(body)
|
||||||
if err != nil && err != dns.ErrTruncated {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
req.reply.Rcode = dns.RcodeServerFailure
|
req.reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(req.reply)
|
w.WriteMsg(req.reply)
|
||||||
|
|||||||
@@ -25,14 +25,82 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkPIDFile(pidFile string) (bool, error) {
|
||||||
|
retry:
|
||||||
|
f, err := os.OpenFile(pidFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
|
||||||
|
if os.IsExist(err) {
|
||||||
|
pidStr, err := ioutil.ReadFile(pidFile)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
pid, err := strconv.ParseUint(string(pidStr), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
_, err = os.Stat(fmt.Sprintf("/proc/%d", pid))
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err = os.Remove(pidFile)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
goto retry
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
log.Printf("Already running on PID %d, exiting.\n", pid)
|
||||||
|
return false, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
_, err = io.WriteString(f, strconv.FormatInt(int64(os.Getpid()), 10))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
confPath := flag.String("conf", "doh-client.conf", "Configuration file")
|
confPath := flag.String("conf", "doh-client.conf", "Configuration file")
|
||||||
verbose := flag.Bool("verbose", false, "Enable logging")
|
verbose := flag.Bool("verbose", false, "Enable logging")
|
||||||
|
showVersion := flag.Bool("version", false, "Show software version and exit")
|
||||||
|
var pidFile *string
|
||||||
|
|
||||||
|
// I really want to push the technology forward by recommending cgroup-based
|
||||||
|
// process tracking. But I understand some cloud service providers have
|
||||||
|
// their own monitoring system. So this feature is only enabled on Linux and
|
||||||
|
// BSD series platforms which lacks functionality similar to cgroup.
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
|
||||||
|
pidFile = flag.String("pid-file", "", "PID file for legacy supervision systems lacking support for reliable cgroup-based process tracking")
|
||||||
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Printf("doh-server %s\nHomepage: https://github.com/m13253/dns-over-https\n", VERSION)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pidFile != nil && *pidFile != "" {
|
||||||
|
ok, err := checkPIDFile(*pidFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error checking PID file: %v\n", err)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conf, err := loadConfig(*confPath)
|
conf, err := loadConfig(*confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "1.4.1"
|
VERSION = "1.4.2"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,14 +25,82 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkPIDFile(pidFile string) (bool, error) {
|
||||||
|
retry:
|
||||||
|
f, err := os.OpenFile(pidFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
|
||||||
|
if os.IsExist(err) {
|
||||||
|
pidStr, err := ioutil.ReadFile(pidFile)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
pid, err := strconv.ParseUint(string(pidStr), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
_, err = os.Stat(fmt.Sprintf("/proc/%d", pid))
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err = os.Remove(pidFile)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
goto retry
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
log.Printf("Already running on PID %d, exiting.\n", pid)
|
||||||
|
return false, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
_, err = io.WriteString(f, strconv.FormatInt(int64(os.Getpid()), 10))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
confPath := flag.String("conf", "doh-server.conf", "Configuration file")
|
confPath := flag.String("conf", "doh-server.conf", "Configuration file")
|
||||||
verbose := flag.Bool("verbose", false, "Enable logging")
|
verbose := flag.Bool("verbose", false, "Enable logging")
|
||||||
|
showVersion := flag.Bool("version", false, "Show software version and exit")
|
||||||
|
var pidFile *string
|
||||||
|
|
||||||
|
// I really want to push the technology forward by recommending cgroup-based
|
||||||
|
// process tracking. But I understand some cloud service providers have
|
||||||
|
// their own monitoring system. So this feature is only enabled on Linux and
|
||||||
|
// BSD series platforms which lacks functionality similar to cgroup.
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
|
||||||
|
pidFile = flag.String("pid-file", "", "PID file for legacy supervision systems lacking support for reliable cgroup-based process tracking")
|
||||||
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Printf("doh-server %s\nHomepage: https://github.com/m13253/dns-over-https\n", VERSION)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pidFile != nil && *pidFile != "" {
|
||||||
|
ok, err := checkPIDFile(*pidFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error checking PID file: %v\n", err)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conf, err := loadConfig(*confPath)
|
conf, err := loadConfig(*confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
|||||||
@@ -251,14 +251,14 @@ func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequ
|
|||||||
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
||||||
if !s.conf.TCPOnly {
|
if !s.conf.TCPOnly {
|
||||||
req.response, _, err = s.udpClient.Exchange(req.request, req.currentUpstream)
|
req.response, _, err = s.udpClient.Exchange(req.request, req.currentUpstream)
|
||||||
if err == dns.ErrTruncated {
|
if err == nil && req.response != nil && req.response.Truncated {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||||
}
|
}
|
||||||
if err == nil || err == dns.ErrTruncated {
|
if err == nil {
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
log.Printf("DNS error from upstream %s: %s\n", req.currentUpstream, err.Error())
|
log.Printf("DNS error from upstream %s: %s\n", req.currentUpstream, err.Error())
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "1.4.1"
|
VERSION = "1.4.2"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user