mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
merge: Merge upstream v1.14.6
This commit is contained in:
@@ -200,6 +200,10 @@ func (i *Instance) registerPowerReport(ctx context.Context, reloading bool) {
|
||||
})
|
||||
}
|
||||
|
||||
func (i *Instance) Context() context.Context {
|
||||
return i.ctx
|
||||
}
|
||||
|
||||
func (i *Instance) Box() *box.Box {
|
||||
return i.instance
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
"github.com/sagernet/sing-box/protocol/group"
|
||||
"github.com/sagernet/sing-box/service/oomkiller"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/memory"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/common/observable"
|
||||
"github.com/sagernet/sing/service"
|
||||
|
||||
@@ -601,7 +603,9 @@ func (s *StartedService) readGroups() *Groups {
|
||||
g.Tag = iGroup.Tag()
|
||||
g.Type = iGroup.Type()
|
||||
_, g.Selectable = iGroup.(*group.Selector)
|
||||
g.Selected = iGroup.Now()
|
||||
if selected := iGroup.Selected(N.NetworkTCP); selected != nil {
|
||||
g.Selected = selected.Tag()
|
||||
}
|
||||
if boxService.cacheFile != nil {
|
||||
if isExpand, loaded := boxService.cacheFile.LoadGroupExpand(g.Tag); loaded {
|
||||
g.IsExpand = isExpand
|
||||
@@ -617,7 +621,7 @@ func (s *StartedService) readGroups() *Groups {
|
||||
var item GroupItem
|
||||
item.Tag = itemTag
|
||||
item.Type = itemOutbound.Type()
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, itemOutbound)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(itemOutbound, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -1177,7 +1181,7 @@ func (s *StartedService) SubscribeOutbounds(_ *emptypb.Empty, server grpc.Server
|
||||
Tag: ob.Tag(),
|
||||
Type: ob.Type(),
|
||||
}
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, ob)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(ob, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -1188,7 +1192,7 @@ func (s *StartedService) SubscribeOutbounds(_ *emptypb.Empty, server grpc.Server
|
||||
Tag: ep.Tag(),
|
||||
Type: ep.Type(),
|
||||
}
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(boxService.outboundManager, ep)); history != nil {
|
||||
if history := historyStorage.LoadURLTestHistory(group.RealTag(ep, N.NetworkTCP)); history != nil {
|
||||
item.UrlTestTime = history.Time.Unix()
|
||||
item.UrlTestDelay = int32(history.Delay)
|
||||
}
|
||||
@@ -2113,3 +2117,35 @@ func (s *StartedService) Instance() *Instance {
|
||||
defer s.serviceAccess.RUnlock()
|
||||
return s.instance
|
||||
}
|
||||
|
||||
func (s *StartedService) WaitStartedInstance(ctx context.Context) (*Instance, error) {
|
||||
subscription, done, err := s.serviceStatusObserver.Subscribe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.serviceStatusObserver.UnSubscribe(subscription)
|
||||
for {
|
||||
s.serviceAccess.RLock()
|
||||
currentStatus := s.serviceStatus
|
||||
instance := s.instance
|
||||
s.serviceAccess.RUnlock()
|
||||
switch currentStatus.Status {
|
||||
case ServiceStatus_STARTED:
|
||||
return instance, nil
|
||||
case ServiceStatus_STARTING, ServiceStatus_STOPPING:
|
||||
case ServiceStatus_FATAL:
|
||||
return nil, E.New(currentStatus.ErrorMessage)
|
||||
default:
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-s.ctx.Done():
|
||||
return nil, s.ctx.Err()
|
||||
case <-subscription:
|
||||
case <-done:
|
||||
return nil, os.ErrClosed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user