Feature: add custom DNS support (#56)
This commit is contained in:
@ -14,18 +14,18 @@ var (
|
||||
tun = tunnel.Instance()
|
||||
)
|
||||
|
||||
type httpListener struct {
|
||||
type HttpListener struct {
|
||||
net.Listener
|
||||
address string
|
||||
closed bool
|
||||
}
|
||||
|
||||
func NewHttpProxy(addr string) (*httpListener, error) {
|
||||
func NewHttpProxy(addr string) (*HttpListener, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hl := &httpListener{l, addr, false}
|
||||
hl := &HttpListener{l, addr, false}
|
||||
|
||||
go func() {
|
||||
log.Infoln("HTTP proxy listening at: %s", addr)
|
||||
@ -44,12 +44,12 @@ func NewHttpProxy(addr string) (*httpListener, error) {
|
||||
return hl, nil
|
||||
}
|
||||
|
||||
func (l *httpListener) Close() {
|
||||
func (l *HttpListener) Close() {
|
||||
l.closed = true
|
||||
l.Listener.Close()
|
||||
}
|
||||
|
||||
func (l *httpListener) Address() string {
|
||||
func (l *HttpListener) Address() string {
|
||||
return l.address
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
var (
|
||||
allowLan = false
|
||||
|
||||
socksListener listener
|
||||
httpListener listener
|
||||
redirListener listener
|
||||
socksListener *socks.SockListener
|
||||
httpListener *http.HttpListener
|
||||
redirListener *redir.RedirListener
|
||||
)
|
||||
|
||||
type listener interface {
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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"
|
||||
|
||||
@ -14,19 +15,19 @@ var (
|
||||
tun = tunnel.Instance()
|
||||
)
|
||||
|
||||
type sockListener struct {
|
||||
type SockListener struct {
|
||||
net.Listener
|
||||
address string
|
||||
closed bool
|
||||
}
|
||||
|
||||
func NewSocksProxy(addr string) (*sockListener, error) {
|
||||
func NewSocksProxy(addr string) (*SockListener, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sl := &sockListener{l, addr, false}
|
||||
sl := &SockListener{l, addr, false}
|
||||
go func() {
|
||||
log.Infoln("SOCKS proxy listening at: %s", addr)
|
||||
for {
|
||||
@ -44,12 +45,12 @@ func NewSocksProxy(addr string) (*sockListener, error) {
|
||||
return sl, nil
|
||||
}
|
||||
|
||||
func (l *sockListener) Close() {
|
||||
func (l *SockListener) Close() {
|
||||
l.closed = true
|
||||
l.Listener.Close()
|
||||
}
|
||||
|
||||
func (l *sockListener) Address() string {
|
||||
func (l *SockListener) Address() string {
|
||||
return l.address
|
||||
}
|
||||
|
||||
@ -60,5 +61,5 @@ func handleSocks(conn net.Conn) {
|
||||
return
|
||||
}
|
||||
conn.(*net.TCPConn).SetKeepAlive(true)
|
||||
tun.Add(adapters.NewSocket(target, conn))
|
||||
tun.Add(adapters.NewSocket(target, conn, C.SOCKS))
|
||||
}
|
||||
|
Reference in New Issue
Block a user