Feature: add custom DNS support (#56)

This commit is contained in:
Dreamacro
2018-12-05 21:13:29 +08:00
committed by GitHub
parent da5db36ccf
commit 03c249ecb1
23 changed files with 939 additions and 124 deletions

View File

@ -4,6 +4,7 @@ import (
"net"
"github.com/Dreamacro/clash/adapters/inbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/tunnel"
)
@ -12,18 +13,18 @@ var (
tun = tunnel.Instance()
)
type redirListener struct {
type RedirListener struct {
net.Listener
address string
closed bool
}
func NewRedirProxy(addr string) (*redirListener, error) {
func NewRedirProxy(addr string) (*RedirListener, error) {
l, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
}
rl := &redirListener{l, addr, false}
rl := &RedirListener{l, addr, false}
go func() {
log.Infoln("Redir proxy listening at: %s", addr)
@ -42,12 +43,12 @@ func NewRedirProxy(addr string) (*redirListener, error) {
return rl, nil
}
func (l *redirListener) Close() {
func (l *RedirListener) Close() {
l.closed = true
l.Listener.Close()
}
func (l *redirListener) Address() string {
func (l *RedirListener) Address() string {
return l.address
}
@ -58,5 +59,5 @@ func handleRedir(conn net.Conn) {
return
}
conn.(*net.TCPConn).SetKeepAlive(true)
tun.Add(adapters.NewSocket(target, conn))
tun.Add(adapters.NewSocket(target, conn, C.REDIR))
}