add port range support for service

This commit is contained in:
ginuerzh
2024-07-08 22:38:21 +08:00
parent 96f4d7bf5c
commit c1d0887a9b
73 changed files with 1915 additions and 316 deletions

View File

@ -14,11 +14,12 @@ import (
"github.com/go-gost/core/chain"
"github.com/go-gost/core/logger"
xchain "github.com/go-gost/x/chain"
"github.com/miekg/dns"
)
type Options struct {
router *chain.Router
router chain.Router
tlsConfig *tls.Config
timeout time.Duration
logger logger.Logger
@ -28,7 +29,7 @@ type Options struct {
type Option func(opts *Options)
// RouterOption sets the router for Exchanger.
func RouterOption(router *chain.Router) Option {
func RouterOption(router chain.Router) Option {
return func(opts *Options) {
opts.router = router
}
@ -65,7 +66,7 @@ type exchanger struct {
network string
addr string
rawAddr string
router *chain.Router
router chain.Router
client *http.Client
options Options
}
@ -102,7 +103,7 @@ func NewExchanger(addr string, opts ...Option) (Exchanger, error) {
ex.addr = net.JoinHostPort(ex.addr, "53")
}
if ex.router == nil {
ex.router = chain.NewRouter(chain.LoggerRouterOption(options.logger))
ex.router = xchain.NewRouter(chain.LoggerRouterOption(options.logger))
}
switch ex.network {

View File

@ -9,6 +9,7 @@ import (
"github.com/go-gost/core/chain"
"github.com/go-gost/core/logger"
"github.com/go-gost/core/resolver"
xchain "github.com/go-gost/x/chain"
resolver_util "github.com/go-gost/x/internal/util/resolver"
"github.com/go-gost/x/resolver/exchanger"
"github.com/miekg/dns"
@ -67,7 +68,7 @@ func NewResolver(nameservers []NameServer, opts ...Option) (resolver.Resolver, e
ex, err := exchanger.NewExchanger(
addr,
exchanger.RouterOption(
chain.NewRouter(
xchain.NewRouter(
chain.ChainRouterOption(server.Chain),
chain.LoggerRouterOption(options.logger),
),
@ -165,7 +166,7 @@ func (r *localResolver) resolveAsync(ctx context.Context, server *NameServer, ho
return
}
func (r *localResolver) lookupCache(ctx context.Context, server *NameServer, host string) (ips []net.IP, ttl time.Duration, ok bool) {
func (r *localResolver) lookupCache(_ context.Context, server *NameServer, host string) (ips []net.IP, ttl time.Duration, ok bool) {
lookup := func(t uint16, host string) (ips []net.IP, ttl time.Duration, ok bool) {
mq := dns.Msg{}
mq.SetQuestion(dns.Fqdn(host), t)