Skip to content

Commit

Permalink
WIP: improve doh.go file
Browse files Browse the repository at this point in the history
  • Loading branch information
kaveh-ahangar committed Jul 25, 2023
1 parent ebc50bc commit f5829a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
13 changes: 3 additions & 10 deletions doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func WithTimeout(t time.Duration) ClientOption {

type Client struct {
opt *clientOptions
cli *http.Client
}

func NewClient(opts ...ClientOption) *Client {
Expand All @@ -37,9 +36,6 @@ func NewClient(opts ...ClientOption) *Client {
}
return &Client{
opt: o,
cli: &http.Client{
Timeout: o.Timeout,
},
}
}

Expand All @@ -50,19 +46,16 @@ func (c *Client) Exchange(req *dns.Msg, address string) (r *dns.Msg, rtt time.Du
origID = req.Id
)

// Set DNS ID as zero accoreding to RFC8484 (cache friendly)
// Set DNS ID as zero according to RFC8484 (cache friendly)
req.Id = 0
buf, err = req.Pack()
b64 = make([]byte, base64.RawURLEncoding.EncodedLen(len(buf)))
if err != nil {
return
}
b64 = make([]byte, base64.RawURLEncoding.EncodedLen(len(buf)))
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)
resp, err := http.Get(address + "?dns=" + string(b64))
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ type Server struct {
func (s *Server) getChunkedPackets(data []byte) map[int][]byte {
chunks := make(map[int][]byte)
hostname, err := s.getHostname(data)
fmt.Println("Hostname", string(hostname))
if err != nil {
fmt.Println(err)
chunks[0] = data
return chunks
}
fmt.Println("Hostname", string(hostname))
index := bytes.Index(data, hostname)
if index == -1 {
return nil
Expand Down Expand Up @@ -280,7 +281,6 @@ func (s *Server) c(dst io.Writer, src io.Reader, split bool) {
func (s *Server) Handle(socksCtx context.Context, writer io.Writer, socksRequest *socks5.Request) error {
// get , dohClient *doh.Client from context
dohClient := s.DoHClient
fmt.Println(socksRequest.RawDestAddr)
dialDest := socksRequest.RawDestAddr.String()
closeSignal := make(chan error)
dest := socksRequest.RawDestAddr
Expand Down

0 comments on commit f5829a6

Please sign in to comment.