fix(relay): authenticate endpoints and fail closed on missing routes

This commit is contained in:
sagitchu
2026-11-08 23:31:08 +08:00
parent 46bfb86c1b
commit 7f0177491b
50 changed files with 5405 additions and 277 deletions
+16 -1
View File
@@ -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)