-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
131 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
[ -z "$1" ] && { echo "Usage: build.sh VERSION" >&1; exit 1; } | ||
VERSION="$1" | ||
|
||
############################################### | ||
|
||
function build() | ||
{ | ||
TARGET="$1" | ||
|
||
echo "Building dingo v. $VERSION for $TARGET" | ||
GOOS="${TARGET%-*}" GOARCH="${TARGET##*-}" go build \ | ||
-o release/dingo-$VERSION/dingo-$TARGET \ | ||
./dingo.go ./gdns.go | ||
} | ||
|
||
############################################### | ||
|
||
rm -fr ./release/dingo-$VERSION | ||
mkdir -p ./release/dingo-$VERSION | ||
|
||
for target in \ | ||
darwin-386 darwin-amd64 \ | ||
freebsd-386 freebsd-amd64 \ | ||
linux-386 linux-amd64 \ | ||
netbsd-386 netbsd-amd64 \ | ||
openbsd-386 openbsd-amd64 \ | ||
windows-386 windows-amd64; do | ||
build $target || exit 1 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* dingo: a Google DNS over HTTPS caching proxy written in Go | ||
* dingo: a DNS caching proxy written in Go | ||
* | ||
* Copyright (C) 2016 Pawel Foremski <[email protected]> | ||
* Licensed under GNU GPL v3 | ||
|
@@ -15,29 +15,17 @@ import "net" | |
import "flag" | ||
import "log" | ||
import "github.com/miekg/dns" | ||
import "net/http" | ||
import "net/url" | ||
import "time" | ||
import "io/ioutil" | ||
import "encoding/json" | ||
import "crypto/tls" | ||
import "math/rand" | ||
import "strings" | ||
import "github.com/patrickmn/go-cache" | ||
//import "github.com/devsisters/goquic" | ||
import "math/rand" | ||
|
||
/**********************************************************************/ | ||
|
||
/* command-line arguments */ | ||
var ( | ||
bindip = flag.String("bind", "0.0.0.0", "bind to interface ip") | ||
bindip = flag.String("bind", "0.0.0.0", "IP address to bind to") | ||
port = flag.Int("port", 32000, "listen on port number") | ||
dbglvl = flag.Int("dbg", 1, "debugging level") | ||
workers = flag.Int("workers", 10, "number of independent workers") | ||
server = flag.String("server", "216.58.209.174", "Google DNS web server address") | ||
sni = flag.String("sni", "www.google.com", "SNI string to send (should match server certificate)") | ||
edns = flag.String("edns", "0.0.0.0/0", "edns client subnet") | ||
nopad = flag.Bool("nopad", false, "disable random padding") | ||
dbglvl = flag.Int("dbg", 2, "debugging level") | ||
) | ||
|
||
/**********************************************************************/ | ||
|
@@ -149,57 +137,6 @@ func resolve(name string, qtype int) Reply { | |
return <-rchan | ||
} | ||
|
||
/* resolves queries */ | ||
func resolver(server string) { | ||
/* setup the HTTP client */ | ||
var httpTr = http.DefaultTransport.(*http.Transport) | ||
// var httpTr = goquic.NewRoundTripper(true) | ||
var tlsCfg = &tls.Config{ ServerName: *sni } | ||
httpTr.TLSClientConfig = tlsCfg; | ||
// req,_ := http.NewRequest("GET", "https://www.google.com/", nil) | ||
// httpTr.RoundTrip(req) | ||
var httpClient = &http.Client{ Timeout: time.Second*10, Transport: httpTr } | ||
|
||
for q := range qchan { | ||
/* make the new response object */ | ||
r := Reply{ Status: -1 } | ||
|
||
/* prepare the query */ | ||
v := url.Values{} | ||
v.Set("name", q.Name) | ||
v.Set("type", fmt.Sprintf("%d", q.Type)) | ||
if len(*edns) > 0 { | ||
v.Set("edns_client_subnet", *edns) | ||
} | ||
if !*nopad { | ||
v.Set("random_padding", strings.Repeat(string(65+rand.Intn(26)), rand.Intn(500))) | ||
} | ||
|
||
/* prepare request, send proper HTTP 'Host:' header */ | ||
addr := fmt.Sprintf("https://%s/resolve?%s", server, v.Encode()) | ||
hreq,_ := http.NewRequest("GET", addr, nil) | ||
hreq.Host = "dns.google.com" | ||
|
||
/* send the query */ | ||
resp,err := httpClient.Do(hreq) | ||
if (err == nil) { | ||
dbg(2, "[%s/%d] %s %s", q.Name, q.Type, resp.Status, resp.Proto) | ||
|
||
/* read */ | ||
buf,_ := ioutil.ReadAll(resp.Body) | ||
resp.Body.Close() | ||
dbg(7, " reply: %s", buf) | ||
|
||
/* parse JSON? */ | ||
if (resp.StatusCode == 200) { json.Unmarshal(buf, &r) } | ||
r.Now = time.Now() | ||
} else { dbg(1, "[%s/%d] error: %s", q.Name, q.Type, err.Error()) } | ||
|
||
/* write the reply */ | ||
*q.rchan <- r | ||
} | ||
} | ||
|
||
/* main */ | ||
func main() { | ||
/* prepare */ | ||
|
@@ -215,10 +152,11 @@ func main() { | |
if err != nil { die(err) } | ||
|
||
/* start workers */ | ||
for i := 0; i < *workers; i++ { go resolver(*server) } | ||
gdns_start() | ||
// odns_start() | ||
|
||
/* accept new connections forever */ | ||
dbg(1, "dingo ver. 0.1 started on UDP port %d", laddr.Port) | ||
dbg(1, "dingo ver. 0.11 started on UDP port %d", laddr.Port) | ||
var buf []byte | ||
for { | ||
buf = make([]byte, 1500) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* dingo: a DNS caching proxy written in Go | ||
* This file implements a Google DNS-over-HTTPS client | ||
* | ||
* Copyright (C) 2016 Pawel Foremski <[email protected]> | ||
* Licensed under GNU GPL v3 | ||
*/ | ||
|
||
package main | ||
|
||
import "fmt" | ||
import "net/http" | ||
import "net/url" | ||
import "time" | ||
import "io/ioutil" | ||
import "encoding/json" | ||
import "crypto/tls" | ||
import "math/rand" | ||
import "strings" | ||
import "flag" | ||
//import "github.com/devsisters/goquic" | ||
|
||
/* command-line arguments */ | ||
var ( | ||
gdns_workers = flag.Int("gdns:workers", 10, | ||
"Google DNS: number of independent workers") | ||
gdns_server = flag.String("gdns:server", "216.58.209.174", | ||
"Google DNS: web server address") | ||
gdns_sni = flag.String("gdns:sni", "www.google.com", | ||
"Google DNS: SNI string to send (should match server certificate)") | ||
gdns_edns = flag.String("gdns:edns", "", | ||
"Google DNS: EDNS client subnet (set 0.0.0.0/0 to disable)") | ||
gdns_nopad = flag.Bool("gdns:nopad", false, | ||
"Google DNS: disable random padding") | ||
) | ||
|
||
/**********************************************************************/ | ||
|
||
func gdns_start() { | ||
for i := 0; i < *gdns_workers; i++ { go gdns_resolver(*gdns_server) } | ||
} | ||
|
||
func gdns_resolver(server string) { | ||
/* setup the HTTP client */ | ||
var httpTr = http.DefaultTransport.(*http.Transport) | ||
// var httpTr = goquic.NewRoundTripper(true) | ||
|
||
var tlsCfg = &tls.Config{ ServerName: *gdns_sni } | ||
httpTr.TLSClientConfig = tlsCfg; | ||
// req,_ := http.NewRequest("GET", "https://www.google.com/", nil) | ||
// httpTr.RoundTrip(req) | ||
|
||
var httpClient = &http.Client{ Timeout: time.Second*10, Transport: httpTr } | ||
|
||
for q := range qchan { | ||
/* make the new response object */ | ||
r := Reply{ Status: -1 } | ||
|
||
/* prepare the query */ | ||
v := url.Values{} | ||
v.Set("name", q.Name) | ||
v.Set("type", fmt.Sprintf("%d", q.Type)) | ||
if len(*gdns_edns) > 0 { | ||
v.Set("edns_client_subnet", *gdns_edns) | ||
} | ||
if !*gdns_nopad { | ||
v.Set("random_padding", strings.Repeat(string(65+rand.Intn(26)), rand.Intn(500))) | ||
} | ||
|
||
/* prepare request, send proper HTTP 'Host:' header */ | ||
addr := fmt.Sprintf("https://%s/resolve?%s", server, v.Encode()) | ||
hreq,_ := http.NewRequest("GET", addr, nil) | ||
hreq.Host = "dns.google.com" | ||
|
||
/* send the query */ | ||
resp,err := httpClient.Do(hreq) | ||
if (err == nil) { | ||
dbg(2, "[%s/%d] %s %s", q.Name, q.Type, resp.Status, resp.Proto) | ||
|
||
/* read */ | ||
buf,_ := ioutil.ReadAll(resp.Body) | ||
resp.Body.Close() | ||
dbg(7, " reply: %s", buf) | ||
|
||
/* parse JSON? */ | ||
if (resp.StatusCode == 200) { json.Unmarshal(buf, &r) } | ||
r.Now = time.Now() | ||
} else { dbg(1, "[%s/%d] error: %s", q.Name, q.Type, err.Error()) } | ||
|
||
/* write the reply */ | ||
*q.rchan <- r | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.