-
Notifications
You must be signed in to change notification settings - Fork 71
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
uoosef
committed
Jul 25, 2023
0 parents
commit 449ec61
Showing
20 changed files
with
2,083 additions
and
0 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,40 @@ | ||
package bufferpool | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// BufPool is an interface for getting and returning temporary | ||
// byte slices for use by io.CopyBuffer. | ||
type BufPool interface { | ||
Get() []byte | ||
Put([]byte) | ||
} | ||
|
||
type pool struct { | ||
size int | ||
pool *sync.Pool | ||
} | ||
|
||
// NewPool new buffer pool for getting and returning temporary | ||
// byte slices for use by io.CopyBuffer. | ||
func NewPool(size int) BufPool { | ||
return &pool{ | ||
size, | ||
&sync.Pool{ | ||
New: func() interface{} { return make([]byte, 0, size) }}, | ||
} | ||
} | ||
|
||
// Get implement interface BufPool | ||
func (sf *pool) Get() []byte { | ||
return sf.pool.Get().([]byte) | ||
} | ||
|
||
// Put implement interface BufPool | ||
func (sf *pool) Put(b []byte) { | ||
if cap(b) != sf.size { | ||
panic("invalid buffer size that's put into leaky buffer") | ||
} | ||
sf.pool.Put(b[:0]) //nolint: staticcheck | ||
} |
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,10 @@ | ||
{ | ||
"TLSHeaderLength": 5, | ||
"RemoteDNSAddr": "https://yarp.lefolgoc.net/dns-query", | ||
"DnsCacheTTL": 30, | ||
"BindAddress": "127.0.0.1:8085", | ||
"ChunksLengthBeforeSni": [1, 5], | ||
"SniChunksLength": [1, 5], | ||
"ChunksLengthAfterSni": [1, 5], | ||
"DelayBetweenChunks": [1, 10] | ||
} |
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,85 @@ | ||
package doh | ||
|
||
import ( | ||
"encoding/base64" | ||
"errors" | ||
"io" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
const DoHMediaType = "application/dns-message" | ||
|
||
type clientOptions struct { | ||
Timeout time.Duration // Timeout for one DNS query | ||
} | ||
|
||
type ClientOption func(*clientOptions) error | ||
|
||
func WithTimeout(t time.Duration) ClientOption { | ||
return func(o *clientOptions) error { | ||
o.Timeout = t | ||
return nil | ||
} | ||
} | ||
|
||
type Client struct { | ||
opt *clientOptions | ||
cli *http.Client | ||
} | ||
|
||
func NewClient(opts ...ClientOption) *Client { | ||
o := new(clientOptions) | ||
for _, f := range opts { | ||
f(o) | ||
} | ||
return &Client{ | ||
opt: o, | ||
cli: &http.Client{ | ||
Timeout: o.Timeout, | ||
}, | ||
} | ||
} | ||
|
||
func (c *Client) Exchange(req *dns.Msg, address string) (r *dns.Msg, rtt time.Duration, err error) { | ||
var ( | ||
buf, b64 []byte | ||
begin = time.Now() | ||
origID = req.Id | ||
) | ||
|
||
// Set DNS ID as zero accoreding to RFC8484 (cache friendly) | ||
req.Id = 0 | ||
buf, err = req.Pack() | ||
b64 = make([]byte, base64.RawURLEncoding.EncodedLen(len(buf))) | ||
if err != nil { | ||
return | ||
} | ||
base64.RawURLEncoding.Encode(b64, buf) | ||
|
||
// No need to use hreq.URL.Query() | ||
hreq, _ := http.NewRequest("GET", address+"?dns="+string(b64), nil) | ||
hreq.Header.Add("Accept", DoHMediaType) | ||
resp, err := c.cli.Do(hreq) | ||
if err != nil { | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
content, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
err = errors.New("DoH query failed: " + string(content)) | ||
return | ||
} | ||
|
||
r = new(dns.Msg) | ||
err = r.Unpack(content) | ||
r.Id = origID | ||
rtt = time.Since(begin) | ||
return | ||
} |
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,22 @@ | ||
module bepass | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/ameshkov/dnscrypt/v2 v2.2.7 | ||
github.com/jellydator/ttlcache/v3 v3.0.1 | ||
github.com/miekg/dns v1.1.55 | ||
) | ||
|
||
require ( | ||
github.com/AdguardTeam/golibs v0.10.9 // indirect | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect | ||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 // indirect | ||
github.com/ameshkov/dnsstamps v1.0.3 // indirect | ||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect | ||
golang.org/x/mod v0.7.0 // indirect | ||
golang.org/x/net v0.2.0 // indirect | ||
golang.org/x/sync v0.1.0 // indirect | ||
golang.org/x/sys v0.10.0 // indirect | ||
golang.org/x/tools v0.3.0 // indirect | ||
) |
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,32 @@ | ||
github.com/AdguardTeam/golibs v0.10.9 h1:F9oP2da0dQ9RQDM1lGR7LxUTfUWu8hEFOs4icwAkKM0= | ||
github.com/AdguardTeam/golibs v0.10.9/go.mod h1:W+5rznZa1cSNSFt+gPS7f4Wytnr9fOrd5ZYqwadPw14= | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= | ||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw= | ||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us= | ||
github.com/ameshkov/dnscrypt/v2 v2.2.7 h1:aEitLIR8HcxVodZ79mgRcCiC0A0I5kZPBuWGFwwulAw= | ||
github.com/ameshkov/dnscrypt/v2 v2.2.7/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= | ||
github.com/ameshkov/dnsstamps v1.0.3 h1:Srzik+J9mivH1alRACTbys2xOxs0lRH9qnTA7Y1OYVo= | ||
github.com/ameshkov/dnsstamps v1.0.3/go.mod h1:Ii3eUu73dx4Vw5O4wjzmT5+lkCwovjzaEZZ4gKyIH5A= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/jellydator/ttlcache/v3 v3.0.1 h1:cHgCSMS7TdQcoprXnWUptJZzyFsqs18Lt8VVhRuZYVU= | ||
github.com/jellydator/ttlcache/v3 v3.0.1/go.mod h1:WwTaEmcXQ3MTjOm4bsZoDFiCu/hMvNWLO1w67RXz6h4= | ||
github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= | ||
github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= | ||
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= | ||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo= | ||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= | ||
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= | ||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= | ||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= | ||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= | ||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= | ||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM= | ||
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
Oops, something went wrong.