daemon: Improve URLTest

This commit is contained in:
世界
2026-08-30 17:41:44 +08:00
parent 1698e6cf66
commit c90f3564e8
2 changed files with 25 additions and 17 deletions
+23 -15
View File
@@ -609,21 +609,17 @@ func (s *StartedService) URLTest(ctx context.Context, request *URLTestRequest) (
}
boxService := s.instance
s.serviceAccess.RUnlock()
groupTag := request.OutboundTag
abstractOutboundGroup, isLoaded := boxService.outboundManager.Outbound(groupTag)
outboundTag := request.OutboundTag
outbound, isLoaded := boxService.outboundManager.Outbound(outboundTag)
if !isLoaded {
return nil, status.Error(codes.NotFound, "outbound group not found: "+groupTag)
return nil, status.Error(codes.NotFound, "outbound not found: "+outboundTag)
}
outboundGroup, isOutboundGroup := abstractOutboundGroup.(adapter.OutboundGroup)
if !isOutboundGroup {
return nil, status.Error(codes.InvalidArgument, "outbound is not a group: "+groupTag)
}
urlTest, isURLTest := abstractOutboundGroup.(*group.URLTest)
historyStorage := boxService.urlTestHistoryStorage
urlTest, isURLTest := outbound.(*group.URLTest)
outboundGroup, isOutboundGroup := outbound.(adapter.OutboundGroup)
if isURLTest {
go urlTest.CheckOutbounds()
} else {
historyStorage := boxService.urlTestHistoryStorage
} else if isOutboundGroup {
outbounds := common.Filter(common.Map(outboundGroup.All(), func(it string) adapter.Outbound {
itOutbound, _ := boxService.outboundManager.Outbound(it)
return itOutbound
@@ -637,13 +633,13 @@ func (s *StartedService) URLTest(ctx context.Context, request *URLTestRequest) (
b, _ := batch.New(boxService.ctx, batch.WithConcurrencyNum[any](10))
for _, detour := range outbounds {
outboundToTest := detour
outboundTag := outboundToTest.Tag()
b.Go(outboundTag, func() (any, error) {
itemTag := outboundToTest.Tag()
b.Go(itemTag, func() (any, error) {
t, err := urltest.URLTest(boxService.ctx, "", outboundToTest)
if err != nil {
historyStorage.DeleteURLTestHistory(outboundTag)
historyStorage.DeleteURLTestHistory(itemTag)
} else {
historyStorage.StoreURLTestHistory(outboundTag, &adapter.URLTestHistory{
historyStorage.StoreURLTestHistory(itemTag, &adapter.URLTestHistory{
Time: time.Now(),
Delay: t,
})
@@ -651,6 +647,18 @@ func (s *StartedService) URLTest(ctx context.Context, request *URLTestRequest) (
return nil, nil
})
}
} else {
go func() {
t, err := urltest.URLTest(boxService.ctx, "", outbound)
if err != nil {
historyStorage.DeleteURLTestHistory(outboundTag)
} else {
historyStorage.StoreURLTestHistory(outboundTag, &adapter.URLTestHistory{
Time: time.Now(),
Delay: t,
})
}
}()
}
return &emptypb.Empty{}, nil
}