Add dns client

This commit is contained in:
世界
2022-07-06 23:11:48 +08:00
parent 651c4b539a
commit 8a761d7e3b
23 changed files with 582 additions and 145 deletions

22
adapter/dns.go Normal file
View File

@@ -0,0 +1,22 @@
package adapter
import (
"context"
"net/netip"
C "github.com/sagernet/sing-box/constant"
"golang.org/x/net/dns/dnsmessage"
)
type DNSClient interface {
Exchange(ctx context.Context, transport DNSTransport, message *dnsmessage.Message) (*dnsmessage.Message, error)
Lookup(ctx context.Context, transport DNSTransport, domain string, strategy C.DomainStrategy) ([]netip.Addr, error)
}
type DNSTransport interface {
Service
Raw() bool
Exchange(ctx context.Context, message *dnsmessage.Message) (*dnsmessage.Message, error)
Lookup(ctx context.Context, domain string, strategy C.DomainStrategy) ([]netip.Addr, error)
}

View File

@@ -13,6 +13,7 @@ import (
type Router interface {
Service
Outbound(tag string) (Outbound, bool)
DefaultOutbound(network string) Outbound
RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
GeoIPReader() *geoip.Reader