2024-02-18 03:51:37 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
sync "sync"
|
2024-06-29 18:32:57 +00:00
|
|
|
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2024-02-18 03:51:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (r *Router) OverrideBalancer(balancer string, target string) error {
|
|
|
|
var b *Balancer
|
|
|
|
for tag, bl := range r.balancers {
|
|
|
|
if tag == balancer {
|
|
|
|
b = bl
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if b == nil {
|
2024-06-29 18:32:57 +00:00
|
|
|
return errors.New("balancer '", balancer, "' not found")
|
2024-02-18 03:51:37 +00:00
|
|
|
}
|
|
|
|
b.override.Put(target)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type overrideSettings struct {
|
|
|
|
target string
|
|
|
|
}
|
|
|
|
|
|
|
|
type override struct {
|
|
|
|
access sync.RWMutex
|
|
|
|
settings overrideSettings
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get gets the override settings
|
|
|
|
func (o *override) Get() string {
|
|
|
|
o.access.RLock()
|
|
|
|
defer o.access.RUnlock()
|
|
|
|
return o.settings.target
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put updates the override settings
|
|
|
|
func (o *override) Put(target string) {
|
|
|
|
o.access.Lock()
|
|
|
|
defer o.access.Unlock()
|
|
|
|
o.settings.target = target
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear clears the override settings
|
|
|
|
func (o *override) Clear() {
|
|
|
|
o.access.Lock()
|
|
|
|
defer o.access.Unlock()
|
|
|
|
o.settings.target = ""
|
|
|
|
}
|