Rename the randomize attribute

This commit is contained in:
ashly-right 2024-03-10 05:11:43 +01:00
parent 8c893f5180
commit 646703e61e
No known key found for this signature in database
GPG Key ID: 2C70FC9CFBECF3DE
2 changed files with 11 additions and 11 deletions

View File

@ -13,5 +13,5 @@ type URLTestOutboundOptions struct {
Tolerance uint16 `json:"tolerance,omitempty"` Tolerance uint16 `json:"tolerance,omitempty"`
IdleTimeout Duration `json:"idle_timeout,omitempty"` IdleTimeout Duration `json:"idle_timeout,omitempty"`
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"` InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
Randomized bool `json:"randomized,omitempty"` Randomize bool `json:"randomize,omitempty"`
} }

View File

@ -39,7 +39,7 @@ type URLTest struct {
idleTimeout time.Duration idleTimeout time.Duration
group *URLTestGroup group *URLTestGroup
interruptExternalConnections bool interruptExternalConnections bool
randomized bool randomize bool
} }
func NewURLTest(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.URLTestOutboundOptions) (*URLTest, error) { func NewURLTest(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.URLTestOutboundOptions) (*URLTest, error) {
@ -59,7 +59,7 @@ func NewURLTest(ctx context.Context, router adapter.Router, logger log.ContextLo
tolerance: options.Tolerance, tolerance: options.Tolerance,
idleTimeout: time.Duration(options.IdleTimeout), idleTimeout: time.Duration(options.IdleTimeout),
interruptExternalConnections: options.InterruptExistConnections, interruptExternalConnections: options.InterruptExistConnections,
randomized: options.Randomized, randomize: options.Randomize,
} }
if len(outbound.tags) == 0 { if len(outbound.tags) == 0 {
return nil, E.New("missing tags") return nil, E.New("missing tags")
@ -86,7 +86,7 @@ func (s *URLTest) Start() error {
s.tolerance, s.tolerance,
s.idleTimeout, s.idleTimeout,
s.interruptExternalConnections, s.interruptExternalConnections,
s.randomized, s.randomize,
) )
if err != nil { if err != nil {
return err return err
@ -130,7 +130,7 @@ func (s *URLTest) CheckOutbounds() {
func (s *URLTest) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) { func (s *URLTest) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
s.group.Touch() s.group.Touch()
var outbound adapter.Outbound var outbound adapter.Outbound
if s.randomized { if s.randomize {
outbound = s.group.selectRandomOutbound(network) outbound = s.group.selectRandomOutbound(network)
} else { } else {
switch N.NetworkName(network) { switch N.NetworkName(network) {
@ -160,7 +160,7 @@ func (s *URLTest) DialContext(ctx context.Context, network string, destination M
func (s *URLTest) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) { func (s *URLTest) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
s.group.Touch() s.group.Touch()
var outbound adapter.Outbound var outbound adapter.Outbound
if s.randomized { if s.randomize {
outbound = s.group.selectRandomOutbound(N.NetworkUDP) // Since ListenPacket is for UDP, we pass "N.NetworkUDP" as the network type outbound = s.group.selectRandomOutbound(N.NetworkUDP) // Since ListenPacket is for UDP, we pass "N.NetworkUDP" as the network type
} else { } else {
outbound = s.group.selectedOutboundUDP outbound = s.group.selectedOutboundUDP
@ -209,7 +209,7 @@ type URLTestGroup struct {
pauseManager pause.Manager pauseManager pause.Manager
selectedOutboundTCP adapter.Outbound selectedOutboundTCP adapter.Outbound
selectedOutboundUDP adapter.Outbound selectedOutboundUDP adapter.Outbound
randomized bool randomize bool
bestTCPLatencyOutbounds []adapter.Outbound bestTCPLatencyOutbounds []adapter.Outbound
bestUDPLatencyOutbounds []adapter.Outbound bestUDPLatencyOutbounds []adapter.Outbound
interruptGroup *interrupt.Group interruptGroup *interrupt.Group
@ -232,7 +232,7 @@ func NewURLTestGroup(
tolerance uint16, tolerance uint16,
idleTimeout time.Duration, idleTimeout time.Duration,
interruptExternalConnections bool, interruptExternalConnections bool,
randomized bool, randomize bool,
) (*URLTestGroup, error) { ) (*URLTestGroup, error) {
if interval == 0 { if interval == 0 {
interval = C.DefaultURLTestInterval interval = C.DefaultURLTestInterval
@ -267,7 +267,7 @@ func NewURLTestGroup(
pauseManager: service.FromContext[pause.Manager](ctx), pauseManager: service.FromContext[pause.Manager](ctx),
interruptGroup: interrupt.NewGroup(), interruptGroup: interrupt.NewGroup(),
interruptExternalConnections: interruptExternalConnections, interruptExternalConnections: interruptExternalConnections,
randomized: randomized, randomize: randomize,
}, nil }, nil
} }
@ -367,7 +367,7 @@ func (g *URLTestGroup) loopCheck() {
} }
g.pauseManager.WaitActive() g.pauseManager.WaitActive()
g.CheckOutbounds(false) g.CheckOutbounds(false)
if g.randomized { if g.randomize {
g.selectBestLatencyOutbounds() g.selectBestLatencyOutbounds()
} }
} }
@ -383,7 +383,7 @@ func (g *URLTestGroup) URLTest(ctx context.Context) (map[string]uint16, error) {
return nil, err return nil, err
} }
if g.randomized { if g.randomize {
g.selectBestLatencyOutbounds() g.selectBestLatencyOutbounds()
} }
return result, nil return result, nil