Skip to content

Commit

Permalink
refactor: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
igoogolx committed Oct 1, 2023
1 parent fa4574e commit 2b16b46
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions internal/dns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/igoogolx/itun2socks/pkg/log"
"github.com/igoogolx/itun2socks/pkg/pool"
D "github.com/miekg/dns"
"io"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -55,61 +54,6 @@ func HandleDnsConn(conn conn.UdpConn) error {
return err
}

type Conn struct {
remoteAddr chan net.Addr
written bool
read bool
data chan []byte
}

func (d *Conn) WriteTo(data []byte, addr net.Addr) (int, error) {
if d.written {
return 0, io.EOF
}
dnsMessage := new(D.Msg)
err := dnsMessage.Unpack(data)
if err != nil {
return 0, fmt.Errorf("fail to unpack dns message: err: %v", err)
}
res, err := handle(dnsMessage)
if err != nil {
return 0, fmt.Errorf("fail to hanlde dns message: err: %v", err)
}
resData, err := res.Pack()
d.data <- resData
d.remoteAddr <- addr
d.written = true
return len(data), err
}

func (d *Conn) ReadFrom(data []byte) (int, net.Addr, error) {
if d.read {
return 0, nil, io.EOF
}
n := copy(data, <-d.data)
d.read = true
return n, <-d.remoteAddr, nil
}

func (d *Conn) Close() error {
return nil
}

func (d *Conn) SetDeadline(_ time.Time) error {
return nil
}

func (d *Conn) SetReadDeadline(_ time.Time) error {
return nil
}

func NewConn() *Conn {
return &Conn{
data: make(chan []byte),
remoteAddr: make(chan net.Addr),
}
}

func getDnsQuestion(msg *D.Msg) (string, error) {
if len(msg.Question) == 0 {
return "", fmt.Errorf("no dns question")
Expand Down

0 comments on commit 2b16b46

Please sign in to comment.