Skip to content

Commit 05d052e

Browse files
committed
allow groups to be created without initial outbounds
1 parent 1a029f0 commit 05d052e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

protocol/group/mutableselector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,13 @@ type MutableSelector struct {
5454
}
5555

5656
func NewMutableSelector(ctx context.Context, router A.Router, logger log.ContextLogger, tag string, options option.MutableSelectorOutboundOptions) (A.Outbound, error) {
57-
tags := options.Outbounds
58-
if len(tags) == 0 {
59-
return nil, errors.New("missing tags")
60-
}
6157
selector := &MutableSelector{
6258
Adapter: outbound.NewAdapter(constant.TypeMutableSelector, tag, nil, nil),
6359
ctx: ctx,
6460
outboundMgr: service.FromContext[A.OutboundManager](ctx),
6561
connMgr: service.FromContext[A.ConnectionManager](ctx),
6662
logger: logger,
67-
tags: tags,
63+
tags: options.Outbounds,
6864
outbounds: make(map[string]A.Outbound),
6965
interruptGroup: interrupt.NewGroup(),
7066
}
@@ -75,6 +71,10 @@ func (s *MutableSelector) Start() error {
7571
s.mu.Lock()
7672
defer s.mu.Unlock()
7773

74+
if len(s.tags) == 0 {
75+
return nil
76+
}
77+
7878
for _, tag := range s.tags {
7979
outbound, found := s.outboundMgr.Outbound(tag)
8080
if !found {

protocol/group/mutableurltest.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ type MutableURLTest struct {
5252
}
5353

5454
func NewMutableURLTest(ctx context.Context, _ A.Router, logger log.ContextLogger, tag string, options option.MutableURLTestOutboundOptions) (A.Outbound, error) {
55-
if len(options.Outbounds) == 0 {
56-
return nil, errors.New("missing tags")
57-
}
5855
interval := time.Duration(options.Interval)
5956
if interval == 0 {
6057
interval = C.DefaultURLTestInterval
@@ -241,6 +238,13 @@ type urlTestGroup struct {
241238
}
242239

243240
func (g *urlTestGroup) Start() error {
241+
g.access.Lock()
242+
defer g.access.Unlock()
243+
244+
if len(g.tags) == 0 {
245+
return nil
246+
}
247+
244248
for _, tag := range g.tags {
245249
outbound, found := g.outboundMgr.Outbound(tag)
246250
if !found {
@@ -349,7 +353,7 @@ func (g *urlTestGroup) Remove(tags []string) (n int, err error) {
349353
func (g *urlTestGroup) keepAlive() {
350354
g.access.Lock()
351355
defer g.access.Unlock()
352-
if !g.started {
356+
if !g.started || len(g.tags) == 0 {
353357
return
354358
}
355359
if !g.running.CompareAndSwap(false, true) {

0 commit comments

Comments
 (0)