Add dns client
This commit is contained in:
@@ -20,7 +20,7 @@ type defaultDialer struct {
|
||||
net.ListenConfig
|
||||
}
|
||||
|
||||
func newDefault(options option.DialerOptions) N.Dialer {
|
||||
func NewDefault(options option.DialerOptions) N.Dialer {
|
||||
var dialer net.Dialer
|
||||
var listener net.ListenConfig
|
||||
if options.BindInterface != "" {
|
||||
|
||||
@@ -10,27 +10,31 @@ import (
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
)
|
||||
|
||||
type detourDialer struct {
|
||||
router adapter.Router
|
||||
options option.DialerOptions
|
||||
detour string
|
||||
dialer N.Dialer
|
||||
initOnce sync.Once
|
||||
initErr error
|
||||
}
|
||||
|
||||
func newDetour(router adapter.Router, options option.DialerOptions) N.Dialer {
|
||||
return &detourDialer{router: router, options: options}
|
||||
func NewDetour(router adapter.Router, detour string) N.Dialer {
|
||||
return &detourDialer{router: router, detour: detour}
|
||||
}
|
||||
|
||||
func (d *detourDialer) Start() error {
|
||||
_, err := d.Dialer()
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *detourDialer) Dialer() (N.Dialer, error) {
|
||||
d.initOnce.Do(func() {
|
||||
var loaded bool
|
||||
d.dialer, loaded = d.router.Outbound(d.options.Detour)
|
||||
d.dialer, loaded = d.router.Outbound(d.detour)
|
||||
if !loaded {
|
||||
d.initErr = E.New("outbound detour not found: ", d.options.Detour)
|
||||
d.initErr = E.New("outbound detour not found: ", d.detour)
|
||||
}
|
||||
})
|
||||
return d.dialer, d.initErr
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
||||
var dialer N.Dialer
|
||||
if options.Detour == "" {
|
||||
dialer = newDefault(options)
|
||||
dialer = NewDefault(options)
|
||||
} else {
|
||||
dialer = newDetour(router, options)
|
||||
dialer = NewDetour(router, options.Detour)
|
||||
}
|
||||
if options.OverrideOptions.IsValid() {
|
||||
dialer = newOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
|
||||
dialer = NewOverride(dialer, common.PtrValueOrDefault(options.OverrideOptions))
|
||||
}
|
||||
return dialer
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type overrideDialer struct {
|
||||
uotEnabled bool
|
||||
}
|
||||
|
||||
func newOverride(upstream N.Dialer, options option.OverrideStreamOptions) N.Dialer {
|
||||
func NewOverride(upstream N.Dialer, options option.OverrideStreamOptions) N.Dialer {
|
||||
return &overrideDialer{
|
||||
upstream,
|
||||
options.TLS,
|
||||
|
||||
@@ -5,7 +5,6 @@ package dialer
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
@@ -42,6 +41,6 @@ func ProtectPath(protectPath string) control.Func {
|
||||
err := conn.Control(func(fd uintptr) {
|
||||
innerErr = sendAncillaryFileDescriptors(protectPath, []int{int(fd)})
|
||||
})
|
||||
return common.AnyError(innerErr, err)
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user