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

@ -15,7 +15,6 @@ import (
"time"
"github.com/go-gost/core/bypass"
"github.com/go-gost/core/chain"
"github.com/go-gost/core/handler"
"github.com/go-gost/core/logger"
md "github.com/go-gost/core/metadata"
@ -32,7 +31,6 @@ func init() {
}
type redirectHandler struct {
router *chain.Router
md metadata
options handler.Options
}
@ -53,11 +51,6 @@ func (h *redirectHandler) Init(md md.Metadata) (err error) {
return
}
h.router = h.options.Router
if h.router == nil {
h.router = chain.NewRouter(chain.LoggerRouterOption(h.options.Logger))
}
return
}
@ -129,7 +122,7 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
return nil
}
cc, err := h.router.Dial(ctx, dstAddr.Network(), dstAddr.String())
cc, err := h.options.Router.Dial(ctx, dstAddr.Network(), dstAddr.String())
if err != nil {
log.Error(err)
return err
@ -170,13 +163,13 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
return nil
}
cc, err := h.router.Dial(ctx, "tcp", host)
cc, err := h.options.Router.Dial(ctx, "tcp", host)
if err != nil {
log.Error(err)
}
if cc == nil {
cc, err = h.router.Dial(ctx, "tcp", dstAddr.String())
cc, err = h.options.Router.Dial(ctx, "tcp", dstAddr.String())
if err != nil {
log.Error(err)
return err
@ -245,14 +238,14 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad
return nil
}
cc, err = h.router.Dial(ctx, "tcp", host)
cc, err = h.options.Router.Dial(ctx, "tcp", host)
if err != nil {
log.Error(err)
}
}
if cc == nil {
cc, err = h.router.Dial(ctx, "tcp", dstAddr.String())
cc, err = h.options.Router.Dial(ctx, "tcp", dstAddr.String())
if err != nil {
log.Error(err)
return err