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"`
IdleTimeout Duration `json:"idle_timeout,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
group *URLTestGroup
interruptExternalConnections bool
randomized bool
randomize bool
}
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,
idleTimeout: time.Duration(options.IdleTimeout),
interruptExternalConnections: options.InterruptExistConnections,
randomized: options.Randomized,
randomize: options.Randomize,
}
if len(outbound.tags) == 0 {
return nil, E.New("missing tags")
@ -86,7 +86,7 @@ func (s *URLTest) Start() error {
s.tolerance,
s.idleTimeout,
s.interruptExternalConnections,
s.randomized,
s.randomize,
)
if err != nil {
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) {
s.group.Touch()
var outbound adapter.Outbound
if s.randomized {
if s.randomize {
outbound = s.group.selectRandomOutbound(network)
} else {
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) {
s.group.Touch()
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
} else {
outbound = s.group.selectedOutboundUDP
@ -209,7 +209,7 @@ type URLTestGroup struct {
pauseManager pause.Manager
selectedOutboundTCP adapter.Outbound
selectedOutboundUDP adapter.Outbound
randomized bool
randomize bool
bestTCPLatencyOutbounds []adapter.Outbound
bestUDPLatencyOutbounds []adapter.Outbound
interruptGroup *interrupt.Group
@ -232,7 +232,7 @@ func NewURLTestGroup(
tolerance uint16,
idleTimeout time.Duration,
interruptExternalConnections bool,
randomized bool,
randomize bool,
) (*URLTestGroup, error) {
if interval == 0 {
interval = C.DefaultURLTestInterval
@ -267,7 +267,7 @@ func NewURLTestGroup(
pauseManager: service.FromContext[pause.Manager](ctx),
interruptGroup: interrupt.NewGroup(),
interruptExternalConnections: interruptExternalConnections,
randomized: randomized,
randomize: randomize,
}, nil
}
@ -367,7 +367,7 @@ func (g *URLTestGroup) loopCheck() {
}
g.pauseManager.WaitActive()
g.CheckOutbounds(false)
if g.randomized {
if g.randomize {
g.selectBestLatencyOutbounds()
}
}
@ -383,7 +383,7 @@ func (g *URLTestGroup) URLTest(ctx context.Context) (map[string]uint16, error) {
return nil, err
}
if g.randomized {
if g.randomize {
g.selectBestLatencyOutbounds()
}
return result, nil