mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-17 01:44:23 +08:00
fix(relay): authenticate endpoints and fail closed on missing routes
This commit is contained in:
@@ -15,7 +15,8 @@ import (
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
options chain.RouterOptions
|
||||
options chain.RouterOptions
|
||||
requireChain bool
|
||||
}
|
||||
|
||||
func NewRouter(opts ...chain.RouterOption) *Router {
|
||||
@@ -35,6 +36,13 @@ func NewRouter(opts ...chain.RouterOption) *Router {
|
||||
return r
|
||||
}
|
||||
|
||||
// WithRequiredChain disables direct fallback when an explicitly required chain
|
||||
// is absent or selects no route. Configure it before serving requests.
|
||||
func (r *Router) WithRequiredChain() *Router {
|
||||
r.requireChain = true
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Router) Options() *chain.RouterOptions {
|
||||
if r == nil {
|
||||
return nil
|
||||
@@ -117,6 +125,10 @@ func (r *Router) dial(ctx context.Context, network, address string, log logger.L
|
||||
route = r.options.Chain.Route(ctx, network, ipAddr, chain.WithHostRouteOption(address))
|
||||
}
|
||||
|
||||
if r.requireChain && (route == nil || len(route.Nodes()) == 0) {
|
||||
return nil, ErrEmptyRoute
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = &bytes.Buffer{}
|
||||
}
|
||||
@@ -164,6 +176,9 @@ func (r *Router) Bind(ctx context.Context, network, address string, opts ...chai
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
if r.requireChain && r.options.Chain == nil {
|
||||
return nil, ErrEmptyRoute
|
||||
}
|
||||
var route chain.Route
|
||||
if r.options.Chain != nil {
|
||||
route = r.options.Chain.Route(ctx, network, address)
|
||||
|
||||
Reference in New Issue
Block a user