mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 05:31:18 +08:00
71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
package dialer
|
|
|
|
import (
|
|
"github.com/Dreamacro/clash/component/resolver"
|
|
|
|
"go.uber.org/atomic"
|
|
)
|
|
|
|
var (
|
|
DefaultOptions []Option
|
|
DefaultInterface = atomic.NewString("")
|
|
DefaultRoutingMark = atomic.NewInt32(0)
|
|
)
|
|
|
|
type option struct {
|
|
interfaceName string
|
|
addrReuse bool
|
|
routingMark int
|
|
network int
|
|
prefer int
|
|
resolver resolver.Resolver
|
|
}
|
|
|
|
type Option func(opt *option)
|
|
|
|
func WithInterface(name string) Option {
|
|
return func(opt *option) {
|
|
opt.interfaceName = name
|
|
}
|
|
}
|
|
|
|
func WithAddrReuse(reuse bool) Option {
|
|
return func(opt *option) {
|
|
opt.addrReuse = reuse
|
|
}
|
|
}
|
|
|
|
func WithRoutingMark(mark int) Option {
|
|
return func(opt *option) {
|
|
opt.routingMark = mark
|
|
}
|
|
}
|
|
|
|
func WithResolver(r resolver.Resolver) Option {
|
|
return func(opt *option) {
|
|
opt.resolver = r
|
|
}
|
|
}
|
|
|
|
func WithPreferIPv4() Option {
|
|
return func(opt *option) {
|
|
opt.prefer = 4
|
|
}
|
|
}
|
|
|
|
func WithPreferIPv6() Option {
|
|
return func(opt *option) {
|
|
opt.prefer = 6
|
|
}
|
|
}
|
|
|
|
func WithOnlySingleStack(isIPv4 bool) Option {
|
|
return func(opt *option) {
|
|
if isIPv4 {
|
|
opt.network = 4
|
|
} else {
|
|
opt.network = 6
|
|
}
|
|
}
|
|
}
|