mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-01-31 13:16:53 +00:00
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package dns
|
|
|
|
import (
|
|
"net/netip"
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
C "github.com/sagernet/sing-box/constant"
|
|
"github.com/sagernet/sing-box/option"
|
|
)
|
|
|
|
var _ adapter.LegacyDNSTransport = (*TransportAdapter)(nil)
|
|
|
|
type TransportAdapter struct {
|
|
transportType string
|
|
transportTag string
|
|
dependencies []string
|
|
strategy C.DomainStrategy
|
|
clientSubnet netip.Prefix
|
|
}
|
|
|
|
func NewTransportAdapter(transportType string, transportTag string, dependencies []string) TransportAdapter {
|
|
return TransportAdapter{
|
|
transportType: transportType,
|
|
transportTag: transportTag,
|
|
dependencies: dependencies,
|
|
}
|
|
}
|
|
|
|
func NewTransportAdapterWithLocalOptions(transportType string, transportTag string, localOptions option.LocalDNSServerOptions) TransportAdapter {
|
|
return TransportAdapter{
|
|
transportType: transportType,
|
|
transportTag: transportTag,
|
|
strategy: C.DomainStrategy(localOptions.LegacyStrategy),
|
|
clientSubnet: localOptions.LegacyClientSubnet,
|
|
}
|
|
}
|
|
|
|
func NewTransportAdapterWithRemoteOptions(transportType string, transportTag string, remoteOptions option.RemoteDNSServerOptions) TransportAdapter {
|
|
var dependencies []string
|
|
if remoteOptions.AddressResolver != "" {
|
|
dependencies = []string{remoteOptions.AddressResolver}
|
|
}
|
|
return TransportAdapter{
|
|
transportType: transportType,
|
|
transportTag: transportTag,
|
|
dependencies: dependencies,
|
|
strategy: C.DomainStrategy(remoteOptions.LegacyStrategy),
|
|
clientSubnet: remoteOptions.LegacyClientSubnet,
|
|
}
|
|
}
|
|
|
|
func (a *TransportAdapter) Type() string {
|
|
return a.transportType
|
|
}
|
|
|
|
func (a *TransportAdapter) Tag() string {
|
|
return a.transportTag
|
|
}
|
|
|
|
func (a *TransportAdapter) Dependencies() []string {
|
|
return a.dependencies
|
|
}
|
|
|
|
func (a *TransportAdapter) LegacyStrategy() C.DomainStrategy {
|
|
return a.strategy
|
|
}
|
|
|
|
func (a *TransportAdapter) LegacyClientSubnet() netip.Prefix {
|
|
return a.clientSubnet
|
|
}
|