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

@ -18,7 +18,6 @@ import (
"time"
"github.com/asaskevich/govalidator"
"github.com/go-gost/core/chain"
"github.com/go-gost/core/handler"
traffic "github.com/go-gost/core/limiter/traffic"
"github.com/go-gost/core/logger"
@ -37,7 +36,6 @@ func init() {
}
type httpHandler struct {
router *chain.Router
md metadata
options handler.Options
stats *stats_util.HandlerStats
@ -61,11 +59,6 @@ func (h *httpHandler) Init(md md.Metadata) error {
return err
}
h.router = h.options.Router
if h.router == nil {
h.router = chain.NewRouter(chain.LoggerRouterOption(h.options.Logger))
}
ctx, cancel := context.WithCancel(context.Background())
h.cancel = cancel
@ -215,7 +208,7 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
ctx = ctxvalue.ContextWithHash(ctx, &ctxvalue.Hash{Source: addr})
}
cc, err := h.router.Dial(ctx, network, addr)
cc, err := h.options.Router.Dial(ctx, network, addr)
if err != nil {
resp.StatusCode = http.StatusServiceUnavailable

View File

@ -51,7 +51,7 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, log logger.L
}
// obtain a udp connection
c, err := h.router.Dial(ctx, "udp", "") // UDP association
c, err := h.options.Router.Dial(ctx, "udp", "") // UDP association
if err != nil {
log.Error(err)
return err