mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 17:10:08 +08:00
chore: simplify DNSPrefer serialization process
This commit is contained in:
parent
32ce513977
commit
b509affe5b
@ -95,7 +95,7 @@ func NewAnyTLS(option AnyTLSOption) (*AnyTLS, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -164,7 +164,7 @@ type BasicOption struct {
|
|||||||
MPTCP bool `proxy:"mptcp,omitempty"`
|
MPTCP bool `proxy:"mptcp,omitempty"`
|
||||||
Interface string `proxy:"interface-name,omitempty"`
|
Interface string `proxy:"interface-name,omitempty"`
|
||||||
RoutingMark int `proxy:"routing-mark,omitempty"`
|
RoutingMark int `proxy:"routing-mark,omitempty"`
|
||||||
IPVersion string `proxy:"ip-version,omitempty"`
|
IPVersion C.DNSPrefer `proxy:"ip-version,omitempty"`
|
||||||
DialerProxy string `proxy:"dialer-proxy,omitempty"` // don't apply this option into groups, but can set a group name in a proxy
|
DialerProxy string `proxy:"dialer-proxy,omitempty"` // don't apply this option into groups, but can set a group name in a proxy
|
||||||
|
|
||||||
DialerForAPI C.Dialer `proxy:"-"` // the dialer used for API usage has higher priority than all the above configurations.
|
DialerForAPI C.Dialer `proxy:"-"` // the dialer used for API usage has higher priority than all the above configurations.
|
||||||
|
|||||||
@ -74,7 +74,7 @@ func NewDirectWithOption(option DirectOption) *Direct {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
loopBack: loopback.NewDetector(),
|
loopBack: loopback.NewDetector(),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,7 +163,7 @@ func NewDnsWithOption(option DnsOption) *Dns {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -174,7 +174,7 @@ func NewHttp(option HttpOption) (*Http, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
user: option.UserName,
|
user: option.UserName,
|
||||||
pass: option.Password,
|
pass: option.Password,
|
||||||
|
|||||||
@ -247,7 +247,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
|
|||||||
tfo: option.FastOpen,
|
tfo: option.FastOpen,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
client: client,
|
client: client,
|
||||||
|
|||||||
@ -113,7 +113,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
|
|||||||
udp: true,
|
udp: true,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
|
|||||||
CWND: option.CWND,
|
CWND: option.CWND,
|
||||||
UdpMTU: option.UdpMTU,
|
UdpMTU: option.UdpMTU,
|
||||||
ServerAddress: func(ctx context.Context) (*net.UDPAddr, error) {
|
ServerAddress: func(ctx context.Context) (*net.UDPAddr, error) {
|
||||||
udpAddr, err := resolveUDPAddr(ctx, "udp", addr, C.NewDNSPrefer(option.IPVersion))
|
udpAddr, err := resolveUDPAddr(ctx, "udp", addr, option.IPVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -172,7 +172,7 @@ func NewMieru(option MieruOption) (*Mieru, error) {
|
|||||||
udp: option.UDP,
|
udp: option.UDP,
|
||||||
xudp: false,
|
xudp: false,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
client: c,
|
client: c,
|
||||||
|
|||||||
@ -463,7 +463,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
method: method,
|
method: method,
|
||||||
|
|
||||||
|
|||||||
@ -167,7 +167,7 @@ func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
cipher: coreCiph,
|
cipher: coreCiph,
|
||||||
|
|||||||
@ -170,7 +170,7 @@ func NewSnell(option SnellOption) (*Snell, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
psk: psk,
|
psk: psk,
|
||||||
|
|||||||
@ -195,7 +195,7 @@ func NewSocks5(option Socks5Option) (*Socks5, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
user: option.UserName,
|
user: option.UserName,
|
||||||
|
|||||||
@ -189,7 +189,7 @@ func NewSsh(option SshOption) (*Ssh, error) {
|
|||||||
udp: false,
|
udp: false,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
config: &config,
|
config: &config,
|
||||||
|
|||||||
@ -243,7 +243,7 @@ func NewSudoku(option SudokuOption) (*Sudoku, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
table: table,
|
table: table,
|
||||||
|
|||||||
@ -293,7 +293,7 @@ func NewTrojan(option TrojanOption) (*Trojan, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
hexPassword: trojan.Key(option.Password),
|
hexPassword: trojan.Key(option.Password),
|
||||||
|
|||||||
@ -256,7 +256,7 @@ func NewTuic(option TuicOption) (*Tuic, error) {
|
|||||||
tfo: option.FastOpen,
|
tfo: option.FastOpen,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
option: &option,
|
option: &option,
|
||||||
tlsConfig: tlsClientConfig,
|
tlsConfig: tlsClientConfig,
|
||||||
|
|||||||
@ -423,7 +423,7 @@ func NewVless(option VlessOption) (*Vless, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
client: client,
|
client: client,
|
||||||
option: &option,
|
option: &option,
|
||||||
|
|||||||
@ -433,7 +433,7 @@ func NewVmess(option VmessOption) (*Vmess, error) {
|
|||||||
mpTcp: option.MPTCP,
|
mpTcp: option.MPTCP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
client: client,
|
client: client,
|
||||||
option: &option,
|
option: &option,
|
||||||
|
|||||||
@ -173,7 +173,7 @@ func NewWireGuard(option WireGuardOption) (*WireGuard, error) {
|
|||||||
udp: option.UDP,
|
udp: option.UDP,
|
||||||
iface: option.Interface,
|
iface: option.Interface,
|
||||||
rmark: option.RoutingMark,
|
rmark: option.RoutingMark,
|
||||||
prefer: C.NewDNSPrefer(option.IPVersion),
|
prefer: option.IPVersion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
outbound.dialer = option.NewDialer(outbound.DialOptions())
|
outbound.dialer = option.NewDialer(outbound.DialOptions())
|
||||||
|
|||||||
@ -86,12 +86,17 @@ func (d DNSPrefer) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDNSPrefer(prefer string) DNSPrefer {
|
func (d DNSPrefer) MarshalText() ([]byte, error) {
|
||||||
if p, ok := dnsPreferMap[prefer]; ok {
|
return []byte(d.String()), nil
|
||||||
return p
|
}
|
||||||
} else {
|
|
||||||
return DualStack
|
func (d *DNSPrefer) UnmarshalText(data []byte) error {
|
||||||
|
p, exist := dnsPreferMap[strings.ToLower(string(data))]
|
||||||
|
if !exist {
|
||||||
|
p = DualStack
|
||||||
}
|
}
|
||||||
|
*d = p
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterModeMapping is a mapping for FilterMode enum
|
// FilterModeMapping is a mapping for FilterMode enum
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user