add weight for selector

This commit is contained in:
ginuerzh
2022-09-02 17:23:59 +08:00
parent c643014e12
commit 00f7fa2997
16 changed files with 109 additions and 45 deletions

View File

@ -10,7 +10,6 @@ import (
tls_util "github.com/go-gost/x/internal/util/tls"
"github.com/go-gost/x/metadata"
"github.com/go-gost/x/registry"
xs "github.com/go-gost/x/selector"
)
func ParseChain(cfg *config.ChainConfig) (chain.SelectableChainer, error) {
@ -142,7 +141,7 @@ func ParseChain(cfg *config.ChainConfig) (chain.SelectableChainer, error) {
sel = s
}
if sel == nil {
sel = xs.DefaultNodeSelector
sel = defaultNodeSelector()
}
group.WithSelector(sel).
WithBypass(bypass.BypassGroup(bypassList(hop.Bypass, hop.Bypasses...)...))

View File

@ -298,3 +298,11 @@ func ParseRecorder(cfg *config.RecorderConfig) (r recorder.Recorder) {
return
}
func defaultNodeSelector() selector.Selector[*chain.Node] {
return xs.NewSelector(xs.RoundRobinStrategy[*chain.Node]())
}
func defaultChainSelector() selector.Selector[chain.SelectableChainer] {
return xs.NewSelector(xs.RoundRobinStrategy[chain.SelectableChainer]())
}

View File

@ -17,7 +17,6 @@ import (
tls_util "github.com/go-gost/x/internal/util/tls"
"github.com/go-gost/x/metadata"
"github.com/go-gost/x/registry"
xs "github.com/go-gost/x/selector"
)
func ParseService(cfg *config.ServiceConfig) (service.Service, error) {
@ -188,7 +187,7 @@ func parseForwarder(cfg *config.ForwarderConfig) *chain.NodeGroup {
sel := parseNodeSelector(cfg.Selector)
if sel == nil {
sel = xs.DefaultNodeSelector
sel = defaultNodeSelector()
}
return group.WithSelector(sel)
}
@ -250,7 +249,7 @@ func chainGroup(name string, group *config.ChainGroupConfig) chain.Chainer {
}
if sel == nil {
sel = xs.DefaultChainSelector
sel = defaultChainSelector()
}
return chain.NewChainGroup(chains...).