daemon: Improve URLTest
This commit is contained in:
+23
-15
@@ -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
|
||||
}
|
||||
|
||||
@@ -550,10 +550,10 @@ func (c *CommandClient) SelectOutbound(groupTag string, outboundTag string) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CommandClient) URLTest(groupTag string) error {
|
||||
func (c *CommandClient) URLTest(outboundTag string) error {
|
||||
_, err := callWithResult(c, func(ctx context.Context, client daemon.StartedServiceClient) (*emptypb.Empty, error) {
|
||||
return client.URLTest(ctx, &daemon.URLTestRequest{
|
||||
OutboundTag: groupTag,
|
||||
OutboundTag: outboundTag,
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user